node.js - 如何在 Microsoft Bot Framework v.3 (Node.js) 中发送欢迎消息并自动加载特定对话框?
问题描述
我正在尝试在我的机器人启动时显示欢迎消息并加载特定对话框。我们在我工作的公司中使用第 3 版(我知道,它很旧且不受支持)。
至于欢迎信息,https://docs.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-handle-conversation-events?view=azure-bot-service-3.0说使用on conversationUpdate
,效果很好,但这似乎与https://blog.botframework.com/2018/07/12/how-to-properly-send-a-greeting-message-and-common-issues相矛盾-from-customers/,这表明不应使用,conversationUpdate
除非使用 DirectLine,而是发送事件。这是对此事的最终决定吗?有没有更好的办法?
我还想在欢迎消息之后自动加载一个对话框。我该怎么做呢?我可以在上面的“on conversationUpdate”事件期间访问会话并直接在那里加载对话框吗?有没有更好的办法?
谢谢你的帮助!
解决方案
这是矛盾的,但conversationUpdate
在大多数情况下可能是你最好的选择。但是,由于渠道对此的处理方式不同,因此您应该知道结果可能会有所不同。对于直线,使用发送事件是一个更好的选择。
一个例子,以备不时之需:
bot.on('conversationUpdate', function(message) {
if (message.membersAdded) {
message.membersAdded.forEach(function(identity) {
if (identity.id === message.address.bot.id) {
var reply = new builder.Message()
.address(message.address)
.text("Welcome");
bot.send(reply);
}
});
}
});
要立即调用特定对话框,请执行以下操作:
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
bot.beginDialog(message.address, '/main');
}
});
}
});
bot.dialog('/main', [
function (session, args, next) {
session.send("Glad you could join.");
session.beginDialog('/next');
}
]);
只需将两者结合起来发送欢迎消息并启动对话。
希望有帮助!
推荐阅读
- python - python正则表达式无法获取数据
- mysql - Mysql Select Correlation 2 Levels Deep Subqueries
- c++ - 使用 C++ 初始化 Struct 的变量 const char* const*
- angular - 尝试使用 Angular 从 Firebase DB 中提取/检索所有值时,键未定义
- pandas - Pandas 用 grpupby sum 替换行
- javascript - 为什么可以通过同步脚本测量刚刚附加的 DOM 元素?
- java - SQLException: ORA-02292: 违反完整性约束 (SCHOOL.STUDENT_STAGE_FK) - 找到子记录
- c++ - 未实例化的模板的 C++ 标准要求
- android - 自动为列表视图生成项目
- c# - 界面代码生成......Visual Studio 2015 中的快速操作和重构功能