我在Microsoft Bot Framework上编写了一个机器人。我使用过LUIS语言模型。 以下是我的代码:
bot.use(builder.Middleware.dialogVersion({ version: 1.0, resetCommand: /^reset/i }));
bot.dialog('/', intents);
intents.matches('GoogleHome', [
function (session, args) {
if(builder.EntityRecognizer.findEntity(args.entities, 'cookingtips'))
{
quickReply(session, args)
}
if(builder.EntityRecognizer.findEntity(args.entities, 'wakingtips'))
{
//My rest of the code
}
}])
以下是我的quickReply
的代码function quickreply(session, args){
var msg = new builder.Message(session)
.text("Let me know the date and time you are comfortable with..")
.suggestedActions(
builder.SuggestedActions.create(
session,[
builder.CardAction.imBack(session, "CookingTips", "CookingTips"),
builder.CardAction.imBack(session, "WalkingTips", "WalkingTips")
]
)
);
builder.Prompts.choice(session, msg, ["CookingTips", "WalkingTips"]), function(session,results) {
console.log(results);
session.send('So I understand you want a cooking tip ' + results + ' right now');
session.endDialog();
}}
我能够快速回复并点击没有任何反应。我在控制台中看到以下内容:
.BotBuilder:prompt-choice - Prompt.returning([object Object])
.BotBuilder:prompt-choice - Session.endDialogWithResult()
/ - Session.endDialogWithResult()
相反,我希望将消息发送到我的LUIS或至少显示回调函数中写入的确认消息。我该怎么办?
答案 0 :(得分:0)
由于您的quickReply()
函数没有创建新的对话框,因此endDialog()
将终端当前对话框,因为您没有父对话框,无法返回继续对话框。
您可以通过next
中间值来传递值,将代码修改为:
intents.matches('GoogleHome', [
function (session, args, next) {
if(builder.EntityRecognizer.findEntity(args.entities, 'cookingtips'))
{
quickReply(session, args, next)
}
if(builder.EntityRecognizer.findEntity(args.entities, 'wakingtips'))
{
//My rest of the code
}
},(session,result)=>{
//get the user choice here
console.log(result);
session.send(JSON.stringify(result));
}])
<强> quickReply 强>
function quickRelpy(session, args, next) {
var msg = new builder.Message(session)
.text("Let me know the date and time you are comfortable with..")
.suggestedActions(
builder.SuggestedActions.create(
session, [
builder.CardAction.imBack(session, "CookingTips", "CookingTips"),
builder.CardAction.imBack(session, "WalkingTips", "WalkingTips")
]
)
);
builder.Prompts.choice(session, msg, ["CookingTips", "WalkingTips"]);
}