weixin-agent-sdk
Bridge any AI agent backend to WeChat using the weixin-agent-sdk framework with simple Agent interface, login, and message loop.
By reason-machines · 1,097 installs
npx skills add reason-machines/trending-skills --skill weixin-agent-sdk
Source repository · Upstream listing
weixin agent sdk
Skill by [ara.so](https://ara.so) — Daily 2026 Skills collection.
weixin agent sdk is a TypeScript framework that bridges any AI backend to WeChat (微信) via the Clawbot channel. It uses long polling to receive messages — no public server required — and exposes a minimal Agent interface so you can plug in OpenAI, Claude, or any custom logic in minutes.
Installation
Node.js = 22 required.
Quick Start
1. Login (scan QR code once)
2. Implement the Agent interface
Core API
Agent Interface
login()
Triggers QR code scan and persists session to ~/.openclaw/ . Only needs to run once.
start(agent)
Starts the message loop. Blocks until process exits. Automatically reconnects on session expiry.
Common Patterns
Multi turn Conversation with History
OpenAI Agent (Full Example)
Send Image Response
Send File Response
ACP (Agent Client Protocol) Integration
If you have an ACP compatible agent (Claude Code, Codex, kimi cli, etc.), use the weixin acp package — no code needed.
weixin acp launches your agent as a subprocess and communicates via JSON RPC over stdio.
Environment Variables (OpenAI Example)
Variable Required Description
OPENAI API KEY Yes OpenAI API key
OPENAI BASE URL No Custom API base URL (OpenAI compatible services)
OPENAI MODEL No Model name, default gpt 5.4
SYSTEM PROMPT No System prompt for the assistant
Built in Slash Commands
Send these in WeChat chat to control the bot:
Command Description
/echo <message Echoes back directly (bypasses Agent), shows channel latency
/toggle debug Toggles debug mode — appends full latency stats to each reply
Supported Message Types
Incoming (WeChat → Agent)
Type media.type Notes
Text — Plain text in request.text
Image image Downloaded & decrypted, filePath = local file
Voice audio SILK auto converted to WAV (requires silk wasm )
Video video Downloaded & decrypted
File file Downloaded & decrypted, original filename preserved
Quoted message — Quoted text appended to request.text , quoted media as media
Voice to text — WeChat transcription delivered as request.text
Outgoing (Agent → WeChat)
Type Usage
Text Return { text: "..." }
Image Return { media: { type: "image", url: "..." } }
Video Return { media: { type: "video", url: "..." } }
File Return { media: { type: "file", url: "...", fileName: "..." } }
Text + Media Return both text and media together
Remote image Set url to an HTTPS link — SDK auto downloads and uploads to WeChat CDN
Monorepo / pnpm Setup
Troubleshooting
Session expired ( errcode 14 )
The SDK automatically enters a 1 hour cooldown and then reconnects. No manual intervention needed.
Audio not converting from SILK to WAV
Install the optional dependency: npm install silk wasm
Bot not receiving messages after restart
State is persisted in ~/.openclaw/get updates buf . The bot resumes from the last position automatically.
Remote image URL not sending
Ensure the URL is HTTPS and publicly accessible. The SDK downloads it before uploading to WeChat CDN.
login() QR code not appearing
Ensure your terminal supports rendering QR codes, or check ~/.openclaw/ for the raw QR data.