简介
Wechat AutoPublish
原始描述
自动化微信公众号文章发布,通过 API 创建和管理文章草稿,支持封面图和正文图片自动上传。用于:发布文章到公众号、创建内容草稿、自动化内容工作流、或设置定时发布系统。
通过你的 Agent 添加
安装目录:wechat-publisher/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
技能正文
name: wechat-publisher
description: Automated WeChat Official Account article publishing for creating and managing article drafts via API. Use when publishing articles to WeChat, creating content drafts, automating content workflows, or setting up scheduled publishing systems.
WeChat Publisher
Automated tool for publishing articles to WeChat Official Accounts. Supports Python and Node.js implementations with automatic access token management, multi-account support, and draft creation via API.
Quick Start
Prerequisites
Users need:
- WeChat Official Account (authenticated subscription or service account)
- AppID and AppSecret from WeChat Basic Configuration
- Python 3.x (for Python version) or Node.js (for Node.js version)
- Enable feature: access_token, draft, material permissions in WeChat backend
Setup Guide
When a user requests to publish to WeChat, guide them through:
- Create configuration file: Copy
config.example.jsontoconfig.json - Fill credentials: Edit
config.jsonwith AppID and AppSecret - Install dependencies:
- Python:
pip install httpx - Node.js:
npm install axios
- Python:
- Test connection: Run script with sample content
Finding AppID and AppSecret
Guide users to:
- Login: https://mp.weixin.qq.com
- Navigate: 开发 → 基本配置
- Copy: 开发者ID (AppID) and 开发者密码 (AppSecret)
Usage Patterns
Common User Requests
Direct Publishing:
- "Publish this article to my WeChat Official Account"
- "Create a draft for this content"
Scheduled Publishing:
- "Publish this next Monday at 9 AM" (create draft, user manually sends later)
- "Weekly post: every Friday morning" (use OpenClaw cron jobs to trigger script)
Content Formatting:
- "Format this markdown article for WeChat and publish it"
- "Convert this blog post to WeChat format and create a draft"
Execution Methods
Method 1: Direct Script Execution
Python:
cd scripts
python publish_article.py "Title" "<HTML Content>"
Node.js:
cd scripts
node publish_article.js "Title" "<HTML Content>"
Method 2: Via OpenClaw Cron
Create a cron job to trigger script with prepared content:
python scripts/publish_article.py "Scheduled Article" "<content>"
Method 3: Generate First, Then Publish
- Generate article content using AI
- Format to HTML for WeChat
- Execute publishing script with title and content
Script References
Main publishing scripts located in scripts/:
- publish_article.py: Python implementation with httpx
- publish_article.js: Node.js implementation with axios
- config.example.json: Configuration template
- README.md: Detailed setup and usage instructions
When choosing which version:
- Use Python if user prefers Python ecosystem or already has Python environment
- Use Node.js if user prefers JavaScript ecosystem or Node.js is already setup
Configuration File Format
The config.json structure supports multiple WeChat accounts:
{
"wechat": {
"defaultAccount": "account1",
"accounts": {
"account1": {
"name": "Account Name",
"appId": "wx1234567890abcdef",
"appSecret": "your_app_secret",
"type": "subscription",
"enabled": true
},
"account2": { ... }
},
"apiBaseUrl": "https://api.weixin.qq.com",
"tokenCacheDir": "./.tokens"
}
}
Key Fields:
appId: WeChat App IDappSecret: WeChat App Secret (handle securely)type: "subscription" (订阅号) or "service" (服务号)enabled: true/false to enable/disable account
Article Content Format
WeChat requires specific HTML formatting:
Basic Structure:
<section class="article-content">
<p>Paragraph content...</p>
<h2>Section heading</h2>
<p>More content...</p>
<img src="https://example.com/image.jpg" />
</section>
Critical Requirements:
- Use
<section class="article-content">wrapper for content - Closed tags only (no self-closing like
<br/>) - HTTPS image URLs recommended
- Avoid advanced CSS (WeChat has restrictions)
Troubleshooting
Common Errors & Solutions:
| Error Code | Cause | Solution |
|---|---|---|
| 40001 | Invalid AppID/AppSecret | Check credentials in config.json |
| 40164 | IP not whitelisted | Add server IP to WeChat whitelist |
| 45009 | API rate limit exceeded | Wait or decrease frequency |
| Token expired | Cache issue | Delete .tokens/ folder and retry |
Debugging Tips:
- Check config file exists and is valid JSON
- Verify Internet connectivity
- Ensure correct credentials format (no extra spaces)
- Check WeChat backend API permissions enabled
Security Considerations
Important Security Practices:
- Protect AppSecret: Never hardcode AppSecrect in scripts, always use config file
- Git ignore: Add config.json to .gitignore
- Token cache: Use secure permissions on
.tokens/directory - User responsibility: Provide users with clear warnings about credential security
Working with OpenClaw
Integration Options:
- One-shot publishing: User requests to publish, execute script once
- Scheduled publishing: Use
crontool to schedule recurring article publishing - Workflow integration: Combine with article generation skills for end-to-end automation
- Message notifications: Send success/failure notifications via
messagetool after publishing
Example Cron Job for Weekly Publishing:
{
"name": "Weekly WeChat Article",
"schedule": {
"kind": "cron",
"expr": "0 9 * * 5",
"tz": "Asia/Shanghai"
},
"payload": {
"kind": "systemEvent",
"text": "trigger_wechat_publish"
}
}
The agent would then execute the publishing script when receiving the system event.
Feature Limitations
Current Capabilities:
- Create article drafts via API
- Manage access tokens with caching
- Support multiple WeChat accounts
Not Supported (Requires manual WeChat backend):
- Direct publishing (API only creates drafts)
- Media upload (images, videos)
- Article deletion
- View count/engagement metrics
Future Extensions: Add media upload API calls for image handling in future versions.
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。