baoyu-post-to-wechat
- 信任分
- 92/100
- 兼容 Agent
- 1
- 领域
- 设计与多媒体
- 兼容 Agent
- Claude Code
- 信任分
- 92 / 100 · 已通过审计
- 作者 / 版本 / 许可
- @JimLiu · v1.56.1 · 未声明 license
- 安装命令数
- 1 条
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
想读作者英文原文? ↓ 滚到正文区切换 · 在 GitHub 查看 ↗
baoyu-post-to-wechat 把整篇文章一键发到微信公众号——重点是「自动排版 + 多账号支持」,省掉「复制到公众号编辑器手调样式」的半小时。
核心能力
按 SKILL.md 的章节:
- Image-Text Posting(图文):单条带图素材
- Article Posting Workflow(文章):标准长文,含封面、摘要、原创声明
- Multi-Account Support:你可以管多个公众号(个人号、公司号),切换不需要重新登录
- Pre-flight Check:发布前自检,提前发现 token 过期、违禁词、图片尺寸问题
- Feature Comparison:图文 vs 文章 vs 头条文章三种发布形态的对比表,帮你选合适的
工作流
① 读已有的 Markdown 或 HTML(通常是 baoyu-markdown-to-html 的输出);② 配置 Multi-Account Support 选择目标账号;③ 跑 Pre-flight Check;④ 调微信公众平台 API 上传素材并发布;⑤ 返回正文链接 / 草稿箱 ID。
优先级
作者把工具优先级写成 Priority Order:① 优先用 Agent 内置 input 工具(AskUserQuestion);② 否则降级成纯文本编号问答;③ 支持批处理(batching)一次问多题,加速交互。
排错指南
有专门一节列常见报错:access_token 过期、IP 白名单未配、图片大小超限、违禁词触发。每条都有可执行的修复步骤。
适合谁
- 公众号作者,一周稳定发文 1+ 次
- 多账号运营(个人号 + 工作号 + 客户号)
- 博客作者,希望一稿多发(博客 + 公众号)
- 内容团队,把发布流程自动化、记录归档
何时不该用
高度需要在公众号编辑器里实时手调(贴广告、调间距、跑活动)——还是手动发;不需要保留原创声明、不写带封面的长文(只发个朋友圈消息)——用不上这个。
配套
和 baoyu-format-markdown + baoyu-markdown-to-html 形成「整稿 → 出 HTML → 发公众号」三步。配 baoyu-cover-image 自动出封面。
Post to WeChat Official Account
User Input Tools
When this skill prompts the user, follow this tool-selection rule (priority order):
- Prefer built-in user-input tools exposed by the current agent runtime — e.g.,
AskUserQuestion,request_user_input,clarify,ask_user, or any equivalent. - Fallback: if no such tool exists, emit a numbered plain-text message and ask the user to reply with the chosen number/answer for each question.
- Batching: if the tool supports multiple questions per call, combine all applicable questions into a single call; if only single-question, ask them one at a time in priority order.
Concrete AskUserQuestion references below are examples — substitute the local equivalent in other runtimes.
Language
Respond in the user's language. If they write in Chinese, reply in Chinese; if English, English. Keep technical tokens (paths, flags, field names) in English.
Script Directory
{baseDir} = this SKILL.md's directory. Resolve ${BUN_X}: prefer bun; else npx -y bun; else suggest brew install oven-sh/bun/bun.
| Script | Purpose |
|---|---|
scripts/wechat-browser.ts |
Image-text posts (图文) |
scripts/wechat-article.ts |
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 these paths in order; first hit wins:
| Path | Scope |
|---|---|
.baoyu-skills/baoyu-post-to-wechat/EXTEND.md |
Project |
${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-post-to-wechat/EXTEND.md |
XDG |
$HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md |
User home |
Found → read, parse, apply. Not found → run first-time setup (references/config/first-time-setup.md) before anything else.
Minimum keys (case-insensitive, accept 1/0 or true/false):
| Key | Default | Mapping |
|---|---|---|
default_author |
empty | Fallback for author when CLI/frontmatter not provided |
need_open_comment |
1 |
articles[].need_open_comment in draft/add |
only_fans_can_comment |
0 |
articles[].only_fans_can_comment in draft/add |
Recommended EXTEND.md:
default_theme: default
default_color: blue
default_publish_method: api
default_author: 宝玉
need_open_comment: 1
only_fans_can_comment: 0
chrome_profile_path: /path/to/chrome/profile
Theme options: default, grace, simple, modern. Color presets: blue, green, vermilion, yellow, purple, sky, rose, olive, black, gray, pink, red, orange (or hex).
Value priority: CLI args → frontmatter → EXTEND.md (account-level → global) → skill defaults.
Multi-Account Support
EXTEND.md supports an accounts: block for managing multiple Official Accounts. With 2+ entries, the workflow inserts a Step 0.5 to prompt for account selection (or auto-selects based on default: true or --account <alias>).
Full details — compatibility rules, per-account keys, credential resolution, per-account Chrome profiles, CLI usage — in references/multi-account.md.
Pre-flight Check (Optional)
Before first use, suggest the environment check (user can skip):
${BUN_X} {baseDir}/scripts/check-permissions.ts
Checks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, API credentials, Chrome conflicts.
| Check fails | Fix |
|---|---|
| Chrome | Install Chrome or set WECHAT_BROWSER_CHROME_PATH |
| Profile dir | Shared profile at baoyu-skills/chrome-profile |
| Bun runtime | brew install oven-sh/bun/bun or npm install -g bun |
| Accessibility (macOS) | System Settings → Privacy & Security → Accessibility → enable terminal app |
| Clipboard copy | Ensure Swift/AppKit (macOS: xcode-select --install) |
| Paste keystroke (Linux) | Install xdotool (X11) or ydotool (Wayland) |
| API credentials | Follow guided setup in Step 2, or set in .baoyu-skills/.env |
Image-Text Posting (图文)
Short posts with multiple images (up to 9):
${BUN_X} {baseDir}/scripts/wechat-browser.ts --markdown article.md --images ./images/
${BUN_X} {baseDir}/scripts/wechat-browser.ts --title "标题" --content "内容" --image img.png --submit
Details: references/image-text-posting.md.
Article Posting Workflow (文章)
- [ ] Step 0: Load preferences (EXTEND.md)
- [ ] Step 0.5: Resolve account (multi-account only — see references/multi-account.md)
- [ ] Step 1: Determine input type
- [ ] Step 2: Select method and configure credentials
- [ ] Step 3: Resolve theme/color and validate metadata
- [ ] Step 4: Publish to WeChat
- [ ] Step 5: Report completion
Step 0: Load Preferences
Check and load EXTEND.md (see "Preferences" above). If not found, complete first-time setup before any other questions. Resolve and cache for later steps: default_theme, default_color, default_author, need_open_comment, only_fans_can_comment.
Step 1: Determine Input Type
| Input | Detection | Next |
|---|---|---|
| HTML file | Path ends .html, file exists |
Skip to Step 3 |
| Markdown file | Path ends .md, file exists |
Step 2 |
| Plain text | Not a file path, or file doesn't exist | Save to markdown, then Step 2 |
Plain-text handling:
- Generate slug (first 2-4 meaningful words, kebab-case; translate Chinese to English for the slug).
- Save to
post-to-wechat/YYYY-MM-DD/<slug>.md(create directory if needed). - Continue as a markdown file.
Step 2: Select Publishing Method and Configure
Ask method unless specified in EXTEND.md or CLI:
| Method | Speed | Requires |
|---|---|---|
api (Recommended) |
Fast | API credentials |
browser |
Slow | Chrome + logged-in session |
API selected + missing credentials → run guided setup per references/api-setup.md (writes to .baoyu-skills/.env).
Step 3: Resolve Theme/Color and Validate Metadata
- Theme: CLI
--theme→ EXTEND.mddefault_theme→default(first match wins; do NOT ask if resolved). - Color: CLI
--color→ EXTEND.mddefault_color→ omit (theme default applies). - Validate metadata (frontmatter for markdown, meta tags for HTML):
| Field | Missing → |
|---|---|
| Title | Ask, or press Enter to auto-generate from content |
| Summary | Frontmatter description → summary → ask or auto-generate |
| Author | CLI --author → frontmatter author → EXTEND.md default_author |
Auto-generation: title = first H1/H2 or first sentence; summary = first paragraph, truncated to 120 chars.
- Cover image (required for API
article_type=news): CLI--cover→ frontmatter (coverImage/featureImage/cover/image) →imgs/cover.png→ first inline image → stop and request one if still missing.
Step 4: Publish
Important — never pre-convert markdown to HTML. Publishing scripts handle the conversion internally and the two methods render images differently: API renders <img> tags for upload, browser uses placeholders for paste-and-replace. Passing a pre-converted HTML breaks one or the other.
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 inline links. Existing HTML input is left as-is.
API method (accepts .md or .html):
${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme <theme> [--color <color>] [--title <title>] [--summary <summary>] [--author <author>] [--cover <cover_path>] [--no-cite]
Always pass --theme even if it's default. Only pass --color when explicitly set by the user or EXTEND.md.
draft/add payload rules:
- Endpoint:
POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN article_type:news(default) ornewspic- For
news, includethumb_media_id(cover required) - Always include
need_open_comment(default1) andonly_fans_can_comment(default0) in the request body, even if the CLI doesn't expose them
Browser method (accepts --markdown or --html):
${BUN_X} {baseDir}/scripts/wechat-article.ts --markdown <markdown_file> --theme <theme> [--color <color>] [--no-cite]
${BUN_X} {baseDir}/scripts/wechat-article.ts --html <html_file>
Step 5: Completion Report
WeChat Publishing Complete!
Input: [type] - [path]
Method: [API | Browser]
Theme: [theme] [color if set]
Article:
• Title: [title]
• Summary: [summary]
• Images: [N] inline
• Comments: [open/closed], [fans-only/all] ← API method only
Result:
✓ Draft saved to WeChat Official Account
• media_id: [media_id] ← API method only
Next Steps (API):
→ Manage drafts: https://mp.weixin.qq.com (登录后进入「内容管理」→「草稿箱」)
Files created:
[• post-to-wechat/YYYY-MM-DD/slug.md (if plain text input)]
[• slug.html (converted)]
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 | ✗ | ✓ | ✗ |
| Requires Chrome | ✓ | ✗ | ✓ |
| Requires API credentials | ✗ | ✓ | ✗ |
| Speed | Medium | Fast | Slow |
Troubleshooting
| Issue | Fix |
|---|---|
| Missing API credentials | Follow guided setup in Step 2 |
| Access token error | Verify credentials 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 |
| 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 need_open_comment / only_fans_can_comment in EXTEND.md |
| Paste fails | Check system clipboard permissions |
References
| File | Content |
|---|---|
references/image-text-posting.md |
Image-text parameters, auto-compression |
references/article-posting.md |
Article themes, image handling |
references/multi-account.md |
Multi-account compatibility, credentials, Chrome profiles, CLI |
references/api-setup.md |
Guided credential setup |
references/config/first-time-setup.md |
First-time EXTEND.md setup |
Extension Support
Custom configurations via EXTEND.md. See "Preferences" for paths and supported options.