动作留言卡未呈现

时间:2019-09-11 15:16:43

标签: c# json botframework microsoft-teams adaptive-cards

我正在尝试发布Messageback自适应卡,但在仿真器中出现以下错误:     该卡无法渲染。它格式不正确或使用了该主机不支持的功能。

我正在使用AdaptiveCards 1.2.2版本。我正在使用C#发布此自适应卡,但无法确定问题所在。

我的Json文件:

{
  "type": "AdaptiveCard",
  "selectAction": {
    "type": "Action.Submit"
  },
  "body": [

    {
      "type": "TextBlock",
      "text": "1:1 with John Doe",
      "weight": "Bolder"
    },
    {
      "type": "ColumnSet",
      "columns": [
        {
          "type": "Column",
          "items": [
            {
              "type": "Image",
              "url": "https://images.idgesg.net/images/article/2019/04/google-calendar-android-100794956-large.jpg",
              "altText": "Calendar",
              "size": "small"


            }
          ],
          "width": "auto"
        },
        {
          "type": "Column",
          "items": [
            {
              "type": "TextBlock",
              "text": "Tomorrow, 30 May"
            }
          ],
          "width": "stretch"
        }
      ]
    },
    {
      "type": "ColumnSet",

      "columns": [
        {
          "type": "Column",
          "items": [
            {
              "type": "Image",
              "url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
              "altText": "Calendar",
              "height": "20px"
            }
          ],
          "width": "auto"
        },
        {
          "type": "Column",
          "items": [
            {
              "type": "TextBlock",
              "text": "John Doe",

              "spacing": "Medium"
            }
          ],
          "width": "stretch"
        }
      ]
    },
    {
      "type": "TextBlock",
      "text": "Slots available - **1 hr duration**",
      "separator": true,
      "spacing": "Medium",
      "isSubtle": true
    },



    {
      "type": "ColumnSet",
      "columns": [
        {
          "type": "Column",
          "items": [
            {

              "actions": [
                {
                  "type": "Action.Submit",
                  "title": "11:00 AM",
                  "data": {
                    "msteams": {
                      "type": "messageBack",
                      "displayText": "11:00 AM",
                      "text": "text to bots",
                      "value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
                    }
                  }
                }
              ]
            }
          ],
          "width": "auto"
        },

    {

      "actions": [
        {
          "type": "Action.Submit",
          "title": "Cancel",
          "data": {
            "msteams": {
              "type": "messageBack",
              "displayText": "Cancel",
              "text": "text to bots",
              "value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
            }
          }
        },
        {
          "type": "Action.Submit",
          "title": "Confirm",
          "data": {
            "msteams": {
              "type": "messageBack",
              "displayText": "Confirm",
              "text": "text to bots",
              "value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
            }
          }
        }
      ]

  }
  ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.0"
}

1 个答案:

答案 0 :(得分:0)

测试自适应卡的一种好方法是使用Adaptive Card Designer或Microsoft Teams的App Studio中的卡编辑器。如果未渲染预览,则您的卡有问题。

在您的情况下,您说要使用自适应卡1.2.2,但是要在JSON中包含"version": "1.0"。您可能要改说"version": "1.2",但请记住,自适应卡的版本越高,越少的客户端能够渲染它。

更重要的是,您要在列和列集中都放置一个actions属性,而这两个属性都不具有actions属性。请参阅schema以查看哪些元素具有什么属性。您可能打算使用操作集(1.2功能),或者可能只想在卡的身体外部使用卡本身的actions属性。

更重要的是,左括号比右括号更多,因此JSON无效。我怀疑您忘记关闭最后一个列集及其columns数组。请使用Visual Studio Code之类的编辑器来自动格式化JSON并确保其有效。在您的Stack Overflow问题中正确格式化JSON也是一种良好的礼节,以便其他人可以在不为您格式化的情况下读取它。

请阅读my latest blog post,以获取有关自适应卡以及与Microsoft Bot Framework一起使用的更多信息。