I'd like to perform some behavior (e.g., canceling a timer) when a particular dialog is cancelled. I'm using the cancelAction to trigger the cancellation.
I don't see a way to run custom code upon cancellation other than with the onSelectAction option. However, this function is called as soon as the user says "cancel" even though I have a confirmPrompt.
bot.dialog('/intent', intent.dialog)
.cancelAction('cancelIntent', 'Cancelled.', {
matches: cancelKeywords,
confirmPrompt: 'Are you sure you want to cancel?',
onSelectAction: function (session, args, next) { doSomething; }
});
According to the documentation, the onSelectAction "lets you customize the behavior of an action. For instance you could clear the dialog stack before the new dialog is started..." This implies that the action has actually been triggered. If the user hasn't confirmed the action, then I most certainly would not want to clear the dialog stack. Hence, I think this is a bug.
If this is the intended behavior, then please tell me how I can customize the cancellation behavior (when the dialog is actually canceled).
onSelectAction is called before the user has a chance to respond yes or no to the confirmation prompt.
The more I think about this, the more I'm convinced it's a bug, not a "question." The current API behavior isn't useful to anybody. I'd be grateful to learn of a workaround or plan for resolving the issue.
Thanks,
Dan
@Stevenic thoughts?
Any update on this?
@dan-cohn I'm unable to reproduce the issue using only the code snippet. Can you provide a complete working example that reproduces the issue? Thx
This code reproduce this issue : https://gist.github.com/mpicciolli/8a867015c880a76dc8b4d33f186ba21e
If you need another code sample, I can work one up for you. However, I'm not sure what's so complicated about this. The issue is simple: the onSelectAction for a cancelAction gets called immediately after the user says "cancel" before the user confirms the cancellation. I believe it was implemented incorrectly from day one. It shouldn't trigger the onSelectAction until the user has confirmed (unless there's no confirmPrompt).
thanks @mpicciolli for the code example 馃憤
@dan-cohn The issue here is that you're not calling next() at the end of your .onSelectAction() code.
When I added, the call to next(), it prompts the user to confirm the cancel action as expected.
bot.dialog("dialog", [
function (session) {
builder.Prompts.text(session, "Hello... What's your name?");
},
function (session, results) {
session.userData.name = results.response;
builder.Prompts.number(session, "Hi " + results.response + ", How many years have you been coding?");
},
function (session, results) {
session.userData.coding = results.response;
builder.Prompts.choice(session, "What language do you code Node using?", ["JavaScript", "CoffeeScript", "TypeScript"]);
},
function (session, results) {
session.userData.language = results.response.entity;
session.send("Got it... " + session.userData.name +
" you've been programming for " + session.userData.coding +
" years and use " + session.userData.language + ".");
}
]).cancelAction('cancelIntent', 'Cancelled.', {
matches: /^cancel/i,
confirmPrompt: 'Are you sure you want to cancel?',
onSelectAction: function (session, args, next) {
session.send("onSelectAction");
next(); // <--- call next() here
}
});

I'm not sure if you understand my concern (which may be different from @mpicciolli's). I want to know when the user has actually cancelled. Since the selectAction gets called immediately, and then after next() the user is prompted to confirm, I have no way of running some code when the user confirms the cancellation. Perhaps onSelectAction isn't what I'm looking for, but so far I haven't found a way to execute specific code when a cancel actually happens (i.e., after the user says yes).
I also want to refer back to the documentation which says the onSelectAction "lets you customize the behavior of an action. For instance you could clear the dialog stack before the new dialog is started..." Why would I want to clear the dialog stack BEFORE asking the user to confirm? Suppose he/she says no. It's too late if I've already cleared the stack.
What I want is a way to execute code AFTER the confirmation. How would I do that?
Sorry @dan-cohn for the misunderstanding.
You can run this code https://gist.github.com/mpicciolli/a3fdb4c1471d903e8c7ea40999e7919b.
That's what you want ?
@mpicciolli Thanks for suggestion! I can use an outer dialog to catch cancellation of an inner dialog. It works great.
@nwhitmont I still feel there's a deficiency with the onSelectAction method or at least the documentation for it. It doesn't get called when the user actually cancels, it gets called when the user requests cancellation and before s/he confirms.