announcement,

Connect to Wechat: Bot Builder Adapter for Wechat Individual Account

juzibot juzibot Follow Aug 23, 2019 · 1 min read
Connect to Wechat: Bot Builder Adapter for Wechat Individual Account

适用于微信个人帐户的Microsoft Bot Framework v4 适配器

  1. 为 Microsoft Bot Framework v4 做好准备
  2. 不需要在dev.botframework.com上注册机器人,但需要一个微信个人(非官方!)帐户。
  3. Wechaty提供支持
  4. 支持接收和发送几乎所有微信消息类型(WIP)
  • 安装
npm install botbuilder-wechaty-adapter
  • 准备

我们假设您已经有一个微信个人账号。

  • 举例

假设一个示例位于examples/目录中。使用以下命令运行它。

git clone git@github.com:huan/botbuilder-wechaty-adapter.git
cd botbuilder-wechaty-adapter
npm install
npm run example
import {
  ActivityTypes,
  TurnContext,
}                 from 'botbuilder'

import { WechatyAdapter } from 'botbuilder-wechaty-adapter'

export class EchoBot {

  public async onTurn (
    turnContext: TurnContext,
  ): Promise<void> {
    console.info('EchoBot', 'onTurn() %s', turnContext)
    if (turnContext.activity.type === ActivityTypes.Message) {
      const text = turnContext.activity.text
      console.info('RECV:', text)
      switch (text.toLowerCase()) {
        case 'quit':
          console.info('Quiting...')
          process.exit(0)
          break

        case 'ding':
          console.info('Replying `dong`...')
          await turnContext.sendActivity('dong')
          console.info('Replied.')
          break

        default:
          console.info('EchoBot', 'onTurn() skip message "%s"', text)
      }
    }
  }

}

const echoBot = new EchoBot()
const adapter = new WechatyAdapter()
adapter.listen(async (turnContext: TurnContext) => {
  await echoBot.onTurn(turnContext)
}).catch(console.error)

console.info('> Wechaty EchoBot is online. I will reply `dong` if you send me `ding`!')
console.info('> Say "quit" to end.\n')

Bot Friday 会议

Join Newsletter
Get the latest news right in your inbox. We never spam!
Written by juzibot
句子互动是一家人工智能技术与服务提供商,主营业务是基于微信生态,为客户提供集销售、市场和售后于一体的微信智能客服系统。