baoyu-post-to-wechat

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

baoyu-post-to-wechat (Community Edition)

baoyu-post-to-wechat (社区版)

Community edition posts directly to WeChat Official Account API from local machine.
社区版可直接从本地设备调用微信公众号API发布内容。

Runtime

运行环境

  • Entry script:
    scripts/wechat-api.ts
  • Run command:
bash
bun .agents/skills/baoyu-post-to-wechat/scripts/wechat-api.ts <file> [options]
  • 入口脚本:
    scripts/wechat-api.ts
  • 运行命令:
bash
bun .agents/skills/baoyu-post-to-wechat/scripts/wechat-api.ts <file> [options]

Credentials

凭证配置

Put credentials in shared
.agents/skills/.env
:
dotenv
WECHAT_APP_ID=...
WECHAT_APP_SECRET=...
Resolution order:
  1. Process env
  2. .agents/skills/.env
将凭证存入共享的
.agents/skills/.env
文件:
dotenv
WECHAT_APP_ID=...
WECHAT_APP_SECRET=...
读取优先级顺序:
  1. 进程环境变量
  2. .agents/skills/.env
    文件

Scope

适用范围

This skill only targets draft box saving (
draft/add
), not mass-send.
本工具仅支持保存到草稿箱(
draft/add
接口),不支持群发功能。

Publishing Rules

发布规则

  1. Cover image uses permanent material API (
    material/add_material
    , type=image), obtains
    thumb_media_id
    .
  2. Inline images in article HTML use
    media/uploadimg
    , obtains public
    url
    .
  3. Save draft through
    draft/add
    with article payload.
  4. need_open_comment=1
    ,
    only_fans_can_comment=0
    by default.
  1. 封面图调用永久素材API(
    material/add_material
    , type=image),获取
    thumb_media_id
  2. 文章HTML中的内嵌图片调用
    media/uploadimg
    接口,获取公开可访问的
    url
  3. 携带文章请求参数通过
    draft/add
    接口保存草稿。
  4. 默认配置为
    need_open_comment=1
    (开启评论)、
    only_fans_can_comment=0
    (非仅粉丝可评论)。

Official API Mapping

官方API映射

  • draft/add
    (
    article_type=news
    ):
    • thumb_media_id
      must be a permanent
      media_id
      .
    • content
      image URLs must come from
      media/uploadimg
      .
  • material/add_material?type=image
    : cover and other permanent image assets.
  • media/uploadimg
    : inline images for article HTML content.
  • draft/add
    (
    article_type=news
    ):
    • thumb_media_id
      必须是永久有效的
      media_id
    • content
      字段中的图片URL必须来自
      media/uploadimg
      接口的返回值。
  • material/add_material?type=image
    : 用于上传封面图和其他永久图片素材。
  • media/uploadimg
    : 用于上传文章HTML内容中的内嵌图片。

Recommended Operation Order

推荐操作流程

  1. Normalize Obsidian image syntax (including
    ![[...]]
    ) to standard markdown image form.
  2. Render markdown to HTML.
  3. Upload inline images with
    uploadimg
    and replace
    <img src>
    with returned URLs.
  4. Upload cover with permanent material API and get
    thumb_media_id
    .
  5. Call
    draft/add
    .
  1. 将Obsidian图片语法(包括
    ![[...]]
    )统一转换为标准Markdown图片格式。
  2. 将Markdown内容渲染为HTML。
  3. 调用
    uploadimg
    接口上传内嵌图片,用返回的URL替换
    <img src>
    属性值。
  4. 调用永久素材API上传封面图,获取
    thumb_media_id
  5. 调用
    draft/add
    接口。

Input

输入格式

  • .md
    or
    .html
  • If input is markdown, script converts markdown first, then uploads inline images and publishes.
  • 支持
    .md
    .html
    格式文件
  • 如果输入为Markdown格式,脚本会先完成格式转换,再上传内嵌图片并发布。

Examples

使用示例

bash
undefined
bash
undefined

Basic markdown draft publish

基础Markdown草稿发布

bun .agents/skills/baoyu-post-to-wechat/scripts/wechat-api.ts article.md
bun .agents/skills/baoyu-post-to-wechat/scripts/wechat-api.ts article.md

Explicit cover and metadata

显式指定封面和元数据

bun .agents/skills/baoyu-post-to-wechat/scripts/wechat-api.ts article.md
--cover Assets/Cover-Images/my-topic/cover.jpg
--title "标题"
--author "作者"
--summary "摘要"
bun .agents/skills/baoyu-post-to-wechat/scripts/wechat-api.ts article.md
--cover Assets/Cover-Images/my-topic/cover.jpg
--title "标题"
--author "作者"
--summary "摘要"

HTML input

HTML输入格式

bun .agents/skills/baoyu-post-to-wechat/scripts/wechat-api.ts article.html --cover Assets/cover.jpg
undefined
bun .agents/skills/baoyu-post-to-wechat/scripts/wechat-api.ts article.html --cover Assets/cover.jpg
undefined

Notes

注意事项

  • WeChat requires inline article images to come from
    uploadimg
    URLs.
  • Cover and inline image APIs are different and both are required for stable draft publishing.
  • 微信要求文章内嵌图片的URL必须来自
    uploadimg
    接口的返回值。
  • 封面图和内嵌图片使用的API不同,二者都需正确调用才能保证草稿发布稳定。