🤖
Bot SDK
Event-driven bot with long-polling, message send/receive, typing indicators
Cross-platform, type-safe, zero-dependency WeChat Bot SDK for TypeScript
pnpm add @weixin-ts/botimport { MessageItemType, WeixinBot } from '@weixin-ts/bot'
const bot = new WeixinBot({ session: '.weixin-bot.session.json' })
// QR scan login (or load saved session)
const result = await bot.login({
onQrCode: url => console.log('Scan:', url),
onScanned: () => console.log('Confirm in WeChat...'),
})
if (!result.success)
throw new Error(result.message)
// Echo bot
bot.on('message', async (msg) => {
const text = msg.item_list?.find(i => i.type === MessageItemType.TEXT)?.text_item?.text
if (text)
await bot.sendText({ to: msg.from_user_id!, text: `Echo: ${text}` })
})
await bot.start()| Package | Description |
|---|---|
@weixin-ts/bot | Core bot SDK — polling, messaging, events, login |
@weixin-ts/cdn | CDN upload/download with AES-ECB encryption |