我正在尝试实现与该主题相似的功能
Begin Dialog with QnA Maker Bot Framework recognizer (Node JS)
该建议的工作方式如下:让机器人首先发送欢迎消息,然后等待问题。
但是,该机器人现在说“ Hj!我能为您提供什么帮助?”,等待问题,然后再次回到欢迎状态。
就像是
嗨!我怎么帮你?
问:汽车维修多少钱
答:致电500-XXXX等。
问:休假那天我应该联系谁?
嗨!我怎么帮你?
我玩了beginDialog,结束对话,替换对话..但是没有运气。
这是最新的代码。
bot.dialog('/', [
function (session ) {
session.beginDialog('/welcome');
},
function (session) {
session.beginDialog('/qna');
}
]) ;
bot.dialog('/welcome', [
function (session) {
// Send a greeting and show help.
builder.Prompts.text(session, "Hi! How can I help you?");
// session.endDialog();
}
]);
bot.dialog('/qna', basicQnAMakerDialog ) ;
最佳答案
这是一个代码示例,该示例显示了如何侦听新用户连接到bot时触发的conversationUpdate
事件。又称为“欢迎消息”:
// Listen for 'conversationUpdate' event to detect members joining conversation.
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id == message.address.bot.id) {
// Bot is joining conversation
// - For WebChat channel you'll get this on page load.
var reply = new builder.Message()
.address(message.address)
.text("Welcome to my page");
bot.send(reply);
} else {
// User is joining conversation
// - For WebChat channel this will be sent when user sends first message.
// - When a user joins a conversation the address.user field is often for
// essentially a system account so to ensure we're targeting the right
// user we can tweek the address object to reference the joining user.
// - If we wanted to send a private message to teh joining user we could
// delete the address.conversation field from the cloned address.
var address = Object.create(message.address);
address.user = identity;
var reply = new builder.Message()
.address(address)
.text("Hello %s", identity.name);
bot.send(reply);
}
});
}
});
关于javascript - Microsoft QnA制造商-欢迎消息循环,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44572065/