c# - 自适应卡片 C# - 如何在 Body ColumnSet(每行)中添加 Action.Submit

标签 c# bots

我正在尝试在 BOT DirectLine 聊天中显示自适应卡片。自适应卡将包含表格格式的数据。我想在表格的每一行上添加操作按钮以执行特定操作。

但我无法在 ColumnSet 中添加“Action.Submit”。我只能在正文部分之外添加(即单独的操作部分)。

请帮我解决这个问题。以下是发送到 Directline 客户端的示例 JSON。

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [
    {
      "type": "Container",
      "items": [
        {
          "type": "TextBlock",
          "text": "Pending Items",
          "weight": "bolder",
          "size": "medium"
        },
        {
          "type": "ColumnSet",
          "columns": [
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "Number",
                  "weight": "bolder",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "Module",
                  "weight": "bolder",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "Pending count",
                  "weight": "bolder",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "Action",
                  "weight": "bolder",
                  "wrap": true
                }
              ]
            }
          ]
        },
        {
          "type": "ColumnSet",
          "columns": [
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "1",
                  "weight": "bolder",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "Module 1",
                  "weight": "bolder",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "1",
                  "weight": "bolder",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "Input.Toggle",
                  "id": "acceptTerms",
                  "title": "Select this",
                  "value": "true",
                  "valueOn": "true",
                  "valueOff": "false"
                }
              ]
            }
          ]
        },
        {
          "type": "ColumnSet",
          "columns": [
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "2",
                  "weight": "bolder",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "Module 1",
                  "weight": "bolder",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "10",
                  "weight": "bolder",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "Input.Toggle",
                  "id": "acceptTerms",
                  "title": "Select this",
                  "value": "true",
                  "valueOn": "true",
                  "valueOff": "false"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "actions": [
    {
      "type": "Action.ShowCard",
      "title": "Proceed Selected",
      "card": {
        "type": "AdaptiveCard",
        "body": [
          {
            "type": "TextBlock",
            "text": "Are you sure want to Proceed",
            "weight": "bolder",
            "wrap": true
          }
        ],
        "actions": [
          {
            "type": "Action.Submit",
            "title": "OK"
          }
        ]
      }
    },
    {
      "type": "Action.Submit",
      "title": "Cancel",
      "id": "c1"
    }
  ]
}

最佳答案

您可以将容器放置在列中。 此示例可以在列内无错误地显示操作: 在此 Adaptive Card Designer 中进行了测试

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.0",
    "body":[

            {
                "type": "TextBlock",
                "size": "Small",
                "text": "You have the following Time Off planned:"
            }, {
                "type": "ColumnSet",
                "columns": [{
                    "type": "Column",
                    "width": "auto",
                    "items": [{
                        "type": "TextBlock",
                        "size": "Small",
                        "text": "Holiday"
                    }]
                }, {
                    "type": "Column",
                    "width": "auto",
                    "items": [{
                        "type": "TextBlock",
                        "size": "Small",
                        "text": "-"
                    }]
                }, {
                    "type": "Column",
                    "width": "auto",
                    "items": [{
                        "type": "TextBlock",
                        "size": "Small",
                        "text": "Approved"
                    }]
                }, {
                    "type": "Column",
                    "width": "stretch",
                    "items": [{
                        "type": "Container",
                        "items": [{
                            "type": "ActionSet",
                            "actions": [{
                                "type": "Action.Submit",
                                "title": "Cancel",
                                "data": {
                                    "action": "cancelRequest"
                                }
                            }]
                        }]
                    }]
                }]
            }, {
                "type": "ColumnSet",
                "columns": [{
                    "type": "Column",
                    "width": "auto",
                    "items": [{
                        "type": "TextBlock",
                        "size": "Small",
                        "text": "from "
                    }]
                }, {
                    "type": "Column",
                    "width": "auto",
                    "items": [{
                        "type": "TextBlock",
                        "size": "Small",
                        "text": "2019-09-11"
                    }]
                }, {
                    "type": "Column",
                    "width": "auto",
                    "items": [{
                        "type": "TextBlock",
                        "size": "Small",
                        "text": "to "
                    }]
                }, {
                    "type": "Column",
                    "width": "auto",
                    "items": [{
                        "type": "TextBlock",
                        "size": "Small",
                        "text": "2019-09-18"
                    }]
                }]
            }],
            "actions": [{
                "type": "Action.Submit",
                "title": "Submit New Request",
                "data": {
                    "action": "timeoff.request.card"
                }
            }, {
                "type": "Action.Submit",
                "title": "Dismiss",
                "data": {
                    "action": "timeoff.cancel"
                }
            }]
        }

关于c# - 自适应卡片 C# - 如何在 Body ColumnSet(每行)中添加 Action.Submit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50612835/

相关文章:

c# - 如何在没有 svcutil.exe 的情况下使用 WCF 服务?

C#:可以返回新添加对象的排序位置的通用排序容器?

c# - 如何实现微软网络机器人的电子邮件服务

c# - 如何在 Microsoft Bot Framework 中的对话框之间传递对象?

python - PyAutoGUI 定位命令返回错误的图像识别坐标

c# - 无需管理员权限即可创建 outlook 插件

c# - 如果没有发生任何更改,linq 查询是否会重新执行?

javascript - 如何修复必须使用导入来加载 ES 模块 discord.js

java - 如何设置 Heroku 托管的 Twitter 机器人定期运行,在运行之间关闭测功机?

c# - Windows 8 中 WebView 的滚动问题