WeChat Notification Integration
Source: Child Growth Diary Construction Kit
AI要怎么做.md §3.3 WeChat/WeCom Notification, extracted from the project name and turned into a general integration specification.
What This Is
Notifications are a standard feature of most mini-programs. This skill provides integration specifications and generation scripts for the two most common approaches: WeCom Bot (simplest, 5 minutes) and Official Account template messages (requires user follow). It also enforces key storage rules.
The script includes --self-test: it mocks httpx to verify the payload structure of three send types (text / markdown card / template message) is correct, proving the generated module is usable—no real webhook needed, no internet required.
When to Use
- The user says: "Integrate WeChat notifications" / "WeCom Bot" / "Official Account template message" / "WeChat message push"
- Any scenario where system messages need to be pushed to WeChat (groups / users): task reminders, status notifications, alerts
Option 1: WeCom Bot Webhook (Recommended, 5-minute integration)
POST {webhook_url}sends JSON:{"msgtype":"text","text":{"content":"Message content"}}- Supports markdown format, can include links and images
- No application required; a group admin can create it (Group → Add Bot → Copy Webhook URL)
Option 2: Official Account Template Message
- First obtain
access_token(valid for 7200 seconds, must be cached in Redis/memory, never fetch on every call) POST https://api.weixin.qq.com/cgi-bin/message/template/send- Requires the user to follow the Official Account, and the template must be approved in the Official Account backend
Security Requirements (P0)
- The WeCom Bot Webhook URL is treated as a secret, only stored in
.env, never appearing in code - Official Account AppSecret is stored only server-side, not passed to the frontend
- Credentials are never committed to Git; use in conjunction with the
wechat-miniprogram-devrulessecurity boundary
Script Usage (Generate Notification Module)
# 0) First verify the generated send structure is correct (recommended before first use)
python gen_notify.py --self-test
# 1) Generate module
python gen_notify.py --out ./notify_module
Generates:
notify_module/wecom_bot.py— WeCom Bot send (text / markdown, with rate limiting and retry, additionally providesmarkdown_card()to compose broadcast cards)notify_module/mp_template.py— Official Account template message (access_token cache + send, with rate limiting and retry)notify_module/.env.example— Required key fields to fill in
Notes
- WeCom Bot is suitable for "system → group" alerts/broadcasts; Official Account template messages are suitable for "system → specific user" reach (e.g., task reminders, points received)
- The
access_tokencache key includes an expiration time and refreshes early to avoid duplicate fetches triggering rate limits under concurrency - Template message content is constrained by the Official Account's category and template fields; confirm field name matching before sending
- Use in conjunction with
ai-work-acceptancefor verification: focus on ensuring Webhook URL / AppSecret are not hardcoded or stored in the database