Skip to content

Getting started

Install

Terminal window
npm i wechaty wechaty-puppet-bridge

You also need a running agent-wechat daemon (wx serve) with an account already logged in. See How to get these values for AGENT_WECHAT_URL / TOKEN / ACCOUNT.

Minimal Wechaty bot

import { WechatyBuilder } from 'wechaty'
import { PuppetAgentWechat } from 'wechaty-puppet-bridge'
const puppet = new PuppetAgentWechat({
baseUrl: process.env.AGENT_WECHAT_URL || 'http://127.0.0.1:6174',
token: process.env.AGENT_WECHAT_TOKEN!,
account: process.env.AGENT_WECHAT_ACCOUNT!,
})
const bot = WechatyBuilder.build({ puppet })
bot.on('message', msg => {
if (msg.text() === 'ding') void msg.say('dong')
})
await bot.start()

Prerequisites

What Details
Daemon wx serve listening (default http://127.0.0.1:6174)
Account Already connected / logged in on the daemon
Token Bearer token with read + send (add media / admin as needed)
Variable Required Default
AGENT_WECHAT_URL no http://127.0.0.1:6174
AGENT_WECHAT_TOKEN yes —
AGENT_WECHAT_ACCOUNT yes daemon account id

Examples in this repo

From a clone of puppet-bridge:

Terminal window
npm install
export AGENT_WECHAT_URL=http://127.0.0.1:6174
export AGENT_WECHAT_TOKEN=<token>
export AGENT_WECHAT_ACCOUNT=<account-id>
npm run start:ripe:agent-wechat:info

Good to know

The example scripts load dotenv, so you can put the same variables in a local .env file instead of exporting them in the shell.