Cannot cancel prompt
Hi, In my Node JS bot (v3.2.2) I have a waterfall of two steps to let a user change his name, in which the first step can prompt the user for a new name. However, if the user wants to cancel that action by saying 'cancel' or 'nevermind' (as suggested in the docs), the actual word is used as a response. The same goes for a number prompt, where it is seen as invalid input. I saw in the release notes for 3.1.0 that the cancel check was removed, is there still a way to cancel a prompt?
I just noticed that in the release notes. Unfortunately, removing any way to escape the prompt makes it really difficult to use. I'm curious why that was done?
Sorry for the delay. You can cancel a prompt. You just need to wrap it with a waterfall that has a cancel action on it. Let me know if you need an example.
No worries. I can't seem to find it in the documentation, do you have an example?
@Stevenic can you provide an example?
Sorry I missed this. Here you go:
bot.dialog('/', [
function (session, args) {
session.beginDialog("/listBuilder", {
prompt: "Who would you like to invite? Send 'cancel' to skip this field.",
morePrompt: "added... Add another name or send 'done' to finish."
});
},
function (session, results) {
if (results.response) {
session.send("Inviting: %s", results.response.join(', '));
}
}
]);
bot.dialog('/listBuilder', [
function (session, args) {
session.dialogData.morePrompt = args.morePrompt;
session.dialogData.list = args.list || [];
var prompt = args.prompt || args.morePrompt;
builder.Prompts.text(session, prompt);
},
function (session, results) {
if (!/\bdone\b/i.test(results.response)) {
session.dialogData.list.push(results.response);
session.replaceDialog("/listBuilder", {
morePrompt: session.dialogData.morePrompt,
list: session.dialogData.list
});
} else {
session.endDialogWithResult({ response: session.dialogData.list });
}
}
]).cancelAction('cancelList', "skipping", { matches: /\bcancel\b/i });
@Stevenic can a LUIS intent be used instead of a regex to recognize the cancel action?
You need to use endConversationAction(). you can also define words like cancel,exit and etc inside it.