🤖
Bot SDK
事件驱动的 Bot 客户端 — 长轮询收消息、发送文本/图片/视频/文件、输入状态
pnpm add @weixin-ts/botimport { 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/cdn | CDN 上传/下载 + AES-ECB 加密 |