howdyai / botkit

Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.
MIT License
11.39k stars 2.28k forks source link

Webex adapter: Allow dialogs in threads #2198

Closed monzonj closed 2 years ago

monzonj commented 2 years ago

Currently, there is a bug that prevents dialogs to function properly in threads (webex adapter). This PR adds the missing parentId to the conversationID, so bottkit can recover the conversation and continue with the dialog

Example (this dialog can only happen after applying this PR, otherwise it stops at the first question):

image

Code for the example:

    const MY_DIALOG_ID = 'my-dialog-name-constant';
    const convo = new BotkitConversation(MY_DIALOG_ID, controller);
    convo.say('Howdy!');
    convo.ask('What is your name?', async(response, convo, bot) => {
        console.log(`user name is ${ response }`);
    }, 'name');
    convo.addAction('favorite_color');
    convo.addMessage('Awesome {{vars.name}}!', 'favorite_color');
    convo.addQuestion('Now, what is your favorite color?', async(response, convo, bot) => {
        console.log(`user favorite color is ${ response }`);
    },'color', 'favorite_color');
    convo.addAction('confirmation' ,'favorite_color');
    convo.addQuestion('Your name is {{vars.name}} and your favorite color is {{vars.color}}. Is that right?', [
        {
            pattern: 'no',
            handler: async(response, convo, bot) => {
                await convo.gotoThread('favorite_color');
            }
        },
        {
            default: true,
            handler: async(response, convo, bot) => {
            }
        }
    ], 'confirm', 'confirmation');
    controller.addDialog(convo);

    controller.hears("start a thread", 'message', async(bot, message) => {
        await bot.startConversationInThread(message.channel, message.user, message.parentId || message.id);
        await bot.beginDialog(MY_DIALOG_ID);
    });
jmcombs commented 2 years ago

I wish they'd review and approve this already.

benbrown commented 2 years ago

hi @jmcombs and @monzonj! Sorry for the delay. I'll work on getting this rolled into a release.

benbrown commented 2 years ago

This has been published!