baoyu-post-to-wechat
Original:🇺🇸 English
Translated
36 scripts
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 "贴图/图文/文章".
11installs
Sourcelvgj-stack/baoyu-skills
Added on
NPX Install
npx skill4agent add lvgj-stack/baoyu-skills baoyu-post-to-wechatTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Post to WeChat Official Account
Language
Match user's language: Respond in the same language the user uses. If user writes in Chinese, respond in Chinese. If user writes in English, respond in English.
Script Directory
Agent Execution: Determine this SKILL.md directory as , then use . Resolve runtime: if installed → ; if available → ; else suggest installing bun.
{baseDir}{baseDir}/scripts/<name>.ts${BUN_X}bunbunnpxnpx -y bun| Script | Purpose |
|---|---|
| Image-text posts (图文) |
| Article posting via browser (文章) |
| Article posting via API (文章) |
| Markdown → WeChat-ready HTML with image placeholders |
| Verify environment & permissions |
Preferences (EXTEND.md)
Check EXTEND.md existence (priority order):
bash
# macOS, Linux, WSL, Git Bash
test -f .baoyu-skills/baoyu-post-to-wechat/EXTEND.md && echo "project"
test -f "${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-post-to-wechat/EXTEND.md" && echo "xdg"
test -f "$HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md" && echo "user"powershell
# PowerShell (Windows)
if (Test-Path .baoyu-skills/baoyu-post-to-wechat/EXTEND.md) { "project" }
$xdg = if ($env:XDG_CONFIG_HOME) { $env:XDG_CONFIG_HOME } else { "$HOME/.config" }
if (Test-Path "$xdg/baoyu-skills/baoyu-post-to-wechat/EXTEND.md") { "xdg" }
if (Test-Path "$HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md") { "user" }┌────────────────────────────────────────────────────────┬───────────────────┐
│ Path │ Location │
├────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-post-to-wechat/EXTEND.md │ Project directory │
├────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md │ User home │
└────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│ Result │ Action │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Found │ Read, parse, apply settings │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Not found │ Run first-time setup (references/config/first-time-setup.md) → Save → Continue │
└───────────┴───────────────────────────────────────────────────────────────────────────┘
EXTEND.md Supports: Default theme | Default color | Default publishing method (api/browser) | Default author | Default open-comment switch | Default fans-only-comment switch | Chrome profile path
First-time setup: references/config/first-time-setup.md
Minimum supported keys (case-insensitive, accept or ):
1/0true/false| Key | Default | Mapping |
|---|---|---|
| empty | Fallback for |
| | |
| | |
Recommended EXTEND.md example:
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/profileTheme options: default, grace, simple, modern
Color presets: blue, green, vermilion, yellow, purple, sky, rose, olive, black, gray, pink, red, orange (or hex value)
Value priority:
- CLI arguments
- Frontmatter
- EXTEND.md (account-level → global-level)
- Skill defaults
Multi-Account Support
EXTEND.md supports managing multiple WeChat Official Accounts. When block is present, each account can have its own credentials, Chrome profile, and default settings.
accounts:Compatibility rules:
| Condition | Mode | Behavior |
|---|---|---|
No | Single-account | Current behavior, unchanged |
| Single-account | Auto-select, no prompt |
| Multi-account | Prompt to select before publishing |
| Multi-account | Pre-select default, user can switch |
Multi-account EXTEND.md example:
md
default_theme: default
default_color: blue
accounts:
- name: 宝玉的技术分享
alias: baoyu
default: true
default_publish_method: api
default_author: 宝玉
need_open_comment: 1
only_fans_can_comment: 0
app_id: your_wechat_app_id
app_secret: your_wechat_app_secret
- name: AI工具集
alias: ai-tools
default_publish_method: browser
default_author: AI工具集
need_open_comment: 1
only_fans_can_comment: 0Per-account keys (can be set per-account or globally as fallback):
, , , , , ,
default_publish_methoddefault_authorneed_open_commentonly_fans_can_commentapp_idapp_secretchrome_profile_pathGlobal-only keys (always shared across accounts):
,
default_themedefault_colorAccount Selection (Step 0.5)
Insert between Step 0 and Step 1 in the Article Posting Workflow:
if no accounts block:
→ single-account mode (current behavior)
elif accounts.length == 1:
→ auto-select the only account
elif --account <alias> CLI arg:
→ select matching account
elif one account has default: true:
→ pre-select, show: "Using account: <name> (--account to switch)"
else:
→ prompt user:
"Multiple WeChat accounts configured:
1) <name1> (<alias1>)
2) <name2> (<alias2>)
Select account [1-N]:"Credential Resolution (API Method)
For a selected account with alias :
{alias}- /
app_idinline in EXTEND.md account blockapp_secret - Env var /
WECHAT_{ALIAS}_APP_ID(alias uppercased, hyphens → underscores)WECHAT_{ALIAS}_APP_SECRET - with prefixed key
.baoyu-skills/.envWECHAT_{ALIAS}_APP_ID - with prefixed key
~/.baoyu-skills/.env - Fallback to unprefixed /
WECHAT_APP_IDWECHAT_APP_SECRET
.env multi-account example:
bash
# Account: baoyu
WECHAT_BAOYU_APP_ID=your_wechat_app_id
WECHAT_BAOYU_APP_SECRET=your_wechat_app_secret
# Account: ai-tools
WECHAT_AI_TOOLS_APP_ID=your_ai_tools_wechat_app_id
WECHAT_AI_TOOLS_APP_SECRET=your_ai_tools_wechat_app_secretChrome Profile (Browser Method)
Each account uses an isolated Chrome profile for independent login sessions:
| Source | Path |
|---|---|
Account | Use as-is |
| Auto-generated from alias | |
| Single-account fallback | Shared default profile (current behavior) |
CLI --account
Argument
--accountAll publishing scripts accept :
--account <alias>bash
${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme default --account ai-tools
${BUN_X} {baseDir}/scripts/wechat-article.ts --markdown <file> --theme default --account baoyu
${BUN_X} {baseDir}/scripts/wechat-browser.ts --markdown <file> --images ./photos/ --account baoyuPre-flight Check (Optional)
Before first use, suggest running the environment check. User can skip if they prefer.
bash
${BUN_X} {baseDir}/scripts/check-permissions.tsChecks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, API credentials, Chrome conflicts.
If any check fails, provide fix guidance per item:
| Check | Fix |
|---|---|
| Chrome | Install Chrome or set |
| Profile dir | Shared profile at |
| Bun runtime | |
| Accessibility (macOS) | System Settings → Privacy & Security → Accessibility → enable terminal app |
| Clipboard copy | Ensure Swift/AppKit available (macOS Xcode CLI tools: |
| Paste keystroke (macOS) | Same as Accessibility fix above |
| Paste keystroke (Linux) | Install |
| API credentials | Follow guided setup in Step 2, or manually set in |
Image-Text Posting (图文)
For short posts with multiple images (up to 9):
bash
${BUN_X} {baseDir}/scripts/wechat-browser.ts --markdown article.md --images ./images/
${BUN_X} {baseDir}/scripts/wechat-browser.ts --title "标题" --content "内容" --image img.png --submitSee references/image-text-posting.md for details.
Article Posting Workflow (文章)
Copy this checklist and check off items as you complete them:
Publishing Progress:
- [ ] Step 0: Load preferences (EXTEND.md)
- [ ] Step 0.5: Resolve account (multi-account only)
- [ ] 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 completionStep 0: Load Preferences
Check and load EXTEND.md settings (see Preferences section above).
CRITICAL: If not found, complete first-time setup BEFORE any other steps or questions.
Resolve and store these defaults for later steps:
- (default
default_theme)default - (omit if not set — theme default applies)
default_color default_author- (default
need_open_comment)1 - (default
only_fans_can_comment)0
Step 1: Determine Input Type
| Input Type | Detection | Action |
|---|---|---|
| HTML file | Path ends with | Skip to Step 3 |
| Markdown file | Path ends with | Continue to Step 2 |
| Plain text | Not a file path, or file doesn't exist | Save to markdown, continue to Step 2 |
Plain Text Handling:
- Generate slug from content (first 2-4 meaningful words, kebab-case)
- Create directory and save file:
bash
mkdir -p "$(pwd)/post-to-wechat/$(date +%Y-%m-%d)"
# Save content to: post-to-wechat/yyyy-MM-dd/[slug].md- Continue processing as markdown file
Slug Examples:
- "Understanding AI Models" →
understanding-ai-models - "人工智能的未来" → (translate to English for slug)
ai-future
Step 2: Select Publishing Method and Configure
Ask publishing method (unless specified in EXTEND.md or CLI):
| Method | Speed | Requirements |
|---|---|---|
| Fast | API credentials |
| Slow | Chrome, login session |
If API Selected - Check Credentials:
bash
# macOS, Linux, WSL, Git Bash
test -f .baoyu-skills/.env && grep -q "WECHAT_APP_ID" .baoyu-skills/.env && echo "project"
test -f "$HOME/.baoyu-skills/.env" && grep -q "WECHAT_APP_ID" "$HOME/.baoyu-skills/.env" && echo "user"powershell
# PowerShell (Windows)
if ((Test-Path .baoyu-skills/.env) -and (Select-String -Quiet -Pattern "WECHAT_APP_ID" .baoyu-skills/.env)) { "project" }
if ((Test-Path "$HOME/.baoyu-skills/.env") -and (Select-String -Quiet -Pattern "WECHAT_APP_ID" "$HOME/.baoyu-skills/.env")) { "user" }If Credentials Missing - Guide Setup:
WeChat API credentials not found.
To obtain credentials:
1. Visit https://mp.weixin.qq.com
2. Go to: 开发 → 基本配置
3. Copy AppID and AppSecret
Where to save?
A) Project-level: .baoyu-skills/.env (this project only)
B) User-level: ~/.baoyu-skills/.env (all projects)After location choice, prompt for values and write to :
.envWECHAT_APP_ID=<user_input>
WECHAT_APP_SECRET=<user_input>Step 3: Resolve Theme/Color and Validate Metadata
-
Resolve theme (first match wins, do NOT ask user if resolved):
- CLI argument
--theme - EXTEND.md (loaded in Step 0)
default_theme - Fallback:
default
- CLI
-
Resolve color (first match wins):
- CLI argument
--color - EXTEND.md (loaded in Step 0)
default_color - Omit if not set (theme default applies)
- CLI
-
Validate metadata from frontmatter (markdown) or HTML meta tags (HTML input):
| Field | If Missing |
|---|---|
| Title | Prompt: "Enter title, or press Enter to auto-generate from content" |
| Summary | Prompt: "Enter summary, or press Enter to auto-generate (recommended for SEO)" |
| Author | Use fallback chain: CLI |
Auto-Generation Logic:
- Title: First H1/H2 heading, or first sentence
- Summary: First paragraph, truncated to 120 characters
- Cover Image Check (required for API ):
article_type=news- Use CLI if provided.
--cover - Else use frontmatter (,
coverImage,featureImage,cover).image - Else check article directory default path: .
imgs/cover.png - Else fallback to first inline content image.
- If still missing, stop and request a cover image before publishing.
- Use CLI
Step 4: Publish to WeChat
CRITICAL: Publishing scripts handle markdown conversion internally. Do NOT pre-convert markdown to HTML — pass the original markdown file directly. This ensures the API method renders images as tags (for API upload) while the browser method uses placeholders (for paste-and-replace workflow).
<img>Markdown citation default:
- For markdown input, ordinary external links are converted to bottom citations by default.
- Use only if the user explicitly wants to keep ordinary external links inline.
--no-cite - Existing HTML input is left as-is; no extra citation conversion is applied.
API method (accepts or ):
.md.htmlbash
${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme <theme> [--color <color>] [--title <title>] [--summary <summary>] [--author <author>] [--cover <cover_path>] [--no-cite]CRITICAL: Always include parameter. Never omit it, even if using . Only include if explicitly set by user or EXTEND.md.
--themedefault--colordraft/add- Use endpoint:
POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN - :
article_type(default) ornewsnewspic - For , include
news(cover is required)thumb_media_id - Always resolve and send:
- (default
need_open_comment)1 - (default
only_fans_can_comment)0
- resolution: CLI
author→ frontmatter--author→ EXTEND.mdauthordefault_author
If script parameters do not expose the two comment fields, still ensure final API request body includes resolved values.
Browser method (accepts or ):
--markdown--htmlbash
${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
For API method, include draft management link:
WeChat Publishing Complete!
Input: [type] - [path]
Method: API
Theme: [theme name] [color if set]
Article:
• Title: [title]
• Summary: [summary]
• Images: [N] inline images
• Comments: [open/closed], [fans-only/all users]
Result:
✓ Draft saved to WeChat Official Account
• media_id: [media_id]
Next Steps:
→ Manage drafts: https://mp.weixin.qq.com (登录后进入「内容管理」→「草稿箱」)
Files created:
[• post-to-wechat/yyyy-MM-dd/slug.md (if plain text)]
[• slug.html (converted)]For Browser method:
WeChat Publishing Complete!
Input: [type] - [path]
Method: Browser
Theme: [theme name] [color if set]
Article:
• Title: [title]
• Summary: [summary]
• Images: [N] inline images
Result:
✓ Draft saved to WeChat Official Account
Files created:
[• post-to-wechat/yyyy-MM-dd/slug.md (if plain text)]
[• slug.html (converted)]Detailed References
| Topic | Reference |
|---|---|
| Image-text parameters, auto-compression | references/image-text-posting.md |
| Article themes, image handling | references/article-posting.md |
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 ( | ✗ | ✓ | ✗ |
Comment control ( | ✗ | ✓ | ✗ |
| Requires Chrome | ✓ | ✗ | ✓ |
| Requires API credentials | ✗ | ✓ | ✗ |
| Speed | Medium | Fast | Slow |
Prerequisites
For API method:
- WeChat Official Account API credentials
- Guided setup in Step 2, or manually set in
.baoyu-skills/.env
For Browser method:
- Google Chrome
- First run: log in to WeChat Official Account (session preserved)
Config File Locations (priority order):
- Environment variables
<cwd>/.baoyu-skills/.env~/.baoyu-skills/.env
Troubleshooting
| Issue | Solution |
|---|---|
| Missing API credentials | Follow guided setup in Step 2 |
| Access token error | Check if API credentials are valid and not expired |
| Not logged in (browser) | First run opens browser - scan QR to log in |
| Chrome not found | Set |
| Title/summary missing | Use auto-generation or provide manually |
| No cover image | Add frontmatter cover or place |
| Wrong comment defaults | Check |
| Paste fails | Check system clipboard permissions |
Extension Support
Custom configurations via EXTEND.md. See Preferences section for paths and supported options.