Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Post articles and image-text content to WeChat Official Account via API or Chrome CDP, with markdown-to-WeChat HTML conversion.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: baoyu-post-to-wechat3description: 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 "贴图/图文/文章".4version: 1.56.15metadata:6openclaw:7homepage: https://github.com/JimLiu/baoyu-skills#baoyu-post-to-wechat8requires:9anyBins:10- bun11- npx12---1314# Post to WeChat Official Account1516## User Input Tools1718When this skill prompts the user, follow this tool-selection rule (priority order):19201. **Prefer built-in user-input tools** exposed by the current agent runtime — e.g., `AskUserQuestion`, `request_user_input`, `clarify`, `ask_user`, or any equivalent.212. **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.223. **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.2324Concrete `AskUserQuestion` references below are examples — substitute the local equivalent in other runtimes.2526## Language2728Respond 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.2930## Script Directory3132`{baseDir}` = this SKILL.md's directory. Resolve `${BUN_X}`: prefer `bun`; else `npx -y bun`; else suggest `brew install oven-sh/bun/bun`.3334| Script | Purpose |35|--------|---------|36| `scripts/wechat-browser.ts` | Image-text posts (图文) |37| `scripts/wechat-article.ts` | Article posting via browser (文章) |38| `scripts/wechat-api.ts` | Article posting via API (文章) |39| `scripts/md-to-wechat.ts` | Markdown → WeChat-ready HTML with image placeholders |40| `scripts/check-permissions.ts` | Verify environment & permissions |4142## Preferences (EXTEND.md)4344Check these paths in order; first hit wins:4546| Path | Scope |47|------|-------|48| `.baoyu-skills/baoyu-post-to-wechat/EXTEND.md` | Project |49| `${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-post-to-wechat/EXTEND.md` | XDG |50| `$HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md` | User home |5152Found → read, parse, apply. Not found → run first-time setup (`references/config/first-time-setup.md`) before anything else.5354**Minimum keys** (case-insensitive, accept `1/0` or `true/false`):5556| Key | Default | Mapping |57|-----|---------|---------|58| `default_author` | empty | Fallback for `author` when CLI/frontmatter not provided |59| `need_open_comment` | `1` | `articles[].need_open_comment` in `draft/add` |60| `only_fans_can_comment` | `0` | `articles[].only_fans_can_comment` in `draft/add` |6162**Recommended EXTEND.md**:6364```md65default_theme: default66default_color: blue67default_publish_method: api68default_author: 宝玉69need_open_comment: 170only_fans_can_comment: 071chrome_profile_path: /path/to/chrome/profile72```7374**Theme options**: default, grace, simple, modern. **Color presets**: blue, green, vermilion, yellow, purple, sky, rose, olive, black, gray, pink, red, orange (or hex).7576**Value priority**: CLI args → frontmatter → EXTEND.md (account-level → global) → skill defaults.7778## Multi-Account Support7980EXTEND.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>`).8182Full details — compatibility rules, per-account keys, credential resolution, per-account Chrome profiles, CLI usage — in `references/multi-account.md`.8384## Pre-flight Check (Optional)8586Before first use, suggest the environment check (user can skip):8788```bash89${BUN_X} {baseDir}/scripts/check-permissions.ts90```9192Checks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, API credentials, Chrome conflicts.9394| 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` |103104## Image-Text Posting (图文)105106Short posts with multiple images (up to 9):107108```bash109${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 --submit111```112113Details: `references/image-text-posting.md`.114115## Article Posting Workflow (文章)116117```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 type121- [ ] Step 2: Select method and configure credentials122- [ ] Step 3: Resolve theme/color and validate metadata123- [ ] Step 4: Publish to WeChat124- [ ] Step 5: Report completion125```126127### Step 0: Load Preferences128129Check 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`.130131### Step 1: Determine Input Type132133| 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 |138139**Plain-text handling**:1401411. Generate slug (first 2-4 meaningful words, kebab-case; translate Chinese to English for the slug).1422. Save to `post-to-wechat/YYYY-MM-DD/<slug>.md` (create directory if needed).1433. Continue as a markdown file.144145### Step 2: Select Publishing Method and Configure146147Ask method unless specified in EXTEND.md or CLI:148149| Method | Speed | Requires |150|--------|-------|----------|151| `api` (Recommended) | Fast | API credentials |152| `browser` | Slow | Chrome + logged-in session |153154**API selected + missing credentials** → run guided setup per `references/api-setup.md` (writes to `.baoyu-skills/.env`).155156### Step 3: Resolve Theme/Color and Validate Metadata1571581. **Theme**: CLI `--theme` → EXTEND.md `default_theme` → `default` (first match wins; do NOT ask if resolved).1592. **Color**: CLI `--color` → EXTEND.md `default_color` → omit (theme default applies).1603. **Validate metadata** (frontmatter for markdown, meta tags for HTML):161162| Field | Missing → |163|-------|-----------|164| Title | Ask, or press Enter to auto-generate from content |165| Summary | Frontmatter `description` → `summary` → ask or auto-generate |166| Author | CLI `--author` → frontmatter `author` → EXTEND.md `default_author` |167168Auto-generation: title = first H1/H2 or first sentence; summary = first paragraph, truncated to 120 chars.1691704. **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.171172### Step 4: Publish173174**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.175176**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.177178**API method** (accepts `.md` or `.html`):179180```bash181${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme <theme> [--color <color>] [--title <title>] [--summary <summary>] [--author <author>] [--cover <cover_path>] [--no-cite]182```183184Always pass `--theme` even if it's `default`. Only pass `--color` when explicitly set by the user or EXTEND.md.185186**`draft/add` payload rules**:187- Endpoint: `POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN`188- `article_type`: `news` (default) or `newspic`189- For `news`, include `thumb_media_id` (cover required)190- 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 them191192**Browser method** (accepts `--markdown` or `--html`):193194```bash195${BUN_X} {baseDir}/scripts/wechat-article.ts --markdown <markdown_file> --theme <theme> [--color <color>] [--no-cite]196${BUN_X} {baseDir}/scripts/wechat-article.ts --html <html_file>197```198199### Step 5: Completion Report200201```202WeChat Publishing Complete!203204Input: [type] - [path]205Method: [API | Browser]206Theme: [theme] [color if set]207208Article:209• Title: [title]210• Summary: [summary]211• Images: [N] inline212• Comments: [open/closed], [fans-only/all] ← API method only213214Result:215✓ Draft saved to WeChat Official Account216• media_id: [media_id] ← API method only217218Next Steps (API):219→ Manage drafts: https://mp.weixin.qq.com (登录后进入「内容管理」→「草稿箱」)220221Files created:222[• post-to-wechat/YYYY-MM-DD/slug.md (if plain text input)]223[• slug.html (converted)]224```225226## Feature Comparison227228| Feature | Image-Text | Article (API) | Article (Browser) |229|---------|:---:|:---:|:---:|230| Plain text input | ✗ | ✓ | ✓ |231| HTML input | ✗ | ✓ | ✓ |232| Markdown input | Title/content | ✓ | ✓ |233| Multiple images | ✓ (up to 9) | ✓ (inline) | ✓ (inline) |234| Themes | ✗ | ✓ | ✓ |235| Auto-generate metadata | ✗ | ✓ | ✓ |236| Default cover fallback (`imgs/cover.png`) | ✗ | ✓ | ✗ |237| Comment control | ✗ | ✓ | ✗ |238| Requires Chrome | ✓ | ✗ | ✓ |239| Requires API credentials | ✗ | ✓ | ✗ |240| Speed | Medium | Fast | Slow |241242## Troubleshooting243244| Issue | Fix |245|-------|-----|246| Missing API credentials | Follow guided setup in Step 2 |247| Access token error | Verify credentials valid and not expired |248| Not logged in (browser) | First run opens browser — scan QR to log in |249| Chrome not found | Set `WECHAT_BROWSER_CHROME_PATH` |250| Title/summary missing | Use auto-generation or provide manually |251| No cover image | Add frontmatter cover or place `imgs/cover.png` in article directory |252| Wrong comment defaults | Check `need_open_comment` / `only_fans_can_comment` in EXTEND.md |253| Paste fails | Check system clipboard permissions |254255## References256257| File | Content |258|------|---------|259| `references/image-text-posting.md` | Image-text parameters, auto-compression |260| `references/article-posting.md` | Article themes, image handling |261| `references/multi-account.md` | Multi-account compatibility, credentials, Chrome profiles, CLI |262| `references/api-setup.md` | Guided credential setup |263| `references/config/first-time-setup.md` | First-time EXTEND.md setup |264265## Extension Support266267Custom configurations via EXTEND.md. See "Preferences" for paths and supported options.268