How to Build an AI‑Powered WeChat Article Automation Workflow with Prompt Engineering
This guide walks through creating a fully automated WeChat public‑account article publishing pipeline using large‑model prompt engineering, covering token retrieval, title generation, subtitle creation, hand‑drawn comic generation, content formatting, image handling, and final draft publishing with detailed code snippets.
Overview of the WeChat Automation Workflow
The workflow automates the full lifecycle of a WeChat public‑account article. It first obtains a WeChat access token, then uses a large language model (LLM) to generate a main title and three subtitle sections. Each subtitle is passed to a sub‑workflow that creates a hand‑drawn comic image from an image‑prompt. The LLM‑generated text and comic images are formatted, assembled into a complete HTML article, and finally published as a draft.
A secondary sub‑workflow converts each subtitle into an image‑generation prompt, invokes an image model, and composites the resulting hand‑drawn comic.
Prompt Engineering for Large Models
The prompt template follows six essential elements: role definition, requirement specification, core task description, reference examples, constraint conditions, and execution flow.
# Role: Hand‑drawn illustrator
## Task: Generate an image prompt based on user text {{title}}. Requirements:
1. Elements: match the text, keep concise.
2. Style: hand‑drawn, soft lines, warm colors, illustration‑like texture.
3. Output: a single prompt line only.Role positioning : assign a specific persona to steer tone.
Requirement specification : define output format, length, and style explicitly.
Core task : state the exact action the model must perform.
Reference examples : provide 1‑2 examples to illustrate expectations.
Constraint conditions : list prohibited outputs (e.g., no uncertain answers).
Execution flow : break the task into ordered steps to avoid confusion.
Key Nodes and Plugins
WeChat Public Account Assistant : retrieves the access token and uploads generated images to the WeChat material library.
Database Query Node : stores and fetches previously generated titles to avoid duplication.
Code Implementations
Extract subtitle‑content pairs
async function main({ params }: Args): Promise<Output> {
const defaultRet = {title1:'',title2:'',title3:'',content1:'',content2:'',content3:''};
try {
if (!params.input) return defaultRet;
const contentList = params.input || [];
const getItem = (index, key) => (contentList[index] || {})[key] || '';
return {
title1: getItem(0,'subTitle'),
title2: getItem(1,'subTitle'),
title3: getItem(2,'subTitle'),
content1: getItem(0,'subContent'),
content2: getItem(1,'subContent'),
content3: getItem(2,'subContent')
};
} catch (e) {
console.error('Failed to extract contentList:', e);
return defaultRet;
}
}Assemble final HTML article
async function main({ params }: Args): Promise<Output> {
const s1 = `<div style="margin-top:18px;display:flex;justify-content:center;align-items:center;">` +
`<div style="padding:6px 10px;background:#ff0000;color:#fff;font-weight:bold;font-size:16px;border-radius:5px;">${params.title1}</div>` +
`</div>` +
`<p style="font-size:17px;line-height:1.9;color:#333;margin-bottom:20px;">${params.content1}</p>` +
`<div style="position:relative;width:100%;">` +
`<img style="width:100%;" src="${params.pic1}">` +
`</div>`;
// s2 and s3 are built similarly for title2/content2/pic2 and title3/content3/pic3
const finalContent = `<div style="width:100%;max-width:800px;margin:0 auto;">${s1}${s2}${s3}</div>`;
return { finalContent };
}Publishing and Post‑Processing
After assembling the article, the WeChat Public Account Assistant plugin uploads the generated images to the material library and publishes the article as a draft. The title flag in the database is then updated to prevent duplicate generation in subsequent runs.
Result Showcase
Screenshot of the automatically generated WeChat post, displaying the title, three subtitle sections, accompanying hand‑drawn comics, and the final layout as it appears in the draft.
AI Architect Hub
Discuss AI and architecture; a ten-year veteran of major tech companies now transitioning to AI and continuing the journey.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
