howdyai / botkit

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

Adaptive Card as part of Dialog and Receive Response - WebEx Teams #1862

Closed NxP4Code closed 4 years ago

NxP4Code commented 4 years ago

I am trying to use Adaptive Cards in Dialog and use fallback text for the non-supported WebEx Teams clients so that users can respond in the text format as well.

something like this, if the client supports card user will see a proper card and will be able to hit the submit button which sends attachmentActions to the webhook with an object. My test card is simple it has one drop down with 3 options and one submit button.

If client doesn't support AdaptiveCards, the user can respond in text and we continue the dialog with a text response.

    daily_transport_card_dialog.ask({
        text: 'Are you taking Cab Today?',
        attachments: async (template, vars) => {
            return createCabCard(vars.emp_name)
        }
    }, async (response, convo, bot) => {
            if (typeof response === 'object'){
                myobj = JSON.stringify(response);
                await bot.say(`Got your response:${myobj}`);
            }
            else
            console.log(`Got response in text :${response}`);
        },  'wants_transport');

The problem is 2 fold.

  1. when user hit submits on card in response to ask in dialog, it is not captured in the response object in sample code above like regular text.

It seems, continueDialog function in prompts.ts file has condition which is stopping it form processing any non-message events.

    public async continueDialog(dc: DialogContext): Promise<DialogTurnResult> {
        // Don't do anything for non-message activities
        if (dc.context.activity.type !== ActivityTypes.Message ) {
            return Dialog.EndOfTurn;
        }
  1. When we send a card using ask in the dialog and user respond to the card first, bot doesn't fire controller.on('attachmentActions') event until that dialog is completed. if user responds in the card bot doesn't see the controller.on('attachmentActions'). User has to respond with text first and complete dialog and after that when user hits the submit button on card it is received on the bot in controller.on('attachmentActions').

if controller.on works, maybe somehow I can hanle response in controller.on and complete my convo from controller.on when user respond with card submit.

Any alternative or fix to this?

benbrown commented 4 years ago

The mechanism to include the card submission in a dialog is to use a middleware to change the activity type from Event to Message as it is being processed.

However, there is not currently a way to access the additional payload present in this event inside the ask handler function. This will change when #1801 is merged.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

NxP4Code commented 4 years ago

It depends on when #1801 is merged.