Search code examples
c#jsonbotframeworkadaptive-cards

How to handle Multiple events on two Buttons click in same Adaptive Card?


I have an adaptive card which has two separate buttons in it. Button 1 is Submit button with action type - Action.Submit and Button 2 with action type also Action.Submit which is supposed to trigger another Adaptive Card.

The issue is that there are only 3 acceptable Action types according to documentation provided that are Action.Submit , Action.ShowCard and Action.OpenURL.

On Clicking the Button the response which is being returned to my Activity Value is of the input choice set only, i cant access the Action

So therefore i cannot filter the button according to the Title also.

The adaptive card json -

https://gist.github.com/NikhilBansal21/39589cfa3fc33f44b273d551b1650

[IN CASE GIST DOES NOT WORK ON CLICKING . PLEASE COPY AND PASTE THE URL ON BROWSER]

I want my two buttons present in same adaptive cards to trigger different custom flows/cards.


Solution

  • Anything you put in a submit action's data property will be included in the payload sent to the bot alongside any input fields in the card. Therefore you can use the data property to differentiate between submit actions.

    "actions": [
        {
            "type": "Action.Submit",
            "title": "1. Recreation",
            "data": {
                "button": "Recreation"
            }
        },
        {
            "type": "Action.Submit",
            "title": "2. Contractors",
            "data": {
                "button": "Contractors"
            }
        },
        {
            "type": "Action.Submit",
            "title": "3. Retail",
            "data": {
                "button": "Retail"
            }
        }
    ]
    

    If you were to use submit actions like these, the activity's value property would contain a button field that you can check to see which button was clicked. Please see the submit actions section of my latest blog post for more information.