Post to WeChat Official Account
Language
Match user's language: Respond in the same language the user uses. If user writes in Chinese, respond in Chinese. If user writes in English, respond in English.
Script Directory
Agent Execution: Determine this SKILL.md directory as {baseDir}, then use {baseDir}/scripts/<name>.ts. Resolve ${BUN_X} runtime: if bun installed → bun; if npx available → npx -y bun; else suggest installing bun.
| Script | Purpose |
|---|
| INLINECODE7 | Image-text posts (图文) |
| INLINECODE8 |
Article posting via browser (文章) |
|
scripts/wechat-api.ts | Article posting via API (文章) |
|
scripts/md-to-wechat.ts | Markdown → WeChat-ready HTML with image placeholders |
|
scripts/check-permissions.ts | Verify environment & permissions |
Preferences (EXTEND.md)
Check EXTEND.md existence (priority order):
CODEBLOCK0
CODEBLOCK1
┌────────────────────────────────────────────────────────┬───────────────────┐
│ Path │ Location │
├────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-post-to-wechat/EXTEND.md │ Project directory │
├────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md │ User home │
└────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│ Result │ Action │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Found │ Read, parse, apply settings │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Not found │ Run first-time setup (references/config/first-time-setup.md) → Save → Continue │
└───────────┴───────────────────────────────────────────────────────────────────────────┘
EXTEND.md Supports: Default theme | Default color | Default publishing method (api/browser) | Default author | Default open-comment switch | Default fans-only-comment switch | Chrome profile path
First-time setup: references/config/first-time-setup.md
Minimum supported keys (case-insensitive, accept 1/0 or true/false):
| Key | Default | Mapping |
|---|
| INLINECODE14 | empty | Fallback for author when CLI/frontmatter not provided |
| INLINECODE16 |
1 |
articles[].need_open_comment in
draft/add request |
|
only_fans_can_comment |
0 |
articles[].only_fans_can_comment in
draft/add request |
Recommended EXTEND.md example:
CODEBLOCK2
Theme options: default, grace, simple, modern
Color presets: blue, green, vermilion, yellow, purple, sky, rose, olive, black, gray, pink, red, orange (or hex value)
Value priority:
- 1. CLI arguments
- Frontmatter
- EXTEND.md (account-level → global-level)
- Skill defaults
Multi-Account Support
EXTEND.md supports managing multiple WeChat Official Accounts. When accounts: block is present, each account can have its own credentials, Chrome profile, and default settings.
Compatibility rules:
| Condition | Mode | Behavior |
|---|
No accounts block | Single-account | Current behavior, unchanged |
| INLINECODE26 with 1 entry |
Single-account | Auto-select, no prompt |
|
accounts with 2+ entries | Multi-account | Prompt to select before publishing |
|
accounts with
default: true | Multi-account | Pre-select default, user can switch |
Multi-account EXTEND.md example:
CODEBLOCK3
Per-account keys (can be set per-account or globally as fallback):
default_publish_method, default_author, need_open_comment, only_fans_can_comment, app_id, app_secret, INLINECODE36
Global-only keys (always shared across accounts):
default_theme, INLINECODE38
Account Selection (Step 0.5)
Insert between Step 0 and Step 1 in the Article Posting Workflow:
CODEBLOCK4
Credential Resolution (API Method)
For a selected account with alias {alias}:
- 1.
app_id / app_secret inline in EXTEND.md account block - Env var
WECHAT_{ALIAS}_APP_ID / WECHAT_{ALIAS}_APP_SECRET (alias uppercased, hyphens → underscores) - INLINECODE44 with prefixed key INLINECODE45
- INLINECODE46 with prefixed key
- Fallback to unprefixed
WECHAT_APP_ID / INLINECODE48
.env multi-account example:
CODEBLOCK5
Chrome Profile (Browser Method)
Each account uses an isolated Chrome profile for independent login sessions:
| Source | Path |
|---|
Account chrome_profile_path in EXTEND.md | Use as-is |
| Auto-generated from alias |
{shared_profile_parent}/wechat-{alias}/ |
| Single-account fallback | Shared default profile (current behavior) |
CLI --account Argument
All publishing scripts accept --account <alias>:
CODEBLOCK6
Pre-flight Check (Optional)
Before first use, suggest running the environment check. User can skip if they prefer.
CODEBLOCK7
Checks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, API credentials, Chrome conflicts.
If any check fails, provide fix guidance per item:
| Check | Fix |
|---|
| Chrome | Install Chrome or set WECHAT_BROWSER_CHROME_PATH env var |
| Profile dir |
Shared profile at
baoyu-skills/chrome-profile (see CLAUDE.md Chrome Profile section) |
| Bun runtime |
brew install oven-sh/bun/bun (macOS) or
npm install -g bun |
| Accessibility (macOS) | System Settings → Privacy & Security → Accessibility → enable terminal app |
| Clipboard copy | Ensure Swift/AppKit available (macOS Xcode CLI tools:
xcode-select --install) |
| Paste keystroke (macOS) | Same as Accessibility fix above |
| Paste keystroke (Linux) | Install
xdotool (X11) or
ydotool (Wayland) |
| API credentials | Follow guided setup in Step 2, or manually set in
.baoyu-skills/.env |
Image-Text Posting (图文)
For short posts with multiple images (up to 9):
CODEBLOCK8
See references/image-text-posting.md for details.
Article Posting Workflow (文章)
Copy this checklist and check off items as you complete them:
CODEBLOCK9
Step 0: Load Preferences
Check and load EXTEND.md settings (see Preferences section above).
CRITICAL: If not found, complete first-time setup BEFORE any other steps or questions.
Resolve and store these defaults for later steps:
- -
default_theme (default default) - INLINECODE63 (omit if not set — theme default applies)
- INLINECODE64
- INLINECODE65 (default
1) - INLINECODE67 (default
0)
Step 1: Determine Input Type
| Input Type | Detection | Action |
|---|
| HTML file | Path ends with .html, file exists | Skip to Step 3 |
| Markdown file |
Path ends with
.md, file exists | Continue to Step 2 |
| Plain text | Not a file path, or file doesn't exist | Save to markdown, continue to Step 2 |
Plain Text Handling:
- 1. Generate slug from content (first 2-4 meaningful words, kebab-case)
- Create directory and save file:
CODEBLOCK10
- 3. Continue processing as markdown file
Slug Examples:
- - "Understanding AI Models" → INLINECODE71
- "人工智能的未来" →
ai-future (translate to English for slug)
Step 2: Select Publishing Method and Configure
Ask publishing method (unless specified in EXTEND.md or CLI):
| Method | Speed | Requirements |
|---|
| INLINECODE73 (Recommended) | Fast | API credentials |
| INLINECODE74 |
Slow | Chrome, login session |
If API Selected - Check Credentials:
CODEBLOCK11
CODEBLOCK12
If Credentials Missing - Guide Setup:
CODEBLOCK13
After location choice, prompt for values and write to .env:
CODEBLOCK14
Step 3: Resolve Theme/Color and Validate Metadata
- 1. Resolve theme (first match wins, do NOT ask user if resolved):
- CLI
--theme argument
- EXTEND.md
default_theme (loaded in Step 0)
- Fallback: INLINECODE78
- 2. Resolve color (first match wins):
- CLI
--color argument
- EXTEND.md
default_color (loaded in Step 0)
- Omit if not set (theme default applies)
- 3. Validate metadata from frontmatter (markdown) or HTML meta tags (HTML input):
| Field | If Missing |
|---|
| Title | Prompt: "Enter title, or press Enter to auto-generate from content" |
| Summary |
Use fallback chain: frontmatter
description → frontmatter
summary → prompt user or auto-generate |
| Author | Use fallback chain: CLI
--author → frontmatter
author → EXTEND.md
default_author |
Auto-Generation Logic:
- - Title: First H1/H2 heading, or first sentence
- Summary: First paragraph, truncated to 120 characters
- 4. Cover Image Check (required for API
article_type=news):
1. Use CLI
--cover if provided.
2. Else use frontmatter (
coverImage,
featureImage,
cover,
image).
3. Else check article directory default path:
imgs/cover.png.
4. Else fallback to first inline content image.
5. If still missing, stop and request a cover image before publishing.
Step 4: Publish to WeChat
CRITICAL: Publishing scripts handle markdown conversion internally. Do NOT pre-convert markdown to HTML — pass the original markdown file directly. This ensures the API method renders images as <img> tags (for API upload) while the browser method uses placeholders (for paste-and-replace workflow).
Markdown citation default:
- - For markdown input, ordinary external links are converted to bottom citations by default.
- Use
--no-cite only if the user explicitly wants to keep ordinary external links inline. - Existing HTML input is left as-is; no extra citation conversion is applied.
API method (accepts .md or .html):
CODEBLOCK15
CRITICAL: Always include --theme parameter. Never omit it, even if using default. Only include --color if explicitly set by user or EXTEND.md.
draft/add payload rules:
- - Use endpoint: INLINECODE101
- INLINECODE102 :
news (default) or INLINECODE104 - For
news, include thumb_media_id (cover is required) - Always resolve and send:
-
need_open_comment (default
1)
-
only_fans_can_comment (default
0)
- -
author resolution: CLI --author → frontmatter author → EXTEND.md INLINECODE114
If script parameters do not expose the two comment fields, still ensure final API request body includes resolved values.
Browser method (accepts --markdown or --html):
CODEBLOCK16
Step 5: Completion Report
For API method, include draft management link:
CODEBLOCK17
For Browser method:
CODEBLOCK18
Detailed References
references/article-posting.md |
Feature Comparison
| Feature | Image-Text | Article (API) | Article (Browser) |
|---|
| Plain text input | ✗ | ✓ | ✓ |
| HTML input |
✗ | ✓ | ✓ |
| Markdown input | Title/content | ✓ | ✓ |
| Multiple images | ✓ (up to 9) | ✓ (inline) | ✓ (inline) |
| Themes | ✗ | ✓ | ✓ |
| Auto-generate metadata | ✗ | ✓ | ✓ |
| Default cover fallback (
imgs/cover.png) | ✗ | ✓ | ✗ |
| Comment control (
need_open_comment,
only_fans_can_comment) | ✗ | ✓ | ✗ |
| Requires Chrome | ✓ | ✗ | ✓ |
| Requires API credentials | ✗ | ✓ | ✗ |
| Speed | Medium | Fast | Slow |
Prerequisites
For API method:
- - WeChat Official Account API credentials
- Guided setup in Step 2, or manually set in INLINECODE120
For Browser method:
- - Google Chrome
- First run: log in to WeChat Official Account (session preserved)
Config File Locations (priority order):
- 1. Environment variables
- INLINECODE121
- INLINECODE122
Troubleshooting
| Issue | Solution |
|---|
| Missing API credentials | Follow guided setup in Step 2 |
| Access token error |
Check if API credentials are valid and not expired |
| Not logged in (browser) | First run opens browser - scan QR to log in |
| Chrome not found | Set
WECHAT_BROWSER_CHROME_PATH env var |
| Title/summary missing | Use auto-generation or provide manually |
| No cover image | Add frontmatter cover or place
imgs/cover.png in article directory |
| Wrong comment defaults | Check
EXTEND.md keys
need_open_comment and
only_fans_can_comment |
| Paste fails | Check system clipboard permissions |
Extension Support
Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
发布到微信公众号
语言
匹配用户语言:使用用户使用的相同语言回复。如果用户用中文书写,则用中文回复。如果用户用英文书写,则用英文回复。
脚本目录
代理执行:将此 SKILL.md 目录确定为 {baseDir},然后使用 {baseDir}/scripts/<名称>.ts。解析 ${BUN_X} 运行时:如果已安装 bun → bun;如果 npx 可用 → npx -y bun;否则建议安装 bun。
| 脚本 | 用途 |
|---|
| scripts/wechat-browser.ts | 图文发布 |
| scripts/wechat-article.ts |
通过浏览器发布文章 |
| scripts/wechat-api.ts | 通过 API 发布文章 |
| scripts/md-to-wechat.ts | Markdown → 带图片占位符的微信兼容 HTML |
| scripts/check-permissions.ts | 验证环境与权限 |
偏好设置 (EXTEND.md)
检查 EXTEND.md 是否存在(优先级顺序):
bash
macOS, Linux, WSL, Git Bash
test -f .baoyu-skills/baoyu-post-to-wechat/EXTEND.md && echo project
test -f ${XDG
CONFIGHOME:-$HOME/.config}/baoyu-skills/baoyu-post-to-wechat/EXTEND.md && echo xdg
test -f $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md && echo user
powershell
PowerShell (Windows)
if (Test-Path .baoyu-skills/baoyu-post-to-wechat/EXTEND.md) { project }
$xdg = if ($env:XDG
CONFIGHOME) { $env:XDG
CONFIGHOME } else { $HOME/.config }
if (Test-Path $xdg/baoyu-skills/baoyu-post-to-wechat/EXTEND.md) { xdg }
if (Test-Path $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md) { user }
┌────────────────────────────────────────────────────────┬───────────────────┐
│ 路径 │ 位置 │
├────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-post-to-wechat/EXTEND.md │ 项目目录 │
├────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md │ 用户主目录 │
└────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│ 结果 │ 操作 │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 找到 │ 读取、解析、应用设置 │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 未找到 │ 运行首次设置 (references/config/first-time-setup.md) → 保存 → 继续 │
└───────────┴───────────────────────────────────────────────────────────────────────────┘
EXTEND.md 支持:默认主题 | 默认颜色 | 默认发布方式 (api/browser) | 默认作者 | 默认开启评论开关 | 默认仅粉丝评论开关 | Chrome 配置文件路径
首次设置:references/config/first-time-setup.md
最低支持的键(不区分大小写,接受 1/0 或 true/false):
| 键 | 默认值 | 映射 |
|---|
| defaultauthor | 空 | 当 CLI/前置元数据未提供 author 时的回退值 |
| needopencomment |
1 | draft/add 请求中的 articles[].needopen_comment |
| only
fanscan
comment | 0 | draft/add 请求中的 articles[].onlyfans
cancomment |
推荐的 EXTEND.md 示例:
md
default_theme: default
default_color: blue
defaultpublishmethod: api
default_author: 宝玉
needopencomment: 1
onlyfanscan_comment: 0
chromeprofilepath: /path/to/chrome/profile
主题选项:default, grace, simple, modern
颜色预设:blue, green, vermilion, yellow, purple, sky, rose, olive, black, gray, pink, red, orange(或十六进制值)
值优先级:
- 1. CLI 参数
- 前置元数据
- EXTEND.md(账号级别 → 全局级别)
- 技能默认值
多账号支持
EXTEND.md 支持管理多个微信公众号。当存在 accounts: 块时,每个账号可以拥有自己的凭据、Chrome 配置文件和默认设置。
兼容性规则:
| 条件 | 模式 | 行为 |
|---|
| 无 accounts 块 | 单账号 | 当前行为,不变 |
| accounts 有 1 个条目 |
单账号 | 自动选择,不提示 |
| accounts 有 2+ 个条目 | 多账号 | 发布前提示选择 |
| accounts 有 default: true | 多账号 | 预选默认,用户可切换 |
多账号 EXTEND.md 示例:
md
default_theme: default
default_color: blue
accounts:
- name: 宝玉的技术分享
alias: baoyu
default: true
defaultpublishmethod: api
default_author: 宝玉
needopencomment: 1
onlyfanscan_comment: 0
appid: yourwechatappid
appsecret: yourwechatappsecret
- name: AI工具集
alias: ai-tools
defaultpublishmethod: browser
default_author: AI工具集
needopencomment: 1
onlyfanscan_comment: 0
每个账号的键(可在每个账号中设置,或作为回退全局设置):
defaultpublishmethod, defaultauthor, needopencomment, onlyfanscancomment, appid, appsecret, chromeprofilepath
仅全局键(始终在所有账号间共享):
defaulttheme, defaultcolor
账号选择(步骤 0.5)
插入到文章发布工作流程的步骤 0 和步骤 1 之间:
如果没有 accounts 块:
→ 单账号模式(当前行为)
否则如果 accounts.length == 1:
→ 自动选择唯一账号
否则如果存在 --account CLI 参数:
→ 选择匹配的账号
否则如果某个账号有 default: true:
→ 预选,显示:正在使用账号:(使用 --account 切换)
否则:
→ 提示用户:
配置了多个微信账号:
1) ()
2) ()
请选择账号 [1-N]:
凭据解析(API 方法)
对于选定的别名为 {alias} 的账号:
- 1. EXTEND.md 账号块中的内联 appid / appsecret
- 环境变量 WECHAT{ALIAS}APPID / WECHAT{ALIAS}APPSECRET(别名大写,连字符 → 下划线)
- .baoyu-skills/.env 中带前缀的键 WECHAT{ALIAS}APPID
- ~/.baoyu-skills/.env 中带前缀的键
- 回退到无前缀的 WECHATAPPID / WECHATAPP_SECRET
.env 多账号示例:
bash
账号:baoyu
WECHAT
BAOYUAPP
ID=yourwechat
appid
WECHAT
BAOYUAPP
SECRET=yourwechat
appsecret
账号:ai-tools
WECHAT
AITOOLS
APPID=your
aitools
wechatapp_id
WECHAT
AITOOLS
APPSECRET=your
aitools
wechatapp_secret
Chrome 配置文件(浏览器方法)
每个账号使用独立的 Chrome 配置文件以实现独立的登录会话:
| 来源 | 路径 |
|---|
| EXTEND.md 中的账号 chromeprofilepath | 按原样使用 |
| 从别名自动生成 |
{shared
profileparent}/wechat-{alias}/ |