Microsoft Bot Framework v4 adapter for Wechat IndividualAccountgit
Source: Time to do it differently, build chatbots with streamsgithub
If you are finding the Bot Framework v3 version of this adapter, please goto:npm
npm install botbuilder-wechaty-adapter
複製代碼
We assume that, you already have a wechat individual account.bash
An example is located at examples/
directory. Using following command to run it.async
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')
複製代碼
Connect to Wechat: Bot Builder Adapter for Wechat Individual Accountide