wechat-draft-publisher

Original🇨🇳 Chinese
Translated
6 scripts

Automatically publish HTML articles to WeChat Official Account draft box, supporting cover image upload, title, author and metadata management. Use this when the user says "push to WeChat", "publish to official account draft", "upload to draft box" or mentions WeChat article publishing.

10installs
Added on

NPX Install

npx skill4agent add bnd-1/wechat_article_skills wechat-draft-publisher

SKILL.md Content (Chinese)

View Translation Comparison →

WeChat Official Account Draft Publisher

Automatically publish HTML-formatted articles to WeChat Official Account draft box, supporting cover image upload, title, author, abstract and other metadata management.

⚡ Quick Start

Simplest usage:
bash
python publisher.py --title "Article Title" --content article.html
Full parameters:
bash
python publisher.py \
  --title "Title" \
  --content article.html \
  --author "Author Name" \
  --cover cover.png \
  --digest "Article Abstract"
Default values:
  • Author:
    YanG
  • Cover image:
    cover.png

📋 Execution Steps

Complete workflow for publishing articles to WeChat draft box:
  1. Locate HTML file
    • Prioritize looking for
      *_formatted.html
      (formatter output)
    • Fall back to the latest
      .html
      file
  2. Extract article title
    • Extract from HTML comment:
      <!-- Title: xxx -->
    • Extract from file name
    • Ask user for input
  3. Check cover image
    • Look for
      cover.png
    • Warn but continue publishing if missing
  4. Call publishing script
    bash
    python publisher.py --title "xxx" --content xxx.html --cover xxx.png
  5. Verify results
    • Confirm draft creation success
    • Obtain draft media_id
  6. Notify user
    • Provide WeChat backend link
    • Explain next steps

🔧 Configuration Requirements

First-time Usage

The tool will guide you through configuration on first run:
  1. Obtain WeChat Official Account Credentials
  2. Run the publisher
    bash
    python publisher.py --title "Test" --content test.html
  3. Add server IP to whitelist (if required)

Configuration File

Location:
~/.wechat-publisher/config.json
Format:
json
{
  "appid": "wx1234567890abcdef",
  "appsecret": "your_secret_here"
}

✨ Core Features

  • ✅ Automatic access_token caching (valid for 7200 seconds)
  • ✅ Cover image upload and management
  • ✅ Automatic HTML content optimization (WeChat-adapted)
  • ✅ Automatic field length truncation (title/author/abstract)
  • ✅ Error handling and retry mechanism
  • ✅ Chinese error prompts and solutions
  • ✅ Interactive mode and command-line mode

🛠️ Workflow Integration

Collaborate with other skills:
Complete workflow:
  1. wechat-tech-writer
    → Generate article (
    xxx_article.md
    +
    cover.png
    )
  2. wechat-article-formatter
    → Format HTML (
    xxx_formatted.html
    )
  3. wechat-draft-publisher
    → Publish to WeChat draft box (this skill)
Automatic detection mechanism:
  • Automatically find
    *_formatted.html
    files
  • Automatically find
    cover.png
    cover images
  • Automatically identify content images

🚨 FAQ

Error: IP not in whitelist

Symptom:
invalid ip not in whitelist
Solution:
  1. Log in to WeChat Official Account backend
  2. Go to Settings → Basic Configuration
  3. Add server IP to whitelist

Error: AppSecret error

Symptom:
AppSecret error
Solution:
  • Check configuration file:
    ~/.wechat-publisher/config.json
  • Verify AppID starts with "wx" (18 characters)
  • Confirm AppSecret is correct

Error: Title/author exceeds limit

Symptom:
title/author size out of limit
Solution:
  • The tool will automatically truncate (title: 32 bytes, author: 20 bytes)
  • To adjust, modify
    publisher.py

📁 File Structure

wechat-draft-publisher/
├── SKILL.md                # This file
├── publisher.py            # Core publishing script
├── scripts/                # Utility scripts
│   ├── fix-wechat-style.py # HTML optimizer
│   ├── optimize-html.py    # HTML compression tool
│   ├── publish-workflow.sh # Complete workflow
│   ├── install.sh          # Installation assistant
│   └── test.sh             # Test script
├── examples/               # Example files
│   ├── config.json.example # Configuration example
│   └── example.html        # HTML example
└── README.md               # Detailed English documentation

💡 Usage Examples

Example 1: Standard publishing
bash
python publisher.py \
  --title "VSCode Renaming Incident" \
  --content article.html
Example 2: Full metadata
bash
python publisher.py \
  --title "Technical Article" \
  --content article.html \
  --author "YanG" \
  --cover images/cover.png \
  --digest "This is an article about..."
Example 3: Interactive mode
bash
python publisher.py --interactive

📱 Post-Publishing Actions

After successful publishing:
  1. Log in to WeChat Official Account backend
  2. Go to "Draft Box"
  3. Preview the effect
  4. Publish after confirmation
Notes:
  • ⚠️ Drafts are saved in WeChat backend and will not be published immediately
  • ⚠️ You can edit drafts in the draft box before publishing
  • ⚠️ Cover images will be displayed during preview

🔗 Related Documents

  • Detailed Documentation: README.md (English)
  • Installation Guide: scripts/install.sh
  • HTML Processing: scripts/fix-wechat-style.py