{"id":"baoyu-post-to-wechat","name":"baoyu-post-to-wechat","summary":"APIまたはChrome CDPを通じて微信公众号(WeChat)公式アカウントにコンテンツを投稿します。","body":"# Post to WeChat Official Account\n\n## User Input Tools\n\nWhen this skill prompts the user, follow this tool-selection rule (priority order):\n\n1. **Prefer built-in user-input tools** exposed by the current agent runtime — e.g., `AskUserQuestion`, `request_user_input`, `clarify`, `ask_user`, or any equivalent.\n2. **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.\n3. **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.\n\nConcrete `AskUserQuestion` references below are examples — substitute the local equivalent in other runtimes.\n\n## Language\n\nRespond 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.\n\n## Script Directory\n\n`{baseDir}` = this SKILL.md's directory. Resolve `${BUN_X}`: prefer `bun`; else `npx -y bun`; else suggest `brew install oven-sh/bun/bun`.\n\n| Script | Purpose |\n|--------|---------|\n| `scripts/wechat-browser.ts` | Image-text posts (图文) |\n| `scripts/wechat-article.ts` | Article posting via browser (文章) |\n| `scripts/wechat-api.ts` | Article posting via API (文章) |\n| `scripts/md-to-wechat.ts` | Markdown → WeChat-ready HTML with image placeholders |\n| `scripts/check-permissions.ts` | Verify environment & permissions |\n\n## Preferences (EXTEND.md)\n\nCheck these paths in order; first hit wins:\n\n| Path | Scope |\n|------|-------|\n| `.baoyu-skills/baoyu-post-to-wechat/EXTEND.md` | Project |\n| `${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-post-to-wechat/EXTEND.md` | XDG |\n| `$HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md` | User home |\n\nFound → read, parse, apply. Not found → run first-time setup (`references/config/first-time-setup.md`) before anything else.\n\n**Minimum keys** (case-insensitive, accept `1/0` or `true/false`):\n\n| Key | Default | Mapping |\n|-----|---------|---------|\n| `default_author` | empty | Fallback for `author` when CLI/frontmatter not provided |\n| `need_open_comment` | `1` | `articles[].need_open_comment` in `draft/add` |\n| `only_fans_can_comment` | `0` | `articles[].only_fans_can_comment` in `draft/add` |\n\n**Recommended EXTEND.md**:\n\n```md\ndefault_theme: default\ndefault_color: blue\ndefault_publish_method: browser\ndefault_author: 宝玉\nneed_open_comment: 1\nonly_fans_can_comment: 0\nchrome_profile_path: /path/to/chrome/profile\n\n# Remote API publishing (optional) — only set if WeChat's IP allowlist\n# excludes your local machine. See \"Remote API Method\" below.\n# remote_publish_host: server.example.com\n# remote_publish_user: deploy\n# remote_publish_port: 22\n# remote_publish_identity_file: ~/.ssh/id_ed25519\n# remote_publish_known_hosts_file: ~/.ssh/known_hosts\n# remote_publish_strict_host_key_checking: accept-new\n# remote_publish_connect_timeout: 10\n# remote_publish_proxy_jump: bastion.example.com\n```\n\nRaw `ssh` / `scp` options are intentionally not supported; only the typed keys above are honored. Authentication is SSH key only (no passwords).\n\n**Theme options**: default, grace, simple, modern. **Color presets**: blue, green, vermilion, yellow, purple, sky, rose, olive, black, gray, pink, red, orange (or hex).\n\n**Value priority**: CLI args → frontmatter → EXTEND.md (account-level → global) → skill defaults.\n\n## Multi-Account Support\n\nEXTEND.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>`).\n\nFull details — compatibility rules, per-account keys, credential resolution, per-account Chrome profiles, CLI usage — in `references/multi-account.md`.\n\n## Pre-flight Check (Optional)\n\nBefore first use, suggest the environment check (user can skip):\n\n```bash\n${BUN_X} {baseDir}/scripts/check-permissions.ts\n```\n\nChecks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, API credentials, Chrome conflicts.\n\n| Check fails | Fix |\n|-------------|-----|\n| Chrome | Install Chrome or set `WECHAT_BROWSER_CHROME_PATH` |\n| Profile dir | Shared profile at `baoyu-skills/chrome-profile` |\n| Bun runtime | `brew install oven-sh/bun/bun` or `npm install -g bun` |\n| Accessibility (macOS) | System Settings → Privacy & Security → Accessibility → enable terminal app |\n| Clipboard copy | Ensure Swift/AppKit (macOS: `xcode-select --install`) |\n| Paste keystroke (Linux) | Install `xdotool` (X11) or `ydotool` (Wayland) |\n| API credentials | Follow guided setup in Step 2, or set in `.baoyu-skills/.env` |\n\n## Image-Text Posting (图文)\n\nShort posts with multiple images (up to 9):\n\n```bash\n${BUN_X} {baseDir}/scripts/wechat-browser.ts --markdown article.md --images ./images/\n${BUN_X} {baseDir}/scripts/wechat-browser.ts --title \"标题\" --content \"内容\" --image img.png --submit\n```\n\nDetails: `references/image-text-posting.md`.\n\n## Article Posting Workflow (文章)\n\n```\n- [ ] Step 0: Load preferences (EXTEND.md)\n- [ ] Step 0.5: Resolve account (multi-account only — see references/multi-account.md)\n- [ ] Step 1: Determine input type\n- [ ] Step 2: Select method and configure credentials\n- [ ] Step 3: Resolve theme/color and validate metadata\n- [ ] Step 4: Publish to WeChat\n- [ ] Step 5: Report completion\n```\n\n### Step 0: Load Preferences\n\nCheck 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`.\n\n### Step 1: Determine Input Type\n\n| Input | Detection | Next |\n|-------|-----------|------|\n| HTML file | Path ends `.html`, file exists | Skip to Step 3 |\n| Markdown file | Path ends `.md`, file exists | Step 2 |\n| Plain text | Not a file path, or file doesn't exist | Save to markdown, then Step 2 |\n\n**Plain-text handling**:\n\n1. Generate slug (first 2-4 meaningful words, kebab-case; translate Chinese to English for the slug).\n2. Save to `post-to-wechat/YYYY-MM-DD/<slug>.md` (create directory if needed).\n3. Continue as a markdown file.\n\n### Step 2: Select Publishing Method and Configure\n\nAsk method unless specified in EXTEND.md or CLI:\n\n| Method | Speed | Requires |\n|--------|-------|----------|\n| `api` (Recommended) | Fast | API credentials (local IP allowlisted) |\n| `browser` | Slow | Chrome + logged-in session |\n| `remote-api` | Fast | API credentials + an SSH-reachable server whose IP is on the WeChat allowlist |\n\n**API selected + missing credentials** → run guided setup per `references/api-setup.md` (writes to `.baoyu-skills/.env`).\n\n**`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.\n\n### Step 3: Resolve Theme/Color and Validate Metadata\n\n1. **Theme**: CLI `--theme` → EXTEND.md `default_theme` → `default` (first match wins; do NOT ask if resolved).\n2. **Color**: CLI `--color` → EXTEND.md `default_color` → omit (theme default applies).\n3. **Validate metadata** (frontmatter for markdown, meta tags for HTML):\n\n| Field | Missing → |\n|-------|-----------|\n| Title | Ask, or press Enter to auto-generate from content |\n| Summary | Frontmatter `description` → `summary` → ask or auto-generate |\n| Author | CLI `--author` → frontmatter `author` → EXTEND.md `default_author` |\n| Source URL | CLI `--source-url` → frontmatter `sourceUrl`/`contentSourceUrl`/`content_source_url` |\n\nAuto-generation: title = first H1/H2 or first sentence; summary = first paragraph, truncated to 120 chars.\n\n4. **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.\n\n### Step 4: Publish\n\n**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.\n\n**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.\n\n**API method** (accepts `.md` or `.html`):\n\n```bash\n${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]\n```\n\nAlways pass `--theme` even if it's `default`. Only pass `--color` when explicitly set by the user or EXTEND.md.\n\n**Remote API method** (same script, adds `--remote`):\n\n```bash\n${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>]\n```\n\nAny `--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`.\n\n**`draft/add` payload rules**:\n- Endpoint: `POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN`\n- `article_type`: `news` (default) or `newspic`\n- For `news`, include `thumb_media_id` (cover required)\n- 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\n- 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`\n\n**Browser method** (accepts `--markdown` or `--html`):\n\n```bash\n${BUN_X} {baseDir}/scripts/wechat-article.ts --markdown <markdown_file> --theme <theme> [--color <color>] [--no-cite]\n${BUN_X} {baseDir}/scripts/wechat-article.ts --html <html_file>\n```\n\n### Step 5: Completion Report\n\n```\nWeChat Publishing Complete!\n\nInput: [type] - [path]\nMethod: [API | Browser]\nTheme: [theme] [color if set]\n\nArticle:\n• Title: [title]\n• Summary: [summary]\n• Images: [N] inline\n• Comments: [open/closed], [fans-only/all]    ← API method only\n\nResult:\n✓ Draft saved to WeChat Official Account\n• media_id: [media_id]                         ← API method only\n\nNext Steps (API):\n→ Manage drafts: https://mp.weixin.qq.com (登录后进入「内容管理」→「草稿箱」)\n\nFiles created:\n[• post-to-wechat/YYYY-MM-DD/slug.md (if plain text input)]\n[• slug.html (converted)]\n```\n\n## Feature Comparison\n\n| Feature | Image-Text | Article (API) | Article (Remote API) | Article (Browser) |\n|---------|:---:|:---:|:---:|:---:|\n| Plain text input | ✗ | ✓ | ✓ | ✓ |\n| HTML input | ✗ | ✓ | ✓ | ✓ |\n| Markdown input | Title/content | ✓ | ✓ | ✓ |\n| Multiple images | ✓ (up to 9) | ✓ (inline) | ✓ (inline) | ✓ (inline) |\n| Themes | ✗ | ✓ | ✓ | ✓ |\n| Auto-generate metadata | ✗ | ✓ | ✓ | ✓ |\n| Default cover fallback (`imgs/cover.png`) | ✗ | ✓ | ✓ | ✗ |\n| Comment control | ✗ | ✓ | ✓ | ✗ |\n| Requires Chrome | ✓ | ✗ | ✗ | ✓ |\n| Requires API credentials | ✗ | ✓ | ✓ | ✗ |\n| Requires SSH-reachable server with allowlisted IP | ✗ | ✗ | ✓ | ✗ |\n| Speed | Medium | Fast | Fast | Slow |\n\n## Troubleshooting\n\n| Issue | Fix |\n|-------|-----|\n| Missing API credentials | Follow guided setup in Step 2 |\n| Access token error | Verify credentials valid and not expired |\n| 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 |\n| Chrome not found | Set `WECHAT_BROWSER_CHROME_PATH` |\n| Title/summary missing | Use auto-generation or provide manually |\n| No cover image | Add frontmatter cover or place `imgs/cover.png` in article directory |\n| Wrong comment defaults | Check `need_open_comment` / `only_fans_can_comment` in EXTEND.md |\n| Paste fails | Check system clipboard permissions |\n| `Remote publish host is required` | Set `--remote-host` or `remote_publish_host` in EXTEND.md |\n| `SOCKS proxy on 127.0.0.1:… not ready` | SSH could not start the tunnel — check key, host, `StrictHostKeyChecking`, or use `--remote-connect-timeout` |\n| `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 |\n| Remote API call returns `errcode 40164` (invalid IP) | The remote server's egress IP is not on WeChat's allowlist; add it in 公众号设置 → IP 白名单 |\n\n## References\n\n| File | Content |\n|------|---------|\n| `references/image-text-posting.md` | Image-text parameters, auto-compression |\n| `references/article-posting.md` | Article themes, image handling |\n| `references/multi-account.md` | Multi-account compatibility, credentials, Chrome profiles, CLI |\n| `references/api-setup.md` | Guided credential setup |\n| `references/config/first-time-setup.md` | First-time EXTEND.md setup |\n\n## Extension Support\n\nCustom configurations via EXTEND.md. See \"Preferences\" for paths and supported options.","author":"@JimLiu","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/JimLiu/baoyu-skills/tree/main/skills/baoyu-post-to-wechat","license":"MIT","category":"writing","lang":"en","tokens":3649,"stars":0,"calls30d":1,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"references/api-setup.md","size":1186,"sha256":"7003b0ca4619191f01f50c02e5ed1c0064dae1a644ffa8d3e5ec99ce8b2884fd"},{"path":"references/article-posting.md","size":2567,"sha256":"664ac45c986318e83653b5b02ef99c891ab06998f68d205e86cf6d7693dbf992"},{"path":"references/config/first-time-setup.md","size":6317,"sha256":"2dc9a4b9b294d6683ca2079fedbc5426955d94a05d4ff97b2a079182df97f986"},{"path":"references/image-text-posting.md","size":2833,"sha256":"790000e305128340e64f6b4c17c1a146a2fee6c3e130400242cd61628388f751"},{"path":"references/multi-account.md","size":5807,"sha256":"bf15bc34787ca89e2e7b593f82f58b2f53a9e5f2340e6f2450443d9d18a9e351"},{"path":"scripts/bun.lock","size":38871,"sha256":"c4f5e12265ffd3f1051b4928fb93d581e0323552be4e9b8cf133e03c7718743f"},{"path":"scripts/cdp.ts","size":8405,"sha256":"41a8050224f7dc458f1e7bad6758ec39d1d9b09aeabe0767032a34e4d29880d5"},{"path":"scripts/check-permissions.ts","size":8833,"sha256":"740feecc61a8d5032aa997e1315916236efb6188e6bbe40ebb6bc7dbece3fbc5"},{"path":"scripts/copy-to-clipboard-mac.test.ts","size":916,"sha256":"a0d50e4fabaeb6693fae4ab528e6b54a5efde707a1f1f51cdc99e86613751d1a"},{"path":"scripts/copy-to-clipboard.ts","size":14377,"sha256":"78ea870589127501c6b1c42291dc70f76c8d97e850d564ae4a47e3041cf901f2"},{"path":"scripts/md-to-wechat.ts","size":5803,"sha256":"3fca3dbb02a7fe097668369481c8ed2ad2e634129a5defacb90eea18f7915fa4"},{"path":"scripts/package.json","size":244,"sha256":"7f418d7db7d49d4a57247887d8734a1ba8153698ea2bf3eed11b765ceab071c5"},{"path":"scripts/paste-from-clipboard.ts","size":5659,"sha256":"c01606eb970dbe874af3d99a8ed228bda70936cfad1342d0a5a659921a5e2a06"},{"path":"scripts/wechat-agent-browser.ts","size":11400,"sha256":"56853a7cac787789e326dacf0d45bb4915b7358ea25fb5c048ae59c4c07697df"},{"path":"scripts/wechat-api.ts","size":31007,"sha256":"fd1723001e62a16f55b81b8a95bde557553a2b3f6a95788f103d068284fda46a"},{"path":"scripts/wechat-article-focus.test.ts","size":2741,"sha256":"d452c53cc94cd1c9733da1a3c707f3976d629d1e5c88ea5137fd4a4727af0de2"},{"path":"scripts/wechat-article.ts","size":48947,"sha256":"7720b52ddd4b8ac8f4a9860c3c2ee4bde8e053f65c06bb21f17300adc703b48e"},{"path":"scripts/wechat-browser.ts","size":28393,"sha256":"920e9367709629e5d4e1badfae27de6668ca83d6e02e0fc77914a723921cfa8c"},{"path":"scripts/wechat-extend-config.test.ts","size":10079,"sha256":"18ed7c5450f3ae0880657a661428ca2e4fe002b7726f655f45b16ccae5c51492"},{"path":"scripts/wechat-extend-config.ts","size":14593,"sha256":"a0afe5fe6557f54a2be4db5c5da9e12f3d35a67f3e12599c93a21c57824258e0"},{"path":"scripts/wechat-http.test.ts","size":5100,"sha256":"b1788d1cfe6b52e44815dad533c34d0ac00af99f5e77dcc38ee1f92aef2032af"},{"path":"scripts/wechat-http.ts","size":2677,"sha256":"fcb1c1069a84e819e66adba24916bbb088f8bdd3c2b0aafebb9f237672b7b86d"},{"path":"scripts/wechat-image-loader.ts","size":2526,"sha256":"aed7a2699378b85e1eece4317f5e06e7b890e0843e8ff3d4ed26f8e18c8b613b"},{"path":"scripts/wechat-image-processor.ts","size":8524,"sha256":"7a93a031d080c95845810df571f7810c6c5758e39f461ea2f2ae8be635e688ff"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[{"code":"net.endpoints","kind":"exfiltration","excerpt":"api.telegram.org, api.weixin.qq.com, mmbiz.qpic.cn, mp.weixin.qq.com","message":"bundled scripts reach 4 external host(s)","severity":"warn"}],"scannedAt":"2026-08-22","hasScripts":true,"networkEndpoints":["api.telegram.org","api.weixin.qq.com","mmbiz.qpic.cn","mp.weixin.qq.com"]}}