zhy-wechat-publish
Original:🇨🇳 Chinese
Translated
3 scripts
This tool is designed for publishing HTML articles to WeChat Official Account drafts, especially when you need features like cover upload, automatic cover generation, body image URL replacement, CSS variable compatibility, or configuring draft metadata such as author and comment settings.
10installs
Sourcezhylq/yuan-skills
Added on
NPX Install
npx skill4agent add zhylq/yuan-skills zhy-wechat-publishTags
Translated version includes tags in frontmatterSKILL.md Content (Chinese)
View Translation Comparison →WeChat Official Account Draft Publishing Skill
This skill is used to publish articles to WeChat Official Account drafts. The script only depends on Node.js built-in modules; the automatic cover generation step reuses the existing image generation script.
bunPrerequisites
Node.js >= 16- To automatically generate covers, must be available locally
bun - The file in the skill directory must contain at least the following:
.env
env
WECHAT_APP_ID=Your Official Account AppID
WECHAT_APP_SECRET=Your Official Account AppSecret
WECHAT_DEFAULT_THUMB_MEDIA_ID=Default cover image media_id (optional)
WECHAT_DEFAULT_AUTHOR=AI Yuanlai Ruci (optional)- The public IP of the running machine has been added to the IP whitelist in the Official Account backend
- When automatically generating covers, ensure the image generation environment of is available
zhy-article-illustrator
Installation Instructions
This skill is suitable for installation into agent tools that support such as OpenCode and Claude Code using .
SKILL.mdnpx skills add ... --skill zhy-wechat-publishAfter installation, please manually create the file in the local skill directory and do not commit real credentials back to the repository.
.envScript List
Scripts are located in :
scripts/| Script | Purpose |
|---|---|
| Upload article content to WeChat Official Account drafts |
| Upload local cover images to the permanent material library to obtain |
| Read articles, generate covers, upload covers, and push drafts |
Core Capabilities
- Automatically handle CSS variable compatibility for article content
- Automatically upload article body images to WeChat's body image API and replace URLs
- Automatically downgrade to paragraph lists which are more stable in WeChat Official Account editing mode
ul/ol - Support default author, comment toggle, and comment-only-for-fans settings
- Support generating a single WeChat Official Account cover from article content and automatically uploading it as
thumb_media_id
Workflow
Method 1: HTML and cover media_id
are ready
media_idbash
node scripts/wechat_draft.js --title "Article Title" --file "post.html" --author "AI Yuanlai Ruci" --thumb "MEDIA_ID" --need-open-comment "1" --only-fans-can-comment "1"Parameter Description:
| Parameter | Required | Description |
|---|---|---|
| Yes | Article title |
| Yes | Path to HTML article file |
| No | Author; if not provided, defaults to |
| No | Article abstract |
| No | Cover |
| No | Original article URL |
| No | Whether to enable comments, default is |
| No | Whether only fans can comment, default is |
Method 2: Automatically generate cover and publish
When you have the original article file and the final HTML file for upload, you can directly run:
bash
node scripts/publish_with_cover.js --article "article.md" --html "post.html" --author "AI Yuanlai Ruci" --source-url "https://example.com"This script will automatically complete the following steps:
- Read the article content and extract the title/abstract
- Call to generate a 16:9 cover image
zhy-article-illustrator/scripts/image-gen.ts - Call to upload the cover and obtain
upload_image.js --jsonthumb_media_id - Call to push the draft, automatically including:
wechat_draft.jsauthorthumb_media_idneed_open_comment=1only_fans_can_comment=1
Optional Parameters:
| Parameter | Description |
|---|---|
| Original article file, recommended Markdown, can also be HTML |
| Final HTML file to be uploaded to the Official Account |
| Explicitly override the title |
| Explicitly override the author |
| Custom cover output path |
| Cover aspect ratio, default is |
| Original article URL |
| Whether to enable comments, default is |
| Whether only fans can comment, default is |
Content Compatibility Instructions
Before publishing, will automatically handle the following:
wechat_draft.js- Expand CSS variables
var(--xxx) - Compatibility of WeChat section background styles
- Remove the first to avoid duplication with the article title
h1 - Upload body images to
cgi-bin/media/uploadimg - Convert native lists to plain paragraph lists
Troubleshooting
- : Check
[40013] invalid appidinWECHAT_APP_ID.env - : Add the reported IP to the whitelist in the WeChat Official Account backend
[40164] invalid ip... not in whitelist - : The cover material is invalid; re-upload the cover image
[40007] invalid media_id - : Missing image generation configuration required for automatic cover generation
Missing Xiaomi/Gemini/OpenAI API Key - Body images not displaying: Check if the original image path/URL is accessible and whether was successful
media/uploadimg
Quick Examples
bash
# Existing HTML, directly publish to draft
node scripts/wechat_draft.js --title "Tech Weekly" --file "post.html"
# Automatically generate cover and publish
node scripts/publish_with_cover.js --article "article.md" --html "post.html"
# Upload cover image and write media_id back to .env
node scripts/upload_image.js "cover.png" --write-env --json