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

Default callback not invoked in multi-ask conversation #63

Closed
adphillips opened this issue Dec 31, 2015 · 2 comments
Closed

Default callback not invoked in multi-ask conversation #63

adphillips opened this issue Dec 31, 2015 · 2 comments

Comments

@adphillips
Copy link

Hi, Maybe I am just not using this correctly but when I have a conversation in which the bot is asking several questions in succession as in the snippet below, the default callback is not invoked. I confirmed this by commenting out other asks and just leaving the one with the default and in that case the default callback in invoked (as is the case with the sample code 'Shall we proceed Say YES, NO or DONE to quit.')

        convo.ask('Any more to say?', [{
            pattern: bot.utterances.no,
            callback: function(response, convo) {
                convo.say('Moving on..');
                convo.next();
            }
        }, {
            pattern: bot.utterances.yes,
            callback: function(response, convo) {
                convo.say('Great! I will continue...');
                convo.next();
            }
        }, {
            default: true,
            callback: function(response, convo) {
                // just repeat the question 
                convo.say('Repeating..');
                convo.repeat();
                convo.next();
            }
        }]);

        convo.ask(username + ', what did you do last year?', [{
            pattern: '.*',
            callback: function(response, convo) {
                console.log(response);
                //convo.say(username + ', what are you doing today?')
                convo.next();
            }
        }]);```
@anonrig
Copy link
Contributor

anonrig commented Jan 2, 2016

Hello @adphillips

You can do a similar functionality in slack-manager repo from https://github.com/anonrig/slack-manager/blob/master/src/models/meeting.js#L60

@benbrown
Copy link
Contributor

benbrown commented Jan 3, 2016

@adphillips The issue here is that using convo.ask twice in a row. This causes the 2 questions to be added sequentially into the queue instead of waiting for the answer to add the second question.

To get your expected results, but the second convo.ask inside the callback.

One way to do this is to encapsulate each step of the conversation into a function that can be called from inside the callbacks.

See here for an example:

https://github.com/howdyai/botkit/blob/master/examples/convo_bot.js#L74

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

No branches or pull requests

4 participants