A pi extension that bridges WeChat to your Pi coding agent. Scan a QR code in WeChat โ chat with Pi from your phone. Supports text, images, files, voice, and video. Uses the @wechatbot/wechatbot SDK for all iLink protocol operations.
How it works
graph LR A["๐ฑ WeChat User<br/>(phone)"] <--> B["โ๏ธ iLink API<br/>(Tencent)"] B <--> C["๐ค Pi Agent<br/>(laptop)"] B --- D["@wechatbot/wechatbot SDK"] style D fill:none,stroke:none,color:#666
- You run
/wechatin pi - Extension creates a
WeChatBotinstance โ callsbot.login() - SDK calls iLink API โ gets a QR code URL โ displayed in pi terminal
- You scan the QR with WeChat on your phone
- WeChat messages โ
pi.sendUserMessage()โ become pi prompts pi.on('agent_end')โbot.reply()โ sent back to WeChat- Typing indicator shown while Pi thinks
Install
From npm (recommended):
pi install npm:@wechatbot/pi-agent
Or load directly (no install):
pi -e npm:@wechatbot/pi-agent
Or copy to extensions directory (auto-loads):
cp -r pi-agent/ ~/.pi/agent/extensions/wechat-bridge/
Usage
> /wechat ๐ฑ Scan this QR code in WeChat: โโโโโโโ โโโ โโโโโโโ โ โโโ โ โโโ โ โโโ โ ... [wechat] QR scanned โ confirm in WeChat [wechat] Login confirmed โ WeChat connected! Account: e06c1ceea05e@im.bot
Now send a message from WeChat โ Pi receives it as a prompt, processes it, and sends the reply back.
Message flow
WeChat user sends "ๅธฎๆ้ๆ auth ๆจกๅ" โ โผ iLink API (long-poll getupdates) โ โผ Extension receives IncomingMessage โ โโโ bot.sendTyping(userId) โ "ๅฏนๆนๆญฃๅจ่พๅ ฅไธญ..." โ โโโ pi.sendUserMessage(content) โ becomes pi prompt โ โผ Pi agent processes (tools, thinking...) โ โผ pi.on('agent_end') fires โ โโโ Extract assistant text โโโ stripMarkdown() โ clean for WeChat โโโ Detect generated file paths โ send as media โโโ bot.stopTyping(userId) โโโ bot.reply(msg, content) โ sent back to WeChat
Media support
The extension handles all WeChat message types โ not just text.
Inbound (WeChat โ Pi)
| Type | How it's handled | |
|---|---|---|
| Text | Sent directly as pi prompt | |
| Image | Downloaded โ base64 โ sent as ImageContent for vision models | |
| Voice | Uses WeChat transcription if available; otherwise downloads SILK audio | |
| File | Text files (.txt, .md, .py, etc): content included in prompt. Others: described with metadata | |
| Video | Downloaded โ saved to temp file โ pi told the file path for processing |
Outbound (Pi โ WeChat)
| Type | How it's handled | |
|---|---|---|
| Text | Markdown stripped โ sent as plain text | |
| Generated files | Detected in response โ auto-sent via bot.reply({ file }) | |
| Auto-routing | .png โ image message, .mp4 โ video message, .pdf โ file attachment |
Commands
/wechat Start login (show QR code)
/wechat --force Force re-login (new QR code)
/wechat-disconnect Disconnect WeChat
/wechat-send <text> Manually send text to WeChat user
When already connected, /wechat shows a menu: Disconnect, Show status, or Cancel.
Pi APIs used
Extension API usage
| Pi API | Purpose | When |
|---|---|---|
| pi.registerCommand() | /wechat, /wechat-send, /wechat-disconnect | Extension load |
| pi.sendUserMessage() | WeChat msg โ pi prompt (text or image+text) | On each message |
| pi.on(agent_end) | Capture response โ stripMarkdown โ send to WeChat | After agent finishes |
| pi.on(message_update) | Track streaming text | During streaming |
| ctx.ui.setStatus() | Connection status in footer | Throughout |
| pi.on(session_shutdown) | Cleanup on exit | On shutdown |
Features
- Zero config โ just
/wechatand scan - Full media support โ images (vision), voice, files, video
- Markdown stripping โ AI output โ clean plain text for WeChat
- Auto media routing โ generated
.pngsent as image,.mp4as video, etc. - Credential persistence โ
~/.wechatbot/, skips QR on restart - Session recovery โ auto re-login on
-14 - Typing indicator โ "ๅฏนๆนๆญฃๅจ่พๅ ฅไธญ" while Pi thinks
- Text chunking โ long replies split at 2000 chars
- Graceful shutdown โ stops on
session_shutdown