How to use the botkit.BotkitConversation function in botkit

To help you get started, we’ve selected a few botkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github howdyai / botkit / packages / testbot / features / sample_onboarding.js View on Github external
// noop, just continue
            }
        }
    ],{key:'confirmed'});
    confirmation.say('All done!');
    confirmation.addGotoDialog(START_OVER,'try_again');

    const startover = new BotkitConversation(START_OVER, controller);
    startover.say('Lets start from the top...');
    startover.addChildDialog(PROFILE_DIALOG, 'profile');
    startover.addGotoDialog(CONFIRM_DIALOG);

    /**
     * Now, define a BotkitConversation style dialog that will use the profile dialog as a child.
     */
    const onboarding = new BotkitConversation(ONBOARDING_DIALOG, controller);
    onboarding.say('Hello, human! Nice to meet you.');
    onboarding.say('Before we begin, I need to ask you some questions.');
    onboarding.addChildDialog(PROFILE_DIALOG, 'profile');
    onboarding.say('Thanks, {{vars.profile.name}}! Your onboarding has completed.');
    onboarding.addGotoDialog(CONFIRM_DIALOG);

    /**
     * Add all of our dialogs to the bot.
     */
    controller.addDialog(textPrompt);
    controller.addDialog(profile);
    controller.addDialog(onboarding);
    controller.addDialog(confirmation);
    controller.addDialog(startover);

    /** 
github howdyai / botkit / packages / testbot / features / websocket_features.js View on Github external
await bot.reply(message,{
                text: 'Here are some quick replies',
                quick_replies: [
                    {
                        title: 'Foo',
                        payload: 'foo',
                    },
                    {
                        title: 'Bar',
                        payload: 'bar',
                    }
                ]
            });
        });

        let typing = new BotkitConversation('typing', controller);

        typing.say('I am going to type for a while now...');
        typing.addAction('typing');
    
        // start the typing indicator
        typing.addMessage({type: 'typing'}, 'typing');
        // trigger a gotoThread, which gives us an opportunity to delay the next message
        typing.addAction('next_thread','typing');
    
        typing.addMessage('typed!','next_thread');
    
       // use the before handler to delay the next message 
        typing.before('next_thread',  async() => {
            return new Promise((resolve, reject) => {
                // simulate some long running process
                setTimeout(resolve, 3000);
github howdyai / botkit / packages / testbot / features / slack_features.js View on Github external
// Return an error to Slack
            bot.dialogError([
                {
                    "name": "field1",
                    "error": "there was an error in field1"
                }
            ])
        });

        controller.on('dialog_cancellation', async (bot, message) => {
            await bot.reply(message, 'Got a dialog cancellation');
        });


        const dialog = new BotkitConversation('slack_buttons', controller);

        dialog.ask({
            text: 'Click one of these ATTACHMENT BUTTONS',
            attachments: [
                {
                    title: 'This is an attachment',
                    text: 'It has some buttons',
                    callback_id: '123',
                    actions: [
                        {
                            name: 'buttona',
                            type:  'button',
                            text: 'Click this',
                            value: 'Clicked this',                                
                        },
                        {
github howdyai / botkit / packages / testbot / features / interruptions.js View on Github external
module.exports = function(controller) {

    const dialog = new BotkitConversation('HELPDIALOG', controller);

    dialog.ask('What can I help with?', [], 'subject');
    dialog.say('HRRM! What do I know about {{vars.subject}}?');
    dialog.addAction('display_results');

    dialog.before('display_results', async(convo, bot) => {
        convo.setVar('results', 'KNOWLEDGE BASE EMPTY');
    });

    dialog.addMessage('Here is what I know: {{vars.results}}', 'display_results');

    controller.addDialog(dialog);

    // hear the word help, and interrupt whatever is happening to handle it first.
    controller.interrupts(async(message) => { return message.intent==='help' }, 'message', async(bot, message) => {
        await bot.reply(message,'I heard you need help more than anything else!');
github howdyai / botkit / packages / testbot / features / sample_onboarding.js View on Github external
},
        async(step) => {
            // capture result of previous step
            step.values.age = step.result;

            return await step.prompt(ONBOARDING_PROMPT, 'What is your location?');
        },
        async(step) => {
            // capture result of previous step
            step.values.location = step.result;

            return await step.endDialog(step.values);
        }
    ]);

    const confirmation = new BotkitConversation(CONFIRM_DIALOG, controller);
    confirmation.say('Your name is {{vars.profile.name}}, your age is {{vars.profile.age}} and your location is {{vars.profile.location}}');
    confirmation.ask('Is that correct?', [
        {
            pattern: 'no',
            handler: async(res, convo, bot) => {
                await convo.gotoThread('try_again');
                // convo
            }
        },
        {
            default: true,
            handler: async(res, convo, bot) => {
                // noop, just continue
            }
        }
    ],{key:'confirmed'});
github howdyai / botkit / packages / testbot / features / sample_onboarding.js View on Github external
handler: async(res, convo, bot) => {
                await convo.gotoThread('try_again');
                // convo
            }
        },
        {
            default: true,
            handler: async(res, convo, bot) => {
                // noop, just continue
            }
        }
    ],{key:'confirmed'});
    confirmation.say('All done!');
    confirmation.addGotoDialog(START_OVER,'try_again');

    const startover = new BotkitConversation(START_OVER, controller);
    startover.say('Lets start from the top...');
    startover.addChildDialog(PROFILE_DIALOG, 'profile');
    startover.addGotoDialog(CONFIRM_DIALOG);

    /**
     * Now, define a BotkitConversation style dialog that will use the profile dialog as a child.
     */
    const onboarding = new BotkitConversation(ONBOARDING_DIALOG, controller);
    onboarding.say('Hello, human! Nice to meet you.');
    onboarding.say('Before we begin, I need to ask you some questions.');
    onboarding.addChildDialog(PROFILE_DIALOG, 'profile');
    onboarding.say('Thanks, {{vars.profile.name}}! Your onboarding has completed.');
    onboarding.addGotoDialog(CONFIRM_DIALOG);

    /**
     * Add all of our dialogs to the bot.
github howdyai / botkit / packages / botkit-plugin-cms / src / cms.ts View on Github external
scripts.forEach((script) => {
            // map threads from array to object
            let threads = {};
            script.script.forEach((thread) => {
                threads[thread.topic] = thread.script.map(this.mapFields);
            });

            let d = new BotkitConversation(script.command, this._controller);
            d.script = threads;
            botkit.addDialog(d);
        });
    }
github howdyai / botkit / packages / testbot / features / webex_features.js View on Github external
module.exports = function(controller) {

    if (controller.adapter.name == 'Webex Adapter') {

      controller.ready(async function() {
        await controller.adapter.registerAdaptiveCardWebhookSubscription('/api/messages');
      });

    const NEW_ROOM_DIALOG = 'new_room_dialog';
    const dialog = new BotkitConversation(NEW_ROOM_DIALOG, controller);
    dialog.say('I created this room so we could continue our conversation in private...');
    dialog.ask('How does that sound?', async(response, convo, bot) => {

    }, {key: 'how_it_sounds'});
    dialog.say('Ah, {{vars.how_it_sounds}}, eh?');
    dialog.say('I guess that is that.')

    controller.addDialog(dialog);

    controller.hears('delete','message,direct_message', async(bot, message) => {

        let reply = await bot.reply(message,'This message will be deleted in a few seconds.');
        setTimeout(async () => {
            let res = await bot.deleteMessage(reply);
        }, 5000);
github howdyai / botkit / packages / testbot / features / dynamic_attachments.js View on Github external
module.exports = function(controller) {

    let dialog = new BotkitConversation('dynamic_attachments', controller);   
    dialog.ask({
        text: 'What is your name?',
        quick_replies: [
            {
                title: '{{vars.default_name}}',
                payload: '{{vars.default_name}}',
            }
        ]
    }, [], 'name');

    dialog.ask({
        text: 'Your name is:',
        quick_replies: async(line, vars) => {
            return [
                {
                    title: 'Foo',
github howdyai / botkit / packages / generator-botkit / generators / webex / templates / features / webex_features.js View on Github external
module.exports = function(controller) {

    const NEW_ROOM_DIALOG = 'new_room_dialog';
    const dialog = new BotkitConversation(NEW_ROOM_DIALOG, controller);
    dialog.say('I created this room so we could continue our conversation in private...');
    dialog.ask('How does that sound?', async(response, convo, bot) => {

    }, {key: 'how_it_sounds'});
    dialog.say('Ah, {{vars.how_it_sounds}}, eh?');
    dialog.say('I guess that is that.')

    controller.addDialog(dialog);

    controller.hears('delete','message,direct_message', async(bot, message) => {

        let reply = await bot.reply(message,'This message will be deleted in a few seconds.');
        setTimeout(async () => {
            let res = await bot.deleteMessage(reply);
        }, 5000);