This skill is used to publish articles to the WeChat Official Account draft box. The script relies only on Node.js built-in modules; the automatic cover generation step reuses the existing bun image generation script.
Prerequisites
Node.js >= 16- To automatically generate a cover, the local machine must also have
bun - Under the skill directory,
.envmust contain at least:
WECHAT_APP_ID=你的公众号AppID
WECHAT_APP_SECRET=你的公众号AppSecret
WECHAT_DEFAULT_THUMB_MEDIA_ID=默认封面图media_id(可选)
WECHAT_DEFAULT_AUTHOR=AI源来如此(可选)
- The public IP of the running machine has been added to the Official Account backend IP whitelist
- When automatically generating a cover, ensure that
article-illustrator's image generation environment is available
Installation Instructions
This skill is suitable for being installed together with npx skills add ... --skill wechat-publish into agent tools that support SKILL.md , such as OpenCode and Claude Code.
After installation, manually create .envin the local skill directory. Do not commit real credentials back to the repository.
Script List
The scripts are located in scripts/:
| Script | Purpose |
|---|---|
wechat_draft.js |
Upload the body to the Official Account draft box |
upload_image.js |
Upload a local cover image to the permanent material library and obtain media_id |
publish_with_cover.js |
Read the article, generate the cover, upload the cover, and push the draft |
Core Capabilities
- Automatically handle body CSS variable compatibility
- Automatically upload body images to the WeChat body image API and replace URLs
- Automatically downgrade
ul/olto a paragraph list that is more stable in the WeChat Official Account editing state - Support default author, comment toggle, and followers-only comment setting
- Support generating a single Official Account cover from article content, and automatically upload it as
thumb_media_id
Workflow
Method 1: HTML and cover media_id are ready
node scripts/wechat_draft.js --title "文章标题" --file "post.html" --author "AI源来如此" --thumb "MEDIA_ID" --need-open-comment "1" --only-fans-can-comment "1"
Parameter description:
| Parameter | Required | Description |
|---|---|---|
--title |
Yes | Article title |
--file |
Yes | HTML body file path |
--author |
No | Author; if not passed, defaults to WECHAT_DEFAULT_AUTHOR or AI源来如此 |
--digest |
No | Summary |
--thumb |
No | Cover media_id; if not passed, reads the .env default value |
--source-url |
No | Original link |
--need-open-comment |
No | Whether to enable comments; default 1 |
--only-fans-can-comment |
No | Whether only followers can comment; default 1 |
Method 2: Automatically generate a cover and publish
When you already have the article source file and the HTML file ultimately used for upload, you can run directly:
node scripts/publish_with_cover.js --article "article.md" --html "post.html" --author "AI源来如此" --source-url "https://example.com"
This script will automatically complete:
- Read the article content and extract the title/summary
- Call
article-illustrator/scripts/image-gen.tsto generate a single 16:9 cover image - Call
upload_image.js --jsonto upload the cover and obtainthumb_media_id - Call
wechat_draft.jsto push the draft, automatically including:authorthumb_media_idneed_open_comment=1only_fans_can_comment=1
Optional parameters:
| Parameter | Description |
|---|---|
--article |
Original article file; Markdown is recommended, HTML is also allowed |
--html |
The HTML file ultimately uploaded to the Official Account |
--title |
Explicitly override the title |
--author |
Explicitly override the author |
--cover-output |
Custom cover output path |
--cover-ar |
Cover aspect ratio; default 16:9 |
--source-url |
Original link |
--need-open-comment |
Whether comments are enabled, default 1 |
--only-fans-can-comment |
Whether only followers can comment, default 1 |
Body compatibility notes
Before publishing,wechat_draft.js will automatically handle:
var(--xxx)CSS variable expansion- WeChat section background style compatibility
- The first
h1is removed to avoid duplication with the title - Body images are uploaded to
cgi-bin/media/uploadimg - Native lists are converted to plain paragraph lists
Troubleshooting
[40013] invalid appid: check.envinWECHAT_APP_ID[40164] invalid ip... not in whitelist: add the error IP to the WeChat backend whitelist[40007] invalid media_id: the cover asset is invalid, re-upload the cover image缺少 Xiaomi/Gemini/OpenAI API Key: the image generation configuration required for automatic cover generation is missing- Body images not displaying: check whether the original image path/URL is accessible, and whether
media/uploadimgsucceeded
Quick example
# 已有 HTML,直接发草稿
node scripts/wechat_draft.js --title "技术周报" --file "post.html"
# 自动生封面并发布
node scripts/publish_with_cover.js --article "article.md" --html "post.html"
# 上传封面图并把 media_id 回写 .env
node scripts/upload_image.js "cover.png" --write-env --json