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
Added on

NPX Install

npx skill4agent add zhylq/yuan-skills zhy-wechat-publish

SKILL.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
bun
image generation script.

Prerequisites

  1. Node.js >= 16
  2. To automatically generate covers,
    bun
    must be available locally
  3. The
    .env
    file in the skill directory must contain at least the following:
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)
  1. The public IP of the running machine has been added to the IP whitelist in the Official Account backend
  2. When automatically generating covers, ensure the image generation environment of
    zhy-article-illustrator
    is available

Installation Instructions

This skill is suitable for installation into agent tools that support
SKILL.md
such as OpenCode and Claude Code using
npx skills add ... --skill zhy-wechat-publish
.
After installation, please manually create the
.env
file in the local skill directory and do not commit real credentials back to the repository.

Script List

Scripts are located in
scripts/
:
ScriptPurpose
wechat_draft.js
Upload article content to WeChat Official Account drafts
upload_image.js
Upload local cover images to the permanent material library to obtain
media_id
publish_with_cover.js
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
    ul/ol
    to paragraph lists which are more stable in WeChat Official Account editing mode
  • 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

bash
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:
ParameterRequiredDescription
--title
YesArticle title
--file
YesPath to HTML article file
--author
NoAuthor; if not provided, defaults to
WECHAT_DEFAULT_AUTHOR
or "AI Yuanlai Ruci"
--digest
NoArticle abstract
--thumb
NoCover
media_id
; if not provided, reads the default value from
.env
--source-url
NoOriginal article URL
--need-open-comment
NoWhether to enable comments, default is
1
--only-fans-can-comment
NoWhether only fans can comment, default is
1

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:
  1. Read the article content and extract the title/abstract
  2. Call
    zhy-article-illustrator/scripts/image-gen.ts
    to generate a 16:9 cover image
  3. Call
    upload_image.js --json
    to upload the cover and obtain
    thumb_media_id
  4. Call
    wechat_draft.js
    to push the draft, automatically including:
    • author
    • thumb_media_id
    • need_open_comment=1
    • only_fans_can_comment=1
Optional Parameters:
ParameterDescription
--article
Original article file, recommended Markdown, can also be HTML
--html
Final HTML file to be 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 is
16:9
--source-url
Original article URL
--need-open-comment
Whether to enable comments, default is
1
--only-fans-can-comment
Whether only fans can comment, default is
1

Content Compatibility Instructions

Before publishing,
wechat_draft.js
will automatically handle the following:
  1. Expand
    var(--xxx)
    CSS variables
  2. Compatibility of WeChat section background styles
  3. Remove the first
    h1
    to avoid duplication with the article title
  4. Upload body images to
    cgi-bin/media/uploadimg
  5. Convert native lists to plain paragraph lists

Troubleshooting

  • [40013] invalid appid
    : Check
    WECHAT_APP_ID
    in
    .env
  • [40164] invalid ip... not in whitelist
    : Add the reported IP to the whitelist in the WeChat Official Account backend
  • [40007] invalid media_id
    : The cover material is invalid; re-upload the cover image
  • Missing Xiaomi/Gemini/OpenAI API Key
    : Missing image generation configuration required for automatic cover generation
  • Body images not displaying: Check if the original image path/URL is accessible and whether
    media/uploadimg
    was successful

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