WeChat MP Publish Toolkit
WeChat Official Account (微信公众号) draft push and auto-publish toolkit. This skill should be used when the user wants to push article drafts to a WeChat Officia...
yyi162751-collab
@yyi162751-collab
What This Skill Does
Pushes article drafts to a WeChat Official Account draft box and publishes them to subscribers via the WeChat MP API. Supports uploading HTML content with cover images, scheduling auto-publishing, and handling credential setup and IP whitelisting.
Replaces manually logging into the WeChat MP web editor to upload and publish articles by automating the entire draft-to-publish workflow through API calls.
When to Use It
- Push a new article draft to your WeChat Official Account draft box from local HTML files
- Publish an existing draft from the draft box to all subscribers with a single command
- Set up a daily automation to publish scheduled articles without manual intervention
- Upload article cover images to the WeChat material library before pushing a draft
- Verify and troubleshoot API permissions or IP whitelist issues when publishing fails
Install
$ openclaw skills install @yyi162751-collab/wechat-mp-publish-toolkitWeChat MP Publisher
Overview
A generic toolkit for pushing and publishing articles to a WeChat Official Account (公众号) via the WeChat MP API. Supports two core operations:
- Push Draft — Upload article HTML + cover image to the draft box (
draft/add) - Publish Draft — Publish a draft from the draft box to all subscribers (
freepublish/submit)
Plus a daily automation template for scheduled auto-publishing.
First-Time Setup
1. Configure Credentials
Copy assets/.env.example to a permanent location and fill in values:
cp assets/.env.example ~/.wechat-mp.env
Edit the file:
WECHAT_APPID=wx_your_appid_here
WECHAT_SECRET=your_secret_here
WECHAT_AUTHOR=你的公众号名称
Where to find credentials:
- Login to https://mp.weixin.qq.com
- Settings & Development → Development → Basic Configuration
- AppID is visible directly; AppSecret click "Reset" to get (save immediately, only shown once)
2. IP Whitelist
The server IP calling the API must be whitelisted, otherwise errcode=40164.
To get the current server IP:
curl -s https://api.ipify.org
Add this IP at: mp.weixin.qq.com → Development → Basic Configuration → IP Whitelist (IP白名单).
3. API Permissions
draft/add(push draft): Available to all verified accountsfreepublish/submit(publish): Requires verified enterprise/organization account (已认证的企业/个体工商户主体). Permission activates ~24 hours after verification. Iferrcode=48001, the permission is still syncing — publish manually from the draft box.
Core Tasks
Task 1: Push Draft to Draft Box
Use scripts/push_draft.py to push an article as a draft.
python3 scripts/push_draft.py \
--env ~/.wechat-mp.env \
--title "文章标题" \
--digest "文章摘要,不超过120字" \
--html /path/to/article.html \
--thumb MEDIA_ID_OR_LEAVE_BLANK
What the script does:
- Load credentials from the
--envfile - Get
access_token(handles 40164 IP whitelist error) - If
--thumbnot provided and a cover image path is given, upload it to the material library first - Push the draft via
draft/addAPI - Print the resulting
media_id
Key constraints:
- Title: max 64 bytes (~21 Chinese characters)
- Digest (摘要): max 120 characters
- Author: leave empty via API (Chinese names exceed 8-byte limit) — set manually in editor
- Article images must use
mmbiz.qpic.cndomains (upload to material library first) - JSON must use
ensure_ascii=Falseto avoid garbled Chinese — the script handles this withcurl --data-binary
Task 2: Publish a Draft
Use scripts/publish_draft.py to publish a draft that's already in the draft box.
python3 scripts/publish_draft.py \
--env ~/.wechat-mp.env \
--media-id MEDIA_ID_FROM_DRAFT
What the script does:
- Load credentials from the
--envfile - Get
access_token - Call
freepublish/submitwith themedia_id - Report success (
publish_id) or the specific error code
Error handling:
| errcode | Meaning | Action |
|---|---|---|
| 0 | Success | Notify user, provide publish_id |
| 48001 | API permission not active | Tell user to publish manually from mp.weixin.qq.com draft box |
| 40007 | media_id invalid (already published or deleted) | Tell user to check the draft box |
| -1 | System error (transient) | Retry 2-3 times; if persistent, manual publish |
Publishing is irreversible — once published, the article goes to all subscribers. Always verify the media_id is correct.
Task 3: Set Up Daily Auto-Publish Automation
Refer to references/automation-template.md for the complete automation prompt. The recommended setup:
- Draft generation automation — runs daily (e.g., 15:00) to generate article content and push to draft box
- Publish automation — runs daily (e.g., 20:00) to call
freepublish/submiton the day's draft
Create automations using the automation_update tool with:
scheduleType: "recurring"rrule: "FREQ=DAILY;BYHOUR=20;BYMINUTE=0"(for 20:00 daily)- The prompt from
references/automation-template.md
Quick API Reference (Bash)
For ad-hoc operations, use scripts/wechat_api.sh:
source scripts/wechat_api.sh
# Set credentials
export WECHAT_APPID="wx_your_appid"
export WECHAT_SECRET="your_secret"
# Get access token
TOKEN=$(get_wechat_token)
# Upload cover image (returns media_id)
upload_wechat_image "$TOKEN" /path/to/cover.png
# Create draft from JSON file
create_draft "$TOKEN" /path/to/draft.json
# Publish draft
publish_draft "$TOKEN" "MEDIA_ID_HERE"
Resources
scripts/push_draft.py— Push article HTML to draft box (Python, uses curl for binary-safe JSON)scripts/publish_draft.py— Publish a draft via freepublish/submit (Python)scripts/wechat_api.sh— Bash helper functions for all WeChat MP API callsreferences/api-guide.md— Detailed API documentation, error codes, encoding gotchasreferences/automation-template.md— Ready-to-use automation prompt for daily publishingassets/.env.example— Credential template file
Top skills in this category
gmail
@byungkyuGmail API integration with managed OAuth. Read, send, and manage emails, threads, labels, and drafts. Use this skill when users want to interact with Gmail. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Calls run through the `maton` CLI with OAuth login; default to read and list calls, and confirm every write or new connection with the user.
WeChat MP CN
@guohongbin-git微信公众号监控 - 文章监控、阅读量追踪、舆情分析(WeChat Official Account)
Wechat Article Search
@wuchubuzai2018搜索微信公众号文章技能。通过微信搜索获取文章列表,覆盖科技/AI、社会热点、财经、教育、职场等各类中文资讯;可按关键词检索并返回标题、概要、发布时间、来源公众号与链接。当用户需要查找微信公众号文章、整理参考资料或快速获取文章信息时使用此技能。
Wechat Publisher
@0731coderlee-sudo一键发布 Markdown 到微信公众号草稿箱。基于 wenyan-cli,支持多主题、代码高亮、图片自动上传。
google-meet
@byungkyuGoogle Meet API integration with managed OAuth. Create meeting spaces, list conference records, and manage meeting participants. Use this skill when users want to interact with Google Meet. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Calls run through the `maton` CLI with OAuth login; default to read and list calls, and confirm every write or new connection with the user.