我是 Microsoft Bot 框架的新手。现在我正在模拟器上测试我的代码。我想在您连接后立即发送“Hello”消息。以下是我的代码。
var restify = require('restify');
var builder = require('botbuilder');
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
var connector = new builder.ChatConnector({
appId: "-- APP ID --",
appPassword: "-- APP PASS --"
});
var bot = new builder.UniversalBot(connector);
server.post('/api/message/',connector.listen());
bot.dialog('/', function (session) {
session.send("Hello");
session.beginDialog('/createSubscription');
});
上面的代码在用户发起对话时发送 Hello 消息。我想在用户连接后立即发送此消息。
钩入conversationUpdate
事件并检查机器人何时添加。之后,您可以发布消息或开始一个新对话框(如下面我从ContosoFlowers Node.js 示例 https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/demo-ContosoFlowers,虽然有很多做同样的事情)。
// Send welcome when conversation with bot is started, by initiating the root dialog
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
bot.beginDialog(message.address, '/');
}
});
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)