具有2个动作的自适应卡(接受/拒绝)

时间:2017-12-07 14:01:14

标签: node.js botframework adaptive-cards

有人可以帮助如何处理自适应卡中的2个提交操作吗? 如果用户单击“接受”按钮,则必须启动另一个对话框。 如果用户点击了“拒绝”按钮,则必须启动重启对话框。

json布局

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

代码:

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;
    }

1 个答案:

答案 0 :(得分:1)

选择将是 .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)
    }
})