A Python WeChat bridge wakes Grok Bot by webhook; simple replies take 10–15 seconds
Overview
The author runs a local Python WeChat bridge on a Grok Bot computer so a private message can wake real work, with a webhook plus a 10-minute fallback.
Workflow
Trigger: Wake a Grok Bot from WeChat so a message can start real work, not a fixed reply. The author, Jason (@EvanWritesX), built a Python bridge on the Bot's built-in Linux computer. After setup, sending “汇总今天的邮件” in WeChat made the Bot check 4 mailboxes and return one summary. The author says the full setup took about 20 minutes.
The hard part, the author says, is waking a tool-using AI at the moment a message arrives. Preparation: a Grok Bot assistant (it can write files, run Python, and keep a background process), a WeChat account for the QR bind, and Tencent's open-source openclaw-weixin protocol doc at https://github.com/Tencent/openclaw-weixin/blob/main/docs/protocol_zh_CN.md, with details not in the doc taken from the source.
The bridge lives in ~/workspace/wechat-bridge/, uses mostly the standard library, and exposes 5 commands: login (call get_bot_qrcode and make a PNG); wait-login (poll get_qrcode_status, including states beyond wait, scaned, confirmed and expired, such as a captcha or a redirect, then atomically write credentials to state/session.json with mode 600); serve (long-poll with getupdates, persist the cursor get_updates_buf, handle only private chat from the bound account, ignore group and other senders, dedupe by message_id, and write into inbox/); send (reply with sendmessage, must include the context_token from the inbound message, split over 4000 characters, and use client_id plus a send log to avoid duplicates); status / health (login state, process, last poll time, backlog; credentials shown only as the first and last 4 characters).
Pits the author hit: request headers must include iLink-App-Id and iLink-App-ClientVersion, with the version computed from the current source, not copied from an old tutorial; return code -14 means the token expired, and the official client pauses for 1 hour, so do not assume a new QR scan is needed; retry network errors a limited number of times, and do not retry business errors (log the code); for images, voice and files, reply first that they are not supported and ask for a text description, so the AI does not pretend it saw them.
- By hand: Create a routine with a webhook trigger, plus a 10-minute scheduled fallback. In Grok Bot, make a scheduled task whose trigger is webhook. Add a every-10-minute scheduled trigger for fallback and a health check. If the webhook does not arrive, a message is at most 10 minutes late and is not dropped.
- By hand: Store the webhook URL and secret as environment variables. Fill them in Grok Bot's encrypted input box so the secret does not go through chat.
- Bot: POST only a message ID when a new WeChat message arrives. The bridge does not send credentials or the message body. After the AI is woken, it reads the message from the local
inbox/. If the webhook URL leaks, the author says an outsider still gets nothing. - By hand: Write the routine instructions and five task states. The flow is: check health → take a pending task → mark it in progress → actually do the work with tools → send the reply with
send→ mark it sent. The five states are received, in progress, pending send, sent, and failed. If the work finished but the send failed, the task stays at pending send; the next wake only resends and does not redo the work.
To go live, generate the QR only after the phone is in hand; it expires in about 5 minutes. After a confirmed scan, start the background service with setsid and nohup so a crash restarts it. Then open the bot chat in WeChat and send a message; saying it is ready somewhere else is not enough, because that first message is how the first context_token is obtained.
The author reports: send and receive in under 1 second; a simple question takes about 10 to 15 seconds, mostly spent waking the AI; WeChat shows a typing indicator immediately. In use: a daily summary of 4 mailboxes, and a shop revenue daily report pushed at 9:30.
Limits the author lists: each WeChat task is an independent wake, so the AI can use long-term memory but cannot see the full main-chat history; proactive pushes depend on the latest context_token, and if it has been too long, sending any message restores it; after a server restart, the 10-minute health check brings the service back; if credentials fully fail, WeChat can no longer deliver a reminder, so the author uses an in-app notification to rescan; email, payment and delete still need an explicit yes from the person, and the AI does not do those on its own.
The page also names the original post: https://x.com/EvanWritesX/status/2111661828749373784
Check: The latency figures and the two in-use scenes are the author's own account of a running setup, not independently reproduced here.
Key points and results
- The author frames the hard problem as waking a tool-using Bot, not sending a fixed reply. The bridge writes inbound mail to a local
inbox/and the webhook carries only a message ID, so a leaked webhook URL does not expose credentials or message text. - A 10-minute scheduled trigger is the fallback if the webhook is missed. The author says a message is then at most 10 minutes late and is not dropped.
- Five task states keep send failures from redoing finished work. If send fails after the work is done, the task stays at pending send and the next wake only resends.
- Return code -14 means an expired token, not an immediate need to scan again. The author says the official client pauses for 1 hour in that case. Header versions must follow the current source, not an old tutorial.
- Measured times are the author's account, not reproduced here. Send and receive under 1 second; a simple question about 10 to 15 seconds, mostly waking the AI. Limits include no full main-chat history on each wake, and
context_tokenexpiry for proactive pushes.
Source
- Platform
- Blog
- Author
- Jason(@EvanWritesX)
- Published
- Categories
- Mail and calendar, Code and repos
What this evidence label means
Source read in full
We read the source (post, article or transcript). That only means the original was read. It does not mean this site reproduced the author's results.