Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPcastchat

Bridge a Matterbridge chat stream into WordPress. Every chat message that starts with a título: line becomes one scheduled WordPress post, with media attachments, an auto-generated card image, and author metadata.

There are two interchangeable entry points:

Script Delivery Auth
zapost.py WordPress REST API (/wp-json/wp/v2/posts, /media) WP Application Password (Basic auth)
zapost-wpwh.py WP Webhooks Pro (create_post / create_media) WP Webhooks API key

Both connect to Matterbridge's HTTP streaming endpoint (/api/stream), transform each matching message, and keep reconnecting automatically if the stream drops.

How it works

  1. Subscribe to {MATTERBRIDGE_API_URL}/api/stream and read one JSON message per line.
  2. Keep only msg / message events whose text starts with título: (Portuguese, lowercase, accented). When the text is empty, the caption of the first attached file is used instead.
  3. If the message has no media, render a 1080×1080 card JPG (background, stamp overlay, wrapped text) with ImageMagick and upload it as the featured image.
  4. Build the post: title from the título: line, author block with avatar, embedded images/attachments, text body, tags from the gateway/account, and _matterbridge_* metadata.
  5. Publish 12 hours in the future (scheduled), using WP_POST_STATUS (future in the sample .env, draft by default).

A small health endpoint answers GET /health on http://127.0.0.1:8423/health.

Requirements

  • Python 3.13
  • ImageMagick (convert) with the DejaVu-Sans-Bold font available
  • A running Matterbridge with the API enabled and an API token
  • A WordPress site with either an Application Password (REST variant) or WP Webhooks Pro configured (webhook variant)

Setup

python -m venv .venv
.venv/bin/pip install -r requirements.txt

cp env.example .env
$EDITOR .env

Configuration

Configuration is read from .env next to the script. The variables each script actually reads:

Variable Used by Purpose
MATTERBRIDGE_API_URL both Matterbridge base URL (default http://127.0.0.1:8424)
MATTERBRIDGE_API_TOKEN both Matterbridge API token (sent as Bearer header and ?token=)
MEDIA_BASE_URL both Public base URL for matterbridge media files
WP_BASE_URL, WP_USERNAME, WP_APP_PASSWORD zapost.py WordPress REST API credentials
WP_WEBHOOK_URL, WPWHPRO_API_KEY zapost-wpwh.py WP Webhooks Pro endpoint and key
WP_POST_AUTHOR, WP_POST_STATUS, WP_POST_TYPE, WP_POST_CATEGORY, WP_COMMENT_STATUS, WP_TAGS_INPUT both Post defaults
STAMP_PATH, CARDS_DIR, CARD_BG_COLOR, CARD_TEXT_COLOR, CARD_STAMP_OPACITY both Card image generation

Notes:

  • env.example is a template and is out of date in places. The scripts read MATTERBRIDGE_API_URL (HTTP streaming), not MATTERBRIDGE_WS_URL, and ignore SHARED_SECRET, DATE_PREFIX, and LISTEN_PORT.
  • In zapost-wpwh.py, WPWHPRO_API_KEY, STAMP_PATH, CARDS_DIR, and CARD_* are read before .env is loaded, so their .env values currently have no effect; set them in the process environment or fix the load order.
  • The REST API variant expects category and tag term IDs; tag names are passed as-is and may be ignored by WordPress.

Run

.venv/bin/python zapost.py        # REST API variant
.venv/bin/python zapost-wpwh.py   # WP Webhooks Pro variant

Both are long-running foreground processes with auto-reconnect and a rotating middleware.log (5 MB × 3 backups) beside the script. Run only one of them at a time: they share the log file and both bind port 8423.

Message example

Send through your connected chat:

título: Reunião do comitê
Pauta da semana: ...

This creates a post titled "Reunião do comitê" scheduled 12 hours ahead, with the remaining text as its body.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages