Home / All Skills / Content & Media Creation / baoyu-post-to-wechat
Content & Media Creation · JimLiu/baoyu-skills

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 citations for WeChat-friendly output. Use when user mentions "发布公众号", "post to wechat", "微信公众号", or "贴图/图文/文章".

L5 Restricted · Isolated sandbox & strict auditV2 Human-AuditedReverse APITerms / ComplianceCredential / SessionExecute CommandNetwork AccessWrite FileDual-pass Audit
Author JimLiuGitHub JimLiu/baoyu-skills ↗Stars 25926License MIT(仓库根 LICENSE,Copyright (c) 2026 Jim Liu;GitHub API spdx_id=MIT)Commit 1567581c26
Control levels describe skill capabilities and suggested control measures; they do not represent quality or safety certifications, nor do they dictate usability. Usage decisions rest entirely with users and administrators. Different agent hosts apply varying constraints; do not assume hosts provide automatic protection. Third-party skill copyrights belong to their original authors. Use at your own risk.

1How It Works & Mechanism

Three publishing routes coexist: Official API (fast, requires credentials), Browser CDP (slower, reuses login sessions), and remote-api (local rendering + SSH SOCKS5 tunneling for outbound requests via a whitelisted server IP).

skills/baoyu-post-to-wechat/SKILL.md
| `scripts/wechat-api.ts` | Article posting via API (文章) |
The table in Step 2 of SKILL.md outlines the requirements for all three routes (whether API credentials are on the IP whitelist, whether Chrome is required, and whether an SSH-accessible server is needed).

The credential resolution chain uses an explicit multi-source priority: EXTEND.md accounts block → prefixed environment variables → WECHAT_APP_ID/WECHAT_APP_SECRET (process.env, <cwd>/.baoyu-skills/.env, ~/.baoyu-skills/.env).

skills/baoyu-post-to-wechat/scripts/wechat-extend-config.ts
buildCredentialSource("process.env", process.env, "WECHAT_APP_ID", "WECHAT_APP_SECRET"),
Throws an error when missing and prompts three configuration methods (EXTEND.md account / environment variables / .baoyu-skills/.env); the prefixed form is used for multiple accounts (one app_id/app_secret pair per account in the accounts block).

The API route follows the official WeChat four-step workflow: fetch access_token → uploadimg (body images) → material/add_material (cover assets) → draft/add (create draft).

skills/baoyu-post-to-wechat/scripts/wechat-api.ts
const DRAFT_URL = "https://api.weixin.qq.com/cgi-bin/draft/add";
The draft/add payload rules in SKILL.md define the required fields (article_type news/newspic, thumb_media_id, need_open_comment, only_fans_can_comment, and optional content_source_url).

Body images undergo transcoding and compression before uploading to meet WeChat's strict platform limits, and magic bytes are used to correct mismatches between declared and actual formats.

skills/baoyu-post-to-wechat/scripts/wechat-image-processor.ts
export const WECHAT_BODY_IMAGE_MAX_SIZE = 1024 * 1024; // 1MB
Uses jimp and @jsquash/webp (wasm decoding); wechat-image-loader.ts corrects file names and MIME types according to actual content if contentType is inconsistent.

The remote-api mechanism performs rendering, image processing, and draft assembly locally, routing only outbound HTTPS requests to api.weixin.qq.com via SSH dynamic port forwarding (SOCKS5).

skills/baoyu-post-to-wechat/SKILL.md
are tunneled through an SSH SOCKS5 dynamic port forward (`ssh -N -D`)
Implementation: wechat-remote-publish.ts assembles ssh parameters such as `-N -T -D 127.0.0.1:<port>` (supports -i identity file, KnownHosts, StrictHostKeyChecking, ConnectTimeout, -J jump host), and wechat-socks-http.ts crafts outbound requests using the socks package + tls; SKILL.md states: `No files are written to the remote host; `AppSecret` never leaves the local process.`

The browser route derives login sessions from a persistent shared Chrome profile, and launch arguments forcefully disable Chrome's automation flags (--disable-blink-features=AutomationControlled)—a classic technical anti-automation detection evasion technique.

skills/baoyu-post-to-wechat/scripts/cdp.ts
extraArgs: ['--disable-blink-features=AutomationControlled', '--start-maximized'],
launchChromeBase also includes --remote-debugging-port and --user-data-dir (profile defaults to baoyu-skills/chrome-profile, overridable by EXTEND.md chrome_profile_path), allowing long-term reuse after logging in once.

The same directory includes a 'real keypress paste' helper explicitly intended to bypass synthetic events detectable by websites.

skills/baoyu-post-to-wechat/scripts/paste-from-clipboard.ts
This bypasses CDP's synthetic events which websites can detect and ignore.
Scope clarification: In this commit, wechat-browser.ts / wechat-article.ts actually use CDP's Input.dispatchKeyEvent to send paste keys (pasteInEditor/sendPaste in wechat-article.ts). While this OS-level helper script is not directly invoked by the primary workflow, its existence and documentation share the same objective as the launch arguments in cdp.ts.

An exfiltration/outbound channel exists for login sessions: login QR codes are captured when unauthenticated and can optionally be forwarded to a specified chat via Telegram Bot.

skills/baoyu-post-to-wechat/scripts/wechat-article.ts
const tgResp = await fetch(`https://api.telegram.org/bot${botToken}/sendPhoto`, {
Triggered when both TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID are set (preceded by `if (!botToken || !chatId) return;`); QR codes are fetched from the DOM via data:/canvas first, falling back to a full-page screenshot upon failure.

Engineering toolset: EXTEND.md multi-account blocks and account resolution, alongside an upfront environment and permissions self-check script.

skills/baoyu-post-to-wechat/SKILL.md
EXTEND.md supports an `accounts:` block for managing multiple Official Accounts.
check-permissions.ts inspects Chrome, profile isolation, Bun, macOS accessibility permissions, clipboard, paste keypresses (osascript / xdotool / ydotool / PowerShell SendKeys), API credentials, and Chrome process conflicts step by step.

2Core Capabilities

01Publish articles to WeChat Official Account draft box via official API (access_token → uploadimg/add_material → draft/add)
02Publish articles via browser CDP (reuses login sessions; supports HTML, Markdown, and plain text inputs)
03Publish short image-text posts (贴图), supporting up to 9 images
04Convert Markdown into WeChat-friendly HTML (defaults to turning normal external links into bottom citations, toggleable with --no-cite)
05Automatically compress and transcode body images to meet WeChat upload limits (jimp + wasm webp decoding + format sniffing)
06remote-api: routes only WeChat outbound traffic through an SSH SOCKS5 tunnel to an IP-whitelisted server
07Multi-account support (EXTEND.md accounts block + --account selector + dedicated Chrome profile per account)
08Upfront environment and permissions self-check (Chrome, profile, Bun, accessibility permissions, clipboard, paste keypresses, API credentials, Chrome conflicts)

3External Dependencies

KindDependency / Endpoint
api微信公众平台 access_token
api正文图片上传(uploadimg)
api永久素材/封面上传(add_material)
api建草稿(draft/add,含 need_open_comment / only_fans_can_comment 等字段)
apiTelegram Bot API(可选:把登录二维码发到指定聊天)
network浏览器访问 mp.weixin.qq.com(公众号后台登录与发文界面)
clissh(-N -D SOCKS5 动态端口转发;仅密钥认证)
cli本地 Chrome/Chromium(--remote-debugging-port 启动,带 AutomationControlled 关闭参数)
cli系统剪贴板工具(macOS: swift/osascript;Linux: wl-copy 或 xclip;Windows: powershell.exe)
cli粘贴按键工具(macOS osascript System Events;Linux xdotool/ydotool;Windows PowerShell SendKeys)
packagejimp / @jsquash/webp / socks / baoyu-md / baoyu-chrome-cdp
clibun(内部以 npx -y bun 调起同目录脚本)

4Recommended Governance & Evidence

Suggested Controls for Safe Operation
For Agent Runtime
Isolated environment, per-use explicit authorization
For Administrators
Strict authorization, full audit, compliance signoff
Evidence & Triggers (File Paths & Excerpts)
  • SKILL.md / 脚本: Calls undocumented or reverse-engineered private APIs / Spoofs client identity
  • SKILL.md / 脚本参数: Bypasses automation detection, disables host sandbox, or skips SSL certificate verification
  • SKILL.md / 会话存储: Reads or reuses browser user login sessions and session cookies
  • scripts/: Executes local script or command: bun {baseDir}/scripts/wechat-api.ts <file> --theme … [--remote …] (API route)
  • 网络端点: Declares external network access: https://api.weixin.qq.com (token / uploadimg / add_material / draft/add) — usable
  • 本地工作目录: File read/write and artifact output: Locally rendered HTML to be pasted and processed body image artifacts (for WeChat upload)
Audit Notes: Flagged RED at the 'capability/policy level'; the violation originates directly within this skill directory: (1) [Technical Anti-Automation Detection Evasion] scripts/cdp.ts forcibly launches Chrome with `extraArgs: ['--disable-blink-features=AutomationControlled', '--start-maximized'],` (line 125, the entry point for all browser workflows); in the same directory, scripts/paste-from-clipboard.ts explicitly documents its purpose as `This bypasses CDP's synthetic events which websites can detect and ignore.` (Scope note: in this commit, the primary wechat-browser/wechat-article workflow uses CDP's Input.dispatchKeyEvent for paste keystrokes, leaving this OS-level helper uninvoked by the main path). Precedent reference: notebooklm-skill was flagged RED for the same `--disable-blink-features=AutomationControlled`. (2) [Credential Surface] Reads account credentials WECHAT_APP_ID/WECHAT_APP_SECRET (across multiple sources: EXTEND.md/env/.env), optional SSH private keys, and Telegram bot tokens for its stated purposes, while reusing a shared Chrome profile containing login sessions; (3) [External Side Effects] draft/add creates drafts in the official account backend, the browser/image-text routes can submit via --submit, and unauthenticated sessions can optionally forward login QR codes to Telegram. Conclusion: No TLS downgrade, no sandbox downgrade, no unescaped interpolation, no client impersonation; the RED flag is triggered specifically by the anti-automation detection bypass itself.

5Second-Pass Verification

  • [ok] 反自动化检测绕过(判红主因) — scripts/cdp.ts:125 `extraArgs: ['--disable-blink-features=AutomationControlled', '--start-maximized'],` 由 launchChromeBase 传给 Chrome(浏览器脚本共用);scripts/paste-from-clipboard.ts:5-7 明写 'This bypasses CDP's synthetic events which websites can detect and ignore.'
  • [ok] 该绕过是否真的在发布路径上 — cdp.ts 的 Chrome 启动函数是 wechat-browser.ts 与 wechat-article.ts 的入口(两者都从 cdp.ts 导入并把自动化参数交给 launchChromeBase);paste 助手本身在本 commit 未被这两个主流程引用,已在 reason/injection_surface 如实标注程度。
  • [ok] 凭证读取链 — wechat-extend-config.ts 的 loadCredentials 依次尝试 EXTEND.md account → 前缀 env/.env → WECHAT_APP_ID/WECHAT_APP_SECRET(process.env、cwd .env、home .env),与 SKILL.md 描述一致。
  • [ok] 微信 API 端点与 payload 规则 — wechat-api.ts 常量区四个 URL 与 SKILL.md 的 draft/add payload rules(article_type/thumb_media_id/need_open_comment/only_fans_can_comment/content_source_url)逐项对应。
  • [ok] remote-api 的隧道实现与承诺 — wechat-remote-publish.ts 组装 `-N -T -D 127.0.0.1:<port>` 等参数且仅用密钥(`if (config.identityFile) args.push("-i", …)`);SKILL.md 承诺不在远端落文件、AppSecret 不出本机——源码内确无远端文件写入路径(只建隧道与本地 SOCKS 出站)。
  • [ok] Telegram 二维码外发为可选 — wechat-article.ts sendQrToTelegram 在 `if (!botToken || !chatId) return;` 之后才发请求;未配置即完全不走该路径。
  • [ok] 依赖与剪贴板工具链 — package.json/bun.lock 声明 jimp、@jsquash/webp、socks、baoyu-md、baoyu-chrome-cdp;copy-to-clipboard.ts 分别用 swift/osascript、wl-copy/xclip、powershell.exe,与 check-permissions.ts 的检查项一致。
  • [ok] 无其他安全降级 — 全目录 grep no-sandbox / rejectUnauthorized / insecure / NODE_TLS_REJECT_UNAUTHORIZED 零命中;Chrome 启动参数仅常规项 + AutomationControlled。

6Verdict & Scenarios

  • Three routes accommodate real-world constraints: use fast API with credentials, remote-api tunnel when IP is not whitelisted, or browser with login sessions when lacking credentials.
  • Restrained remote-api architecture: local rendering + only WeChat outbound traffic over SOCKS5, keeping AppSecret on the local machine without remote file footprint.
  • Tailored for platform constraints: automatic transcoding for 1MB/format body image limits, fallback chains for missing covers, and external links converted to bottom citations by default.
  • Comprehensive input handling and metadata validation: distinct pipelines for HTML/Markdown/plain text, with clear fallback rules when title/digest/author/source are missing.
  • Complete operational tooling: permission self-check scripts, first-time setup onboarding, multi-account documentation, and remote publishing troubleshooting tables (including 40164 whitelist hints).
  • Best for: Suitable for content creators and teams needing to reliably publish prepared articles and image-text posts to their WeChat Official Accounts: use remote-api with an IP-whitelisted server, or the browser route without API credentials; Markdown writers can directly ingest outputs from markdown-to-html, and multi-account operators can switch accounts via the accounts block.
    Not for: Not suitable for scenarios unwilling to store AppSecret locally or reuse browser login sessions; not suitable for posting on behalf of third-party accounts or evading platform risk controls (this skill includes anti-automation detection evasion, flagged RED); not suitable for compliance-sensitive workflows where publishing is fully delegated to an autonomous agent (recommended to use only the API draft path, avoiding the browser route's --submit).
    Install Agent-Ready
    ① Verified Mirror 2026-09-15
    Option A · Direct DownloadDownload baoyu-post-to-wechat.tar.gz
    sha256: 1f149b01778641d8…
    Option B · Copy Guide for Agent
    install.json
    Agents automatically download and verify mirrors from this JSON guide.
    ② Upstream GitHub
    GitHub Repo ↗
    Pinned to commit 1567581c26.