baoyu-post-to-wechat

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 citation

By jimliu · 33,548 installs

npx skills add jimliu/baoyu-skills --skill baoyu-post-to-wechat

Source repository · Upstream listing

Post to WeChat Official Account User Input Tools When this skill prompts the user, follow this tool selection rule (priority order): 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. 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. 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. 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 : Raw ssh / scp options are intentionally not supported; only the typed keys above are honored. Authentication is SSH key only (no passwords). 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): 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): Details: references/image text posting.md . Article Posting Workflow (文章) 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 : 1. Generate slug (first 2 4 meaningful words, kebab case; translate Chinese to English for the slug). 2. Save to post to wechat/YYYY MM DD/<slug .md (create directory if needed). 3. 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 (local IP allowlisted) browser Slow Chrome + logged in session remote api Fast API credentials + an SSH reachable server whose IP is on the WeChat allowlist API selected + missing credentials → run guided setup per references/api setup.md (writes to .baoyu skills/.env ). 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. Step 3: Resolve Theme/Color and Validate Metadata 1. Theme : CLI theme → EXTEND.md default theme → default (first match wins; do NOT ask if resolved). 2. Color : CLI color → EXTEND.md default color → omit (theme default applies). 3. 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 Source URL CLI source url → frontmatter sourceUrl / contentSourceUrl / content source url Auto generation: title = first H1/H2 or first sentence; summary = first paragraph, truncated to 120 chars. 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. 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 ): Always pass theme even if it's default . Only pass color when explicitly set by the user or EXTEND.md. Remote API method (same script, adds remote ): 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 . draft/add payload rules : Endpoint: POST https://api.weixin.qq.com/cgi bin/draft/add?access token=ACCESS TOKEN article type : news (default) or newspic For news , include thumb media id (cover required) 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 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 Browser method (accepts markdown or html ): Step 5: Completion Report Feature Comparison Feature Image Text Article (API) Article (Remote API) Article (Browser) : : : : : : : : Plain text input ✗ ✓ ✓ ✓ HTML input ✗ ✓ ✓ ✓ Markdown input Title/content ✓ ✓ ✓ Multiple images ✓ (up to 9) ✓ (inline) ✓ (inline) ✓ (inline) Themes ✗ ✓ ✓ ✓ Auto generate metadata ✗ ✓ ✓ ✓ Default cover fallback ( imgs/cover.png ) ✗ ✓ ✓ ✗ Comment control ✗ ✓ ✓ ✗ Requires Chrome ✓ ✗ ✗ ✓ Requires API credentials ✗ ✓ ✓ ✗ Requires SSH reachable server with allowlisted IP ✗ ✗ ✓ ✗ Speed Medium Fast 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. Set TELEGRAM BOT TOKEN + TELEGRAM CHAT ID to receive the QR image via Telegram 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 Remote publish host is required Set remote host or remote publish host in EXTEND.md SOCKS proxy on 127.0.0.1:… not ready SSH could not start the tunnel — check key, host, StrictHostKeyChecking , or use remote connect timeout 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 Remote API call returns errcode 40164 (invalid IP) The remote server's egress IP is not on WeChat's allowlist; add it in 公众号设置 → IP 白名单 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.