wechaty-puppet-mini
TypeScript icon, indicating that this package has built-in type declarations

0.0.9 • Public • Published

PUPPET-MINI

NPM Version npm (tag) NPM

Powered by Wechaty TypeScript

运行方法

安装依赖

npm install @juzi/wechaty
npm install wechaty-puppet-mini

编写代码

import { WechatyBuilder } from '@juzi/wechaty'

WechatyBuilder.build()  // get a Wechaty instance
  .on('message',       message => console.log(`Message: ${message}`))
  .start()

Learn more for building your first Wechaty bot at https://github.com/wechaty/, https://github.com/wechaty/getting-started

消息种类支持

消息类型 从属(根据接口返回) api 接收 发送
文本 text message.text
图片 image message.toImage()
视频 video message.toFilebox()
文件 other message.toFilebox()

使用示例

1. 可配置参数

  • tokenchatbotIdmqNamemqPassword可以通过环境变量或者此处传入。
  • port可以指定 koa 服务监听的端口和路由前缀,默认是8077。
new PuppetMini({
  token: 'mini_1325g3v4vs4xvu7snst',
  chatbotId: 'juzi_1qaz@WSX',
  mqName: 'kbl',
  mqPassword: '1qaz@WSX',
})

2. 创建实例

const bot = WechatyBuilder.build({
  puppet: new PuppetMini({
    token: 'mini_1325g3v4vs4xvu7snst',
    chatbotId: 'juzi_1qaz@WSX',
    mqName: 'kbl',
    mqPassword: '1qaz@WSX',
  }),
})  // get a Wechaty instance
  .on('login', (user: any) => log.info(`User ${user} logged in`))
  .on('message', async (message: Message) => {
    log.info(`Message: ${message}`)
  })

await bot.start()

const contact = await bot.Contact.find({ id: 'xxxxxxxxxxx' })

3. 文本消息

await contact.say('This is a simple text message.')

4. 图片消息

contact.say(FileBox.fromFile('C:\\Users\\Desktop\\1.png'))

Wechaty

Wechaty 是一个开源聊天机器人框架SDK,具有高度封装、高可用的特性,支持NodeJs, Python, Go 和Java 等多语言版本。在过去的5年中,服务了数万名开发者,收获了 Github 的 9600 Star。同时配置了完整的DevOps体系并持续按照Apache 的方式管理技术社区。

项目技术栈

  1. TypeScript programming language
  2. Git
  3. REST Api

相关链接

Package Sidebar

Install

npm i wechaty-puppet-mini

Weekly Downloads

48

Version

0.0.9

License

none

Unpacked Size

187 kB

Total Files

146

Last publish

Collaborators

  • leo_chen