Skip to content

weixin-ts微信 Bot SDK

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

weixin-ts

快速开始

免责声明:本项目是面向微信 iLink Bot API 的非官方 SDK,与腾讯或微信没有从属、背书或官方支持关系。

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

// 扫码登录(或加载已保存的 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}` })
})

bot.start()

包一览

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

项目参考

基于 MIT 许可证发布