node.js - 具有 2 个操作的自适应卡(接受/拒绝)

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

最佳答案

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

关于node.js - 具有 2 个操作的自适应卡(接受/拒绝),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47696765/

相关文章:

node.js - 修改代理请求的 header

javascript - 在 socket.on 回调中获取套接字对象中监听器的名称

node.js - webdriver-manager 更新抛出错误 : connect ETIMEDOUT

azure - 如何在 Microsoft Azure Bot 框架中查看错过的用户话语

Facebook 机器人消息不显示空行

c# - 适用于 Bot 框架 C# 的 Azure 函数

c# - 机器人框架 V4 : Question about Input forms cards

javascript - 如何在 Javascript 中向 Excel 文件添加条件格式?

node.js - 已解决 : Getting onTurnError when sending adaptive card to MS Teams using Bot Framework SDK 4

c# - 使用 Adaptive Cards Designer,然后用 C# 中的真实值替换示例值