我试图在机器人中调用一个必须转到特定功能的对话框,这是场景...... 我有一个对话框机器人,如下所示
bot.dialog('/Welcome', [
function(session){
builder.Prompts.text(session, "Welcome to the Bot");
},
function (session, args) {
// Has some code
},
function (session, args){
//has some code
}......
什么时候我做替换对话即...
bot.replaceDialog('/Welcome')
它不应该转到第一个功能即。 欢迎来到Bot 它应该跳过这个并转到下一个功能。
有没有办法在azure bot中实现这个目标?
答案 0 :(得分:0)
如果你看一下他们的文章
,这很简单https://docs.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-dialog-replace
他们的例子如下
// This dialog prompts the user for a phone number.
// It will re-prompt the user if the input does not match a pattern for phone number.
bot.dialog('phonePrompt', [
function (session, args) {
if (args && args.reprompt) {
builder.Prompts.text(session, "Enter the number using a format of either: '(555) 123-4567' or '555-123-4567' or '5551234567'")
} else {
builder.Prompts.text(session, "What's your phone number?");
}
},
function (session, results) {
var matched = results.response.match(/\d+/g);
var number = matched ? matched.join('') : '';
if (number.length == 10 || number.length == 11) {
session.userData.phoneNumber = number; // Save the number.
session.endDialogWithResult({ response: number });
} else {
// Repeat the dialog
session.replaceDialog('phonePrompt', { reprompt: true });
}
}
]);
所以你的内容就像下面的
bot.dialog('/Welcome', [
function(session, args, next){
if (!args || args.prompt)
builder.Prompts.text(session, "Welcome to the Bot");
else
next();
},
function (session, args) {
// Has some code
},
function (session, args){
//has some code
}......
您将在下面将其称为
bot.replaceDialog('/Welcome', {prompt: false}))