您可以使用prompts.Choice 执行此操作。这将为用户提供每个选项的按钮 - 用户可以单击它们或键入响应。
所以,如果您定义了QnAMaker dialog ...
var recognizer = new cognitiveservices.QnAMakerRecognizer({
knowledgeBaseId: 'set your kbid here',
subscriptionKey: 'set your subscription key here'});
var basicQnAMakerDialog = new cognitiveservices.QnAMakerDialog({
recognizers: [recognizer],
defaultMessage: 'No match! Try changing the query terms!',
qnaThreshold: 0.3
});
bot.dialog('/QnAMakerDialogue', basicQnAMakerDialog);
您可以使用replaceDialog 切换到此对话框,具体取决于用户的选择...
function (session, results) {
builder.Prompts.choice(session, "Hi I'm your bot you what are you looking for?", ["Ask a question", "Other cool stuff"], {listStyle: builder.ListStyle.button});
},
function (session, results) {
if(results.response) {
switch (results.response.entity) {
case 'Ask a question':
session.replaceDialog('/QnAMakerDialogue');
case 'Other cool stuff':
session.replaceDialog('/CoolStuffDialog');
default:
session.send("Something went horribly wrong");
return;
}
}
}
如果您的用户已回复他们想提出问题,您将需要提示该问题。为此,我有时会使用包装对话框 QnAPromptDialogue ...
function (session,args,next) {
//if the user just entered 'ask question' or similar, prompt for the actual question
var regex = new RegExp("^ask .*");
if(regex.test(session.message.text)) {
builder.Prompts.text(session, "Go ahead, what is your question?");
} else {
next();
}
},
function (session, results) {
session.replaceDialog('/QnAMakerDialogue');
}
可能不适合所有人,但如果有帮助,也可以考虑。