How to Connect WeChat to AI Agent in 4 Simple Steps with MMClaw
Problem
I wanted to connect my AI agent to WeChat. After hours of frustration, I kept hitting the same walls:
Error: webhook url requiredError: public IP address not detectedError: Node.js runtime required for WeChat SDKError: registration failed - enterprise verification neededThe official WeChat SDK only supports Node.js. I’m a Python developer. I don’t want to maintain two codebases.
I tried the bridge approach with wechaty:
npm install wechaty wechaty-puppet-wechatpip install wechatyBut then I got this:
(node:12345) Warning: Accessing non-existent property 'puppet' of module 'wechaty'Error: PUPPET_NOT_FOUNDI spent an entire afternoon debugging Node.js dependency issues. This is ridiculous. I just want my AI agent to respond on WeChat.
Environment
Let me show you my setup:
$ python --versionPython 3.11.4
$ node --versionv18.17.0 # I have Node.js but I don't want to use it
$ sw_versProductName: macOSProductVersion: 14.3BuildVersion: 23D56The Traditional Way (Painful)
Here’s what I tried first. The official documentation says to use the WeChat Node.js SDK:
const { WechatyBuilder } = require('wechaty')
const bot = WechatyBuilder.build({ name: 'my-bot', puppet: 'wechaty-puppet-wechat',})
bot.on('message', async (msg) => { const contact = msg.talker() const text = msg.text()
if (msg.self()) return
// Call Python AI agent via HTTP const response = await fetch('http://localhost:8000/chat', { method: 'POST', body: JSON.stringify({ message: text }) })
const data = await response.json() await msg.say(data.reply)})
bot.start()Then I need to run a Python server for my AI agent:
from fastapi import FastAPIfrom pydantic import BaseModel
app = FastAPI()
class Message(BaseModel): message: str
@app.post("/chat")async def chat(msg: Message): # Your AI agent logic here reply = f"You said: {msg.message}" return {"reply": reply}This architecture looks like this:
┌─────────────┐ HTTP ┌─────────────┐│ WeChat │──────────────▶│ Node.js ││ Server │ │ Bot │└─────────────┘ └──────┬──────┘ │ HTTP ▼ ┌─────────────┐ │ Python │ │ AI Agent │ └─────────────┘Problems with this approach:
- Two runtimes to manage (Node.js + Python)
- Two processes to debug
- Complex error handling across languages
- Extra latency from HTTP calls
- Harder to deploy
The Solution: MMClaw
Then I discovered MMClaw. It’s a lightweight (1700 lines) pure Python AI Agent kernel that supports WeChat natively.
The key difference: MMClaw reimplemented the WeChat protocol in pure Python. No Node.js required.
┌─────────────┐ ┌─────────────┐│ WeChat │──────────────│ Python ││ Server │ │ MMClaw │└─────────────┘ │ + Agent │ └─────────────┘One runtime. One process. Much simpler.
Step 1: Install Python
I recommend using Miniconda for isolation:
# Download and install Minicondawget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.shbash Miniconda3-latest-MacOSX-arm64.sh
# Create a new environmentconda create -n mmclaw python=3.11conda activate mmclawOn Linux:
# Ubuntu/Debianwget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.shbash Miniconda3-latest-Linux-x86_64.sh
conda create -n mmclaw python=3.11conda activate mmclawStep 2: Install MMClaw
pip install mmclawThat’s it. No npm install. No dependency hell.
Let me verify the installation:
$ pip show mmclawName: mmclawVersion: 0.3.2Summary: Lightweight Pure Python AI Agent KernelAuthor: MMClaw TeamLocation: /opt/miniconda3/envs/mmclaw/lib/python3.11/site-packagesRequires: httpx, pydantic, websocketsNotice the dependencies: only httpx, pydantic, and websockets. No Node.js bindings.
Step 3: Configure WeChat
Run the configuration wizard:
$ mmclaw config
? Select messaging platform: (Use arrow keys) ❯ WeChat Telegram WhatsApp Feishu QQ Bot
? Select WeChat mode: ❯ Personal (scan QR code) Enterprise (corporate account)
? Enable message logging? (y/N) y
? Set log level: (Use arrow keys) DEBUG ❯ INFO WARNING ERROR
Configuration saved to ~/.mmclaw/config.yaml
Now scan the QR code with WeChat:A QR code will appear in your terminal:
██████████████████████████████████████████████████████████████████████████████████████ ▄▄▄▄▄ ██▄ ▄█▀▄▄ ▄▄▄▄▄ ████████ █ █ █▀▀▀█ ▄█ █ █ ████████ █▄▄▄█ ▀▀▀█ ▄ █ █▄▄▄█ ████████ ▄▄▄▄▄ █ █▄▀▄▀▀█ ▄▄▄▄▄ ████████ █ █ █▄▀▀█ ▄██ █ █ ████████ █▄▄▄█ ██ █▀█ ▀▀█ █▄▄▄█ ████████ ▄▄▄▄▄ █ █▀▀▀ █▀▀█ ▄▄▄▄▄ ████████ █ █ █▀█ █▀▀▀▀██ █ █ ████████ █▄▄▄█ █▄█ ▄▀▀▀▀▀█ █▄▄▄█ ██████████████████████████████████████████████████████████████████████████████████████Open WeChat on your phone, scan the QR code, and confirm the login.
Scan successful!Logged in as: Your NameWeChat ID: your_wechat_idStep 4: Run Your Agent
Create a simple AI agent:
from mmclaw import Agent, Tool
@Tooldef get_weather(city: str) -> str: """Get current weather for a city""" # Your weather API logic here return f"Weather in {city}: Sunny, 22C"
# Create agent with your LLMagent = Agent( name="wechat-assistant", model="gpt-4", tools=[get_weather], system_prompt="""You are a helpful assistant on WeChat. Respond concisely since WeChat messages should be brief.""")
# Run with WeChatagent.run(platform="wechat")Now run it:
$ mmclaw run my_agent.py
[2026-03-24 15:10:01] INFO Starting MMClaw agent...[2026-03-24 15:10:01] INFO Connected to WeChat as: Your Name[2026-03-24 15:10:01] INFO Agent ready. Listening for messages...
[2026-03-24 15:10:15] MESSAGE from John: Hello![2026-03-24 15:10:15] REPLY: Hi! How can I help you today?
[2026-03-24 15:10:23] MESSAGE from John: What's the weather in Beijing?[2026-03-24 15:10:23] TOOL CALL: get_weather(city="Beijing")[2026-03-24 15:10:23] REPLY: The weather in Beijing is sunny with 22C. Great day for a walk!Your AI agent is now live on WeChat.
How It Works
Let me explain what MMClaw does under the hood.
1. WebSocket Connection
MMClaw establishes a WebSocket connection to WeChat servers:
import websockets
class WeChatConnection: async def connect(self, qr_callback): """Connect to WeChat via QR code login""" ws_url = self._get_websocket_url()
async with websockets.connect(ws_url) as ws: # Send login request await ws.send(json.dumps({ "type": "login_request", "device_id": self.device_id }))
# Receive QR code response = await ws.recv() data = json.loads(response)
if data["type"] == "qr_code": qr_callback(data["qr_url"]) # Display QR code
# Wait for scan confirmation while True: response = await ws.recv() data = json.loads(response)
if data["type"] == "login_success": self.session_key = data["session_key"] return True2. Message Handling
Messages are handled through a simple event loop:
class MessageHandler: async def listen(self, on_message): """Listen for incoming messages""" async for message in self.connection.stream(): if message["type"] == "message": await on_message( sender=message["sender"], content=message["content"], room=message.get("room") )3. Pure Python Implementation
The key innovation is that MMClaw reimplemented the WeChat protocol without Node.js:
Official WeChat SDK: WeChat Server <--WebSocket--> Node.js SDK <--HTTP--> Your Python Code
MMClaw: WeChat Server <--WebSocket--> Pure Python SDK + Your CodeThis is possible because:
- WeChat’s protocol is based on standard WebSocket
- The authentication flow uses standard QR code login
- MMClaw reverse-engineered the message format
Common Issues and Solutions
Issue 1: QR Code Timeout
If the QR code expires before you scan:
[2026-03-24 15:05:01] ERROR QR code expired, please re-run mmclaw configSolution: The QR code expires in 5 minutes. Run mmclaw config again for a new QR code.
Issue 2: Login Frequency Limit
WeChat limits how often you can log in:
[2026-03-24 15:15:01] ERROR Login frequency exceeded. Try again in 24 hours.Solution: MMClaw caches your session. Don’t restart the agent frequently. Use mmclaw run --daemon for long-running processes.
Issue 3: Message Rate Limiting
If you send too many messages:
[2026-03-24 15:20:01] WARN Rate limited: waiting 60 secondsSolution: Add delays between messages:
from mmclaw import Agent
agent = Agent( name="wechat-assistant", model="gpt-4", message_delay=2.0 # Wait 2 seconds between replies)Why MMClaw Exists
I asked the MMClaw maintainers why they built this. Here’s what they said:
“We built AI agents in Python. We wanted to deploy them to WeChat. The official SDK required Node.js. We didn’t want to maintain two codebases. So we reimplemented the WeChat protocol in pure Python. MMClaw was born.”
The entire kernel is only 1700 lines of Python. It supports:
- WeChat (personal and enterprise)
- Telegram
- Feishu
- QQ Bot
Summary
In this post, I showed you how to connect an AI agent to WeChat in 4 steps:
- Install Python with Miniconda
pip install mmclawmmclaw configand scan the QR codemmclaw run your_agent.py
The key advantage of MMClaw is that it’s pure Python. No Node.js, no webhook configuration, no public IP address required. Just write your agent in Python and run it.
If you’re building AI agents and need WeChat integration, give MMClaw a try. It saved me hours of frustration.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments