Skip to content

weixin-ts微信 Bot SDK

跨平台、类型安全、零依赖的微信 Bot TypeScript SDK

weixin-ts

快速开始

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' })

// 扫码登录(或加载已保存的 session)
const result = await bot.login({
  onQrCode: url => console.log('请扫码:', url),
  onScanned: () => console.log('请在微信中确认...'),
})
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()

包一览

说明
@weixin-ts/bot核心 Bot SDK — 轮询、消息、事件、登录
@weixin-ts/cdnCDN 上传/下载 + AES-ECB 加密

基于 MIT 许可证发布