Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Node.js] session.reset() doesn't seem to work #1197

Closed
ziggy42 opened this issue Sep 8, 2016 · 1 comment
Closed

[Node.js] session.reset() doesn't seem to work #1197

ziggy42 opened this issue Sep 8, 2016 · 1 comment

Comments

@ziggy42
Copy link

ziggy42 commented Sep 8, 2016

So here's my code:

const firstRun = [
    session => 
        builder.Prompts.text(session, session.userData.reask ? "a message" : "another message"),
    (session, results) => {
        const submittedValue = results.response
        if (isValidValue(submittedValue)) {
            builder.Prompts.confirm(session, "some text")
        } else {
            session.send("some text")
            session.userData.reask = true
            session.reset("/firstRun")
        }
    },
    (session, results) => {
        if (results.response)
            session.beginDialog("/otherDialog")
        else {
            session.userData.reask = true
            session.beginDialog("/firstRun")
        }
    }
]

If I call reset it doesn't work as I thought it would, because after the child /firstRun dialog is completed, the parent is resumed.
So, what's the proper way to "restart" a dialog?

@muzahmed
Copy link
Contributor

muzahmed commented Sep 8, 2016

@ziggy42 use i think for your case, you want to use session.replaceDialog dialog instead

here's an example with breaking out the prompt into its own dialog:

bot.dialog('/', [
    function (session) {
        session.beginDialog('/question');
    },
    function (session, results) {
        // child response here
        session.send("done" + results.r);
    }
]);

bot.dialog('/question', [function(session) {
    builder.Prompts.confirm(session, "proceed");
},  function(session, results) {
    if (results.response) {
        session.endDialogWithResult({r: results.response});
    } else {
        session.replaceDialog('/question');
    }
}]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants