Skip to content

weixin-tsWeChat Bot SDK

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

weixin-ts

Quick Start

Disclaimer: This project is an unofficial SDK for the WeChat iLink Bot API. It is not affiliated with, endorsed by, or supported by Tencent or WeChat.

npm versionLicense

bash
pnpm add @weixin-ts/bot
typescript
import { MessageItemType, WeixinBot } from '@weixin-ts/bot'
import { fileSession } from '@weixin-ts/bot/node'

const bot = new WeixinBot({ session: fileSession('.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}` })
})

bot.start()

Packages

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

Project Reference

Released under the MIT License.