wechatbot
ไธญๆ–‡

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
  1. You run /wechat in pi
  2. Extension creates a WeChatBot instance โ†’ calls bot.login()
  3. SDK calls iLink API โ†’ gets a QR code URL โ†’ displayed in pi terminal
  4. You scan the QR with WeChat on your phone
  5. WeChat messages โ†’ pi.sendUserMessage() โ†’ become pi prompts
  6. pi.on('agent_end') โ†’ bot.reply() โ†’ sent back to WeChat
  7. 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)
TypeHow it's handled
TextSent directly as pi prompt
ImageDownloaded โ†’ base64 โ†’ sent as ImageContent for vision models
VoiceUses WeChat transcription if available; otherwise downloads SILK audio
FileText files (.txt, .md, .py, etc): content included in prompt. Others: described with metadata
VideoDownloaded โ†’ saved to temp file โ†’ pi told the file path for processing
Outbound (Pi โ†’ WeChat)
TypeHow it's handled
TextMarkdown stripped โ†’ sent as plain text
Generated filesDetected 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 APIPurposeWhen
pi.registerCommand()/wechat, /wechat-send, /wechat-disconnectExtension load
pi.sendUserMessage()WeChat msg โ†’ pi prompt (text or image+text)On each message
pi.on(agent_end)Capture response โ†’ stripMarkdown โ†’ send to WeChatAfter agent finishes
pi.on(message_update)Track streaming textDuring streaming
ctx.ui.setStatus()Connection status in footerThroughout
pi.on(session_shutdown)Cleanup on exitOn shutdown

Features

  • Zero config โ€” just /wechat and scan
  • Full media support โ€” images (vision), voice, files, video
  • Markdown stripping โ€” AI output โ†’ clean plain text for WeChat
  • Auto media routing โ€” generated .png sent as image, .mp4 as 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
Pi Agent โ€” Chat with Pi from WeChat