官方文档地址:https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-quickstart
前提:
1.你已经安装了Nodejs环境,并且安装了Npm,
2.已经安装Bot framework模拟器,可以参考:https://docs.microsoft.com/en-us/bot-framework/debug-bots-emulator
第一步:在某个空白目录运行命令创建package.json,安装npm插件
npm init
npm install --save botbuilder restify
=
第二步:创建index.js,并输入以下代码,以下的功能非常简单,Bot回应你输入的内容
var restify = require('restify'); var builder = require('botbuilder'); // Setup Restify Server var server = restify.createServer(); server.listen(process.env.port || process.env.PORT || 3978, function () { console.log('%s listening to %s', server.name, server.url); }); // Create chat connector for communicating with the Bot Framework Service var connector = new builder.ChatConnector({ appId: process.env.MICROSOFT_APP_ID, appPassword: process.env.MICROSOFT_APP_PASSWORD }); // Listen for messages from users server.post('/api/messages', connector.listen()); // Receive messages from the user and respond by echoing each message back (prefixed with 'You said:') var bot = new builder.UniversalBot(connector, function (session) { session.send("You said: %s", session.message.text); });
第三步:运行Bot并测试Bot