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

时间:2018-05-30 20:23:29

标签: c# bots

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

但我无法添加' Action.Submit'在ColumnSet中。我只能在身体部分之外添加(即,单独的动作部分)。

请帮我解决这个问题。下面是发送给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"
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

您可以在容器内放置一个容器。 此示例可以无误地显示列内的操作: 已在此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"
                }
            }]
        }