WeChat Official Account Publishing
Goal
Turn the approved final Markdown draft for a WeChat Official Account into the platform’s native rich text and write it, together with the cover image and in-article images, to the account’s Drafts folder. Only drafts are created; it never sends mass messages.
Adapter Layer
This module is the publishing adapter for the WeChat Official Account channel, based on the open-source
wenyan CLI tool (Apache-2.0). When wenyan is unavailable, it does not block the content-creation workflow. Instead, deliver a manual publishing package according to
self-media-content-delivery
.
Prerequisite Checks
- Run to confirm that it is installed. If it is not installed, suggest
npm install -g @wenyan-md/cli
. If the user does not want to install it, deliver a manual publishing package directly.
- Confirm that the and environment variables exist. Only check for their presence; do not read, echo, or write them to any file.
- Before the first publication, confirm that the IP address of the machine running the tool has been added to the WeChat Official Account allowlist. For environments with frequently changing IP addresses or team collaboration, use server mode. See wenyan-setup.md.
Input Contract
The article must have frontmatter at the top:
is required;
may be a local or network path, and if omitted, the first image in the article body is used automatically;
and
are optional. In-article images may use local absolute paths, relative paths, or network URLs, and are automatically uploaded to the WeChat material library during publishing. See the
WeChat article template.
For a WeChat image-only post (Little Green Book), set
in the frontmatter to extract all images from the article body automatically, or manually specify
. A maximum of 20 images is supported, with the first image serving as the cover.
Theme Selection
- First, read the default formatting theme from the account’s style profile.
- If there is no default theme or the user requests a different style, render the current article with the candidate themes to generate local previews (
wenyan render -f article.md -t theme
), and let the user compare and select one.
- After the user makes a selection, save it to the account’s style profile and reuse it subsequently without asking again.
- For branded formatting, load a custom CSS theme with .
Publishing Workflow
Both layers of authorization are required: approval of the final draft and authorization to write to the Drafts folder.
- Verify that the frontmatter is complete, the cover is available, and all in-article image paths are valid.
- Render the article locally with and confirm that there is no garbled text and that code blocks and tables are readable.
- Run
wenyan publish -f article.md -t theme -h highlight-theme
to write the article to the Drafts folder.
- Remind the user to open the draft in the WeChat Official Account backend and verify the title, cover, first two paragraphs, number of images, and external links.
- Write the draft creation time, selected theme, and verification results back to the task card.
If publishing fails, troubleshoot it according to wenyan-setup.md. Do not blindly retry the same error more than once. Hand credential-related issues over to the user.
Multiple Accounts
When publishing to multiple WeChat Official Accounts, use wenyan’s credential configuration to manage multiple accounts and specify the target account with
during publishing. Each account requires its own configured IP allowlist.
Security Boundaries
- Only write to the Drafts folder; do not call the mass-send endpoint.
- Credentials must be supplied only through environment variables or wenyan’s credential configuration. Never write them to task cards, articles, logs, or repositories.
- If command output contains token or key fragments, do not record or repeat them.
- Stop immediately and hand the issue over to the user when the publishing API reports an error, the allowlist blocks a request, or credentials expire.
Output
Return the draft title, selected theme, cover source, number of images, draft creation time, and a checklist of items requiring manual verification.