byjimliu· 68 skills
Posts content to WeChat Official Account (微信公众号) via API or Chrome CDP. Supports article posting (文章) with HTML, markdown, or plain text input, and image-text posting (贴图, formerly 图文) with multiple images. Markdown article workflows default to converting ordinary external links into bottom citations for WeChat-friendly output. Use when user mentions "发布公众号", "post to wechat", "微信公众号", or "贴图/图文/文章".
$npx -y skills add jimliu/baoyu-skills --skill baoyu-post-to-wechatInstalls into the current project.
Run `npx skills use "https://github.com/jimliu/baoyu-skills" --skill "jimliu/baoyu-skills/baoyu-post-to-wechat"` and follow the generated skill instructions now. Read its complete output, redirecting it to a temporary file first if necessary. Resolve relative paths from the supporting-files directory it provides.
Use the skills in "https://github.com/jimliu/baoyu-skills" that are relevant to the current task. Run `npx skills add "https://github.com/jimliu/baoyu-skills"` and select the relevant skills, then follow their instructions.
| 1 | # Post to WeChat Official Account |
| 2 | |
| 3 | ## User Input Tools |
| 4 | |
| 5 | When this skill prompts the user, follow this tool-selection rule (priority order): |
| 6 | |
| 7 | 1. **Prefer built-in user-input tools** exposed by the current agent runtime — e.g., `AskUserQuestion`, `request_user_input`, `clarify`, `ask_user`, or any equivalent. |
| 8 | 2. **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. |
| 9 | 3. **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. |
| 10 | |
| 11 | Concrete `AskUserQuestion` references below are examples — substitute the local equivalent in other runtimes. |
| 12 | |
| 13 | ## Language |
| 14 | |
| 15 | 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. |
| 16 | |
| 17 | ## Script Directory |
| 18 | |
| 19 | `{baseDir}` = this SKILL.md's directory. Resolve `${BUN_X}`: prefer `bun`; else `npx -y bun`; else suggest `brew install oven-sh/bun/bun`. |
| 20 | |
| 21 | | Script | Purpose | |
| 22 | |--------|---------| |
| 23 | | `scripts/wechat-browser.ts` | Image-text posts (图文) | |
| 24 | | `scripts/wechat-article.ts` | Article posting via browser (文章) | |
| 25 | | `scripts/wechat-api.ts` | Article posting via API (文章) | |
| 26 | | `scripts/md-to-wechat.ts` | Markdown → WeChat-ready HTML with image placeholders | |
| 27 | | `scripts/check-permissions.ts` | Verify environment & permissions | |
| 28 | |
| 29 | ## Preferences (EXTEND.md) |
| 30 | |
| 31 | Check these paths in order; first hit wins: |
| 32 | |
| 33 | | Path | Scope | |
| 34 | |------|-------| |
| 35 | | `.baoyu-skills/baoyu-post-to-wechat/EXTEND.md` | Project | |
| 36 | | `${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-post-to-wechat/EXTEND.md` | XDG | |
| 37 | | `$HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md` | User home | |
| 38 | |
| 39 | Found → read, parse, apply. Not found → run first-time setup (`references/config/first-time-setup.md`) before anything else. |
| 40 | |
| 41 | **Minimum keys** (case-insensitive, accept `1/0` or `true/false`): |
| 42 | |
| 43 | | Key | Default | Mapping | |
| 44 | |-----|---------|---------| |
| 45 | | `default_author` | empty | Fallback for `author` when CLI/frontmatter not provided | |
| 46 | | `need_open_comment` | `1` | `articles[].need_open_comment` in `draft/add` | |
| 47 | | `only_fans_can_comment` | `0` | `articles[].only_fans_can_comment` in `draft/add` | |
| 48 | |
| 49 | **Recommended EXTEND.md**: |
| 50 | |
| 51 | ```md |
| 52 | default_theme: default |
| 53 | default_color: blue |
| 54 | default_publish_method: browser |
| 55 | default_author: 宝玉 |
| 56 | need_open_comment: 1 |
| 57 | only_fans_can_comment: 0 |
| 58 | chrome_profile_path: /path/to/chrome/profile |
| 59 | |
| 60 | # Remote API publishing (optional) — only set if WeChat's IP allowlist |
| 61 | # excludes your local machine. See "Remote API Method" below. |
| 62 | # remote_publish_host: server.example.com |
| 63 | # remote_publish_user: deploy |
| 64 | # remote_publish_port: 22 |
| 65 | # remote_publish_identity_file: ~/.ssh/id_ed25519 |
| 66 | # remote_publish_known_hosts_file: ~/.ssh/known_hosts |
| 67 | # remote_publish_strict_host_key_checking: accept-new |
| 68 | # remote_publish_connect_timeout: 10 |
| 69 | # remote_publish_proxy_jump: bastion.example.com |
| 70 | ``` |
| 71 | |
| 72 | Raw `ssh` / `scp` options are intentionally not supported; only the typed keys above are honored. Authentication is SSH key only (no passwords). |
| 73 | |
| 74 | **Theme options**: default, grace, simple, modern. **Color presets**: blue, green, vermilion, yellow, purple, sky, rose, olive, black, gray, pink, red, orange (or hex). |
| 75 | |
| 76 | **Value priority**: CLI args → frontmatter → EXTEND.md (account-level → global) → skill defaults. |
| 77 | |
| 78 | ## Multi-Account Support |
| 79 | |
| 80 | 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>`). |
| 81 | |
| 82 | Full details — compatibility rules, per-account keys, credential resolution, per-account Chrome profiles, CLI usage — in `references/multi-account.md`. |
| 83 | |
| 84 | ## Pre-flight Check (Optional) |
| 85 | |
| 86 | Before first use, suggest the environment check (user can skip): |
| 87 | |
| 88 | ```bash |
| 89 | ${BUN_X} {baseDir}/scripts/check-permissions.ts |
| 90 | ``` |
| 91 | |
| 92 | Checks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, API credentials, Chrome conflicts. |
| 93 | |
| 94 | | Check fails | Fix | |
| 95 | |-------------|-----| |
| 96 | | Chrome | Install Chrome or set `WECHAT_BROWSER_CHROME_PATH` | |
| 97 | | Profile dir | Shared profile at `baoyu-skills/chrome-profile` | |
| 98 | | Bun runtime | `brew install oven-sh/bun/bun` or `npm install -g bun` | |
| 99 | | Accessibility (macOS) | System Settings → Privacy & Security → Accessibility → enable terminal app | |
| 100 | | Clipboard copy | Ensure Swift/AppKit (macOS: `xcode-select --install`) | |
| 101 | | Paste keystroke (Linux) | Install `xdotool` (X11) or `ydotool` (Wayland) | |
| 102 | | API credentials | Follow guided setup in Step 2, or set in `.baoyu-skills/.env` | |
| 103 | |
| 104 | ## Image-Text Posting (图文) |
| 105 | |
| 106 | Short posts with multiple images (up to 9): |
| 107 | |
| 108 | ```bash |
| 109 | ${BUN_X} {baseDir}/scripts/wechat-browser.ts --markdown article.md --images ./images/ |
| 110 | ${BUN_X} {baseDir}/scripts/wechat-browser.ts --title "标题" --content "内容" --image img.png --submit |
| 111 | ``` |
| 112 | |
| 113 | Details: `references/image-text-posting.md`. |
| 114 | |
| 115 | ## Article Posting Workflow (文章) |
| 116 | |
| 117 | ``` |
| 118 | - [ ] Step 0: Load preferences (EXTEND.md) |
| 119 | - [ ] Step 0.5: Resolve account (multi-account only — see references/multi-account.md) |
| 120 | - [ ] Step 1: Determine input type |
| 121 | - [ ] Step 2: Select method and configure credentials |
| 122 | - [ ] Step 3: Resolve theme/color and validate metadata |
| 123 | - [ ] Step 4: Publish to WeChat |
| 124 | - [ ] Step 5: Report completion |
| 125 | ``` |
| 126 | |
| 127 | ### Step 0: Load Preferences |
| 128 | |
| 129 | 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`. |
| 130 | |
| 131 | ### Step 1: Determine Input Type |
| 132 | |
| 133 | | Input | Detection | Next | |
| 134 | |-------|-----------|------| |
| 135 | | HTML file | Path ends `.html`, file exists | Skip to Step 3 | |
| 136 | | Markdown file | Path ends `.md`, file exists | Step 2 | |
| 137 | | Plain text | Not a file path, or file doesn't exist | Save to markdown, then Step 2 | |
| 138 | |
| 139 | **Plain-text handling**: |
| 140 | |
| 141 | 1. Generate slug (first 2-4 meaningful words, kebab-case; translate Chinese to English for the slug). |
| 142 | 2. Save to `post-to-wechat/YYYY-MM-DD/<slug>.md` (create directory if needed). |
| 143 | 3. Continue as a markdown file. |
| 144 | |
| 145 | ### Step 2: Select Publishing Method and Configure |
| 146 | |
| 147 | Ask method unless specified in EXTEND.md or CLI: |
| 148 | |
| 149 | | Method | Speed | Requires | |
| 150 | |--------|-------|----------| |
| 151 | | `api` (Recommended) | Fast | API credentials (local IP allowlisted) | |
| 152 | | `browser` | Slow | Chrome + logged-in session | |
| 153 | | `remote-api` | Fast | API credentials + an SSH-reachable server whose IP is on the WeChat allowlist | |
| 154 | |
| 155 | **API selected + missing credentials** → run guided setup per `references/api-setup.md` (writes to `.baoyu-skills/.env`). |
| 156 | |
| 157 | **`remote-api` method**: WeChat's "公众号设置 → IP 白名单" often limits API access to one or two fixed IPs. If your local machine's IP is not on that list but a cloud server's is, use `remote-api`: all markdown rendering, image processing, draft assembly, and HTML rewriting still happen locally, and only the outbound HTTPS calls to `api.weixin.qq.com` (token, uploadimg, add_material, draft/add) are tunneled through an SSH SOCKS5 dynamic port forward (`ssh -N -D`) so that WeChat sees the remote server as the source IP. No files are written to the remote host; `AppSecret` never leaves the local process. Requires only `sshd` and outbound network on the remote host — no Python, no agent process. See "Remote API Method" below. |
| 158 | |
| 159 | ### Step 3: Resolve Theme/Color and Validate Metadata |
| 160 | |
| 161 | 1. **Theme**: CLI `--theme` → EXTEND.md `default_theme` → `default` (first match wins; do NOT ask if resolved). |
| 162 | 2. **Color**: CLI `--color` → EXTEND.md `default_color` → omit (theme default applies). |
| 163 | 3. **Validate metadata** (frontmatter for markdown, meta tags for HTML): |
| 164 | |
| 165 | | Field | Missing → | |
| 166 | |-------|-----------| |
| 167 | | Title | Ask, or press Enter to auto-generate from content | |
| 168 | | Summary | Frontmatter `description` → `summary` → ask or auto-generate | |
| 169 | | Author | CLI `--author` → frontmatter `author` → EXTEND.md `default_author` | |
| 170 | | Source URL | CLI `--source-url` → frontmatter `sourceUrl`/`contentSourceUrl`/`content_source_url` | |
| 171 | |
| 172 | Auto-generation: title = first H1/H2 or first sentence; summary = first paragraph, truncated to 120 chars. |
| 173 | |
| 174 | 4. **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. |
| 175 | |
| 176 | ### Step 4: Publish |
| 177 | |
| 178 | **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. |
| 179 | |
| 180 | **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. |
| 181 | |
| 182 | **API method** (accepts `.md` or `.html`): |
| 183 | |
| 184 | ```bash |
| 185 | ${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme <theme> [--color <color>] [--title <title>] [--summary <summary>] [--author <author>] [--cover <cover_path>] [--source-url <url>] [--no-cite] |
| 186 | ``` |
| 187 | |
| 188 | Always pass `--theme` even if it's `default`. Only pass `--color` when explicitly set by the user or EXTEND.md. |
| 189 | |
| 190 | **Remote API method** (same script, adds `--remote`): |
| 191 | |
| 192 | ```bash |
| 193 | ${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme <theme> --remote [--remote-host <host>] [--remote-user <user>] [--remote-port <port>] [--remote-identity-file <path>] [--remote-known-hosts-file <path>] [--remote-strict-host-key-checking yes|no|accept-new] [--remote-connect-timeout <s>] [--remote-proxy-jump <spec>] |
| 194 | ``` |
| 195 | |
| 196 | Any `--remote-*` flag implies `--remote`. CLI values override account-level then global `remote_publish_*` keys from EXTEND.md. Setting `default_publish_method: remote-api` also enables remote mode without `--remote`. |
| 197 | |
| 198 | **`draft/add` payload rules**: |
| 199 | - Endpoint: `POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN` |
| 200 | - `article_type`: `news` (default) or `newspic` |
| 201 | - For `news`, include `thumb_media_id` (cover required) |
| 202 | - Always include `need_open_comment` (default `1`) and `only_fans_can_comment` (default `0`) in the request body, even if the CLI doesn't expose them |
| 203 | - For `news`, optionally include `content_source_url` (original article URL, shown as "阅读原文" link, max 1KB). Provide via `--source-url` CLI flag or frontmatter `sourceUrl`/`contentSourceUrl`/`content_source_url` |
| 204 | |
| 205 | **Browser method** (accepts `--markdown` or `--html`): |
| 206 | |
| 207 | ```bash |
| 208 | ${BUN_X} {baseDir}/scripts/wechat-article.ts --markdown <markdown_file> --theme <theme> [--color <color>] [--no-cite] |
| 209 | ${BUN_X} {baseDir}/scripts/wechat-article.ts --html <html_file> |
| 210 | ``` |
| 211 | |
| 212 | ### Step 5: Completion Report |
| 213 | |
| 214 | ``` |
| 215 | WeChat Publishing Complete! |
| 216 | |
| 217 | Input: [type] - [path] |
| 218 | Method: [API | Browser] |
| 219 | Theme: [theme] [color if set] |
| 220 | |
| 221 | Article: |
| 222 | • Title: [title] |
| 223 | • Summary: [summary] |
| 224 | • Images: [N] inline |
| 225 | • Comments: [open/closed], [fans-only/all] ← API method only |
| 226 | |
| 227 | Result: |
| 228 | ✓ Draft saved to WeChat Official Account |
| 229 | • media_id: [media_id] ← API method only |
| 230 | |
| 231 | Next Steps (API): |
| 232 | → Manage drafts: https://mp.weixin.qq.com (登录后进入「内容管理」→「草稿箱」) |
| 233 | |
| 234 | Files created: |
| 235 | [• post-to-wechat/YYYY-MM-DD/slug.md (if plain text input)] |
| 236 | [• slug.html (converted)] |
| 237 | ``` |
| 238 | |
| 239 | ## Feature Comparison |
| 240 | |
| 241 | | Feature | Image-Text | Article (API) | Article (Remote API) | Article (Browser) | |
| 242 | |---------|:---:|:---:|:---:|:---:| |
| 243 | | Plain text input | ✗ | ✓ | ✓ | ✓ | |
| 244 | | HTML input | ✗ | ✓ | ✓ | ✓ | |
| 245 | | Markdown input | Title/content | ✓ | ✓ | ✓ | |
| 246 | | Multiple images | ✓ (up to 9) | ✓ (inline) | ✓ (inline) | ✓ (inline) | |
| 247 | | Themes | ✗ | ✓ | ✓ | ✓ | |
| 248 | | Auto-generate metadata | ✗ | ✓ | ✓ | ✓ | |
| 249 | | Default cover fallback (`imgs/cover.png`) | ✗ | ✓ | ✓ | ✗ | |
| 250 | | Comment control | ✗ | ✓ | ✓ | ✗ | |
| 251 | | Requires Chrome | ✓ | ✗ | ✗ | ✓ | |
| 252 | | Requires API credentials | ✗ | ✓ | ✓ | ✗ | |
| 253 | | Requires SSH-reachable server with allowlisted IP | ✗ | ✗ | ✓ | ✗ | |
| 254 | | Speed | Medium | Fast | Fast | Slow | |
| 255 | |
| 256 | ## Troubleshooting |
| 257 | |
| 258 | | Issue | Fix | |
| 259 | |-------|-----| |
| 260 | | Missing API credentials | Follow guided setup in Step 2 | |
| 261 | | Access token error | Verify credentials valid and not expired | |
| 262 | | Not logged in (browser) | First run opens browser — scan QR to log in. Set `TELEGRAM_BOT_TOKEN` + `TELEGRAM_CHAT_ID` to receive the QR image via Telegram | |
| 263 | | Chrome not found | Set `WECHAT_BROWSER_CHROME_PATH` | |
| 264 | | Title/summary missing | Use auto-generation or provide manually | |
| 265 | | No cover image | Add frontmatter cover or place `imgs/cover.png` in article directory | |
| 266 | | Wrong comment defaults | Check `need_open_comment` / `only_fans_can_comment` in EXTEND.md | |
| 267 | | Paste fails | Check system clipboard permissions | |
| 268 | | `Remote publish host is required` | Set `--remote-host` or `remote_publish_host` in EXTEND.md | |
| 269 | | `SOCKS proxy on 127.0.0.1:… not ready` | SSH could not start the tunnel — check key, host, `StrictHostKeyChecking`, or use `--remote-connect-timeout` | |
| 270 | | `ssh exited early` during remote publish | Verify the user can `ssh` non-interactively to the server; raise `--remote-connect-timeout` if the link is slow | |
| 271 | | Remote API call returns `errcode 40164` (invalid IP) | The remote server's egress IP is not on WeChat's allowlist; add it in 公众号设置 → IP 白名单 | |
| 272 | |
| 273 | ## References |
| 274 | |
| 275 | | File | Content | |
| 276 | |------|---------| |
| 277 | | `references/image-text-posting.md` | Image-text parameters, auto-compression | |
| 278 | | `references/article-posting.md` | Article themes, image handling | |
| 279 | | `references/multi-account.md` | Multi-account compatibility, credentials, Chrome profiles, CLI | |
| 280 | | `references/api-setup.md` | Guided credential setup | |
| 281 | | `references/config/first-time-setup.md` | First-time EXTEND.md setup | |
| 282 | |
| 283 | ## Extension Support |
| 284 | |
| 285 | Custom configurations via EXTEND.md. See "Preferences" for paths and supported options. |