Skip to content

weixin-tsWeChat Bot SDK

Cross-platform, type-safe, zero-dependency WeChat Bot SDK for TypeScript

weixin-ts

Quick Start

npm versionLicense

bash
pnpm add @weixin-ts/bot
typescript
import { 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()

Packages

PackageDescription
@weixin-ts/botCore bot SDK — polling, messaging, events, login
@weixin-ts/cdnCDN upload/download with AES-ECB encryption

Released under the MIT License.