KHaemels
KHaemels

Reputation: 85

Adaptivecard with 2 actions (Accept/Decline)

Can someone help how to handle 2 submit actions in an adaptive card? If the user clicks on the acceptbutton, another dialog must start. If the user clicks on the declinebutton, the restart dialog has to start.

The json layout

        "actions": [
        {
            "type": "Action.Submit",
            "title": "Accept",
            "data": { "choice": "Accept"}
        },
        {
            "type": "Action.Submit",
            "title": "Decline",
            "data": { "choice": "Decline"}
        }
    ]

Code:

bot.dialog('overview', function (session, options) {
    if (session.message && session.message.value) {
        if(choice == "Accept"){
            session.beginDialog('otherDialog');
        } else if (choice == "Decline"){
            session.beginDialog('restart');
        }
        return;
    }

Upvotes: 1

Views: 703

Answers (1)

Eric Dahlvang
Eric Dahlvang

Reputation: 8292

choice will be a property on .value

bot.dialog('overview', function (session, options) {
    if (session.message && session.message.value) {
        session.endDialog();
        switch (session.message.value.choice) {
            case 'Accept':
                session.beginDialog('otherDialog');
                break;
            case 'Decline':
                session.beginDialog('restart');
                break;                
          }             
        return;
    }else{
        //show the card, since there has not been a choice
        var cardMessage  = require('./overviewCard.json');
        cardMessage.address = session.message.address
        bot.send(cardMessage)
    }
})

Upvotes: 1

Related Questions