Skip to content

Wechaty Puppet Setup

There are two ways to connect Wechaty bots to agent-wechat:

  1. Puppet mode — import @agent-wechat/wechaty-puppet directly and connect to the agent-wechat REST API
  2. Gateway mode — connect via gRPC through a gateway container, using the standard wechaty-puppet-service (no agent-wechat dependency needed)

Both require a running agent-wechat server. You can self-host with Docker or use Managed Hosting.

Option 1: Puppet mode (direct)

Install

Terminal window
npm install @agent-wechat/wechaty-puppet wechaty wechaty-puppet

Prerequisites

  • Docker — on macOS, install Colima (brew install colima && colima start) or Docker Desktop
  • An agent-wechat server — self-hosted or via Managed Hosting:
    Terminal window
    npx @agent-wechat/cli up
  • Node.js >= 22

Usage

import { WechatyBuilder } from 'wechaty'
import PuppetAgentWeChat from '@agent-wechat/wechaty-puppet'
const bot = WechatyBuilder.build({
puppet: new PuppetAgentWeChat({
serverUrl: 'http://localhost:6174', // optional, this is the default
token: 'your-token', // optional, reads from ~/.config/agent-wechat/token
})
})
bot.on('scan', (qrcode, status) => {
console.log(`Scan QR Code: ${status}`)
console.log(`https://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`)
})
bot.on('login', user => console.log(`Logged in: ${user}`))
bot.on('message', async msg => {
if (msg.text() === 'ding') {
await msg.say('dong')
}
})
await bot.start()

Configuration

OptionTypeDefaultDescription
serverUrlstringhttp://localhost:6174agent-wechat server URL
tokenstringautoAuth token. Falls back to AGENT_WECHAT_TOKEN env var, then ~/.config/agent-wechat/token
pollIntervalMsnumber2000Message polling interval (ms)

Option 2: Gateway mode (gRPC)

Gateway mode wraps the puppet in gRPC, so existing Wechaty bots can connect using the standard wechaty-puppet-service — no @agent-wechat/wechaty-puppet dependency needed. This is the recommended approach for Managed Hosting instances, where the gateway is already running.

Install

Terminal window
npm install wechaty wechaty-puppet-service

Usage

import { WechatyBuilder } from 'wechaty'
import { PuppetService } from 'wechaty-puppet-service'
const bot = WechatyBuilder.build({
puppet: new PuppetService({
endpoint: 'your-instance.agent-wx.app:8443', // provided by managed hosting
token: 'your-token',
tls: {
caCert: fs.readFileSync('/etc/ssl/cert.pem'), // system CA certs
},
})
})
bot.on('login', user => console.log(`Logged in: ${user}`))
bot.on('message', async msg => {
if (msg.text() === 'ding') {
await msg.say('dong')
}
})
await bot.start()

How it works

The connection flow is:

Your Wechaty bot → gRPC → Gateway container → REST API → Agent container

On managed hosting instances, the gateway endpoint and token are provided to you. The token may include an SNI prefix for TLS routing.

Supported features

FeatureStatusNotes
QR LoginYesVia WebSocket
LogoutYes
Receive TextYesPolling-based
Receive ImageYesVia media endpoint
Receive VoiceYesVia media endpoint
Receive VideoYesVia media endpoint
Receive EmoticonYes
Send TextYes
Send ImageYes
Send FileYes
Contact ListYesFull address book
Contact AliasReadFrom remark field
Room ListPartialRecent group chats only
Room TopicReadFrom group name
Message RecallNo
Room CreateNo
FriendshipsNo