Wechat Publisher
by @yuejiangli
Publish articles to WeChat Official Account (微信公众号) draft box via API. Use when the user wants to upload a Markdown article (with optional local images) to t...
clawhub install wechat-official-account-publisher📖 About This Skill
name: wechat-publisher description: Publish articles to WeChat Official Account (微信公众号) draft box via API. Use when the user wants to upload a Markdown article (with optional local images) to their WeChat 公众号 草稿箱. Handles token management, image uploading to WeChat CDN, Markdown-to-HTML conversion, and draft creation. Does NOT generate images — images must be provided as local files.
WeChat Publisher Skill
Publish Markdown articles to WeChat Official Account draft box.
Prerequisites
1. Create config.json in the skill root (copy from config.example.json), or set env vars WX_APPID / WX_APPSECRET (recommended for secrets).
2. Python 3 available (python3)
3. All scripts are in scripts/ relative to this SKILL.md
For full API details, read references/wechat_api.md.
Workflow
Step 1 — Gather inputs
Ask the user (or infer from context):
.md fileStep 2 — Upload cover image → get thumb_media_id
THUMB_ID=$(python3 scripts/upload_thumb.py cover.jpg)
Step 3 — Upload body images → build image map
For each body image referenced in the article:
WX_URL=$(python3 scripts/upload_img.py images/fig1.png)
Build a JSON map of local filenames to WeChat CDN URLs:
{"fig1.png": "http://mmbiz.qpic.cn/...", "fig2.jpg": "http://..."}
Save as /tmp/image_map.json.
Skip this step if the article has no inline images.
Step 4 — Convert Markdown to HTML
# Without images:
python3 scripts/md_to_html.py article.md > /tmp/article.htmlWith image map:
python3 scripts/md_to_html.py article.md --image-map /tmp/image_map.json > /tmp/article.html
Step 5 — Upload draft
python3 scripts/upload_draft.py \
--title "文章标题" \
--html /tmp/article.html \
--thumb-media-id "$THUMB_ID" \
--author "作者名" \
--digest "文章摘要"
Output: media_id of the created draft.
The draft appears in the WeChat MP backend at: https://mp.weixin.qq.com → 草稿箱
Step 6 — Confirm
Tell the user:
XXXError Handling
| Error | Fix |
|-------|-----|
| errcode: 40001 | Token expired → delete .token_cache.json and retry |
| errcode: 48001 | Account lacks API permission (check subscription vs service account) |
| errcode: 40007 | Invalid thumb_media_id → re-upload cover image |
| Cover upload fails | Image must be jpg/png, ≤1MB |
Notes
.token_cache.json (auto-refreshed when expired)/cgi-bin/freepublish/submit⚙️ Configuration
1. Create config.json in the skill root (copy from config.example.json), or set env vars WX_APPID / WX_APPSECRET (recommended for secrets).
2. Python 3 available (python3)
3. All scripts are in scripts/ relative to this SKILL.md
For full API details, read references/wechat_api.md.
📋 Tips & Best Practices
.token_cache.json (auto-refreshed when expired)/cgi-bin/freepublish/submit