botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Cannot cancel prompt

Open hgjkant opened this issue 10 years ago • 7 comments

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?

hgjkant avatar Aug 10 '16 12:08 hgjkant

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?

MironV avatar Aug 10 '16 22:08 MironV

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.

Stevenic avatar Aug 23 '16 06:08 Stevenic

No worries. I can't seem to find it in the documentation, do you have an example?

hgjkant avatar Aug 23 '16 11:08 hgjkant

@Stevenic can you provide an example?

danmarshall avatar Aug 27 '16 00:08 danmarshall

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 avatar Sep 12 '16 18:09 Stevenic

@Stevenic can a LUIS intent be used instead of a regex to recognize the cancel action?

hgjkant avatar Sep 22 '16 10:09 hgjkant

You need to use endConversationAction(). you can also define words like cancel,exit and etc inside it.

rahul251993 avatar Sep 27 '16 11:09 rahul251993