BotFramework自适应卡 - 不渲染容器操作

时间:2017-09-12 12:00:22

标签: botframework adaptive-cards

如何为容器添加操作? 根据{{​​3}}容器类型有"动作"对象,但在documentation或僵尸框架模拟器中测试卡时,不会显示任何按钮。 附上我试图生成的那种卡片的例子。

感谢您的帮助。

{
    "type": "AdaptiveCard",
    "body": [
    {

        "style":"normal",
        "type": "Container",
        "separation" : "strong",
        "actions": [
            {
              "type": "Action.OpenUrl",
              "url": "http://foo.bar.com",
              "title": "adaptivecards1"
            }
            ],
        "items": [
            {
                "type": "ColumnSet",
                "separation": "strong",
                "columns": [
                    {
                        "type": "Column",
                        "size":1,
                        "items": [
                            {
                                "type": "TextBlock",
                                "text": "Title",
                                "size": "large",
                                "isSubtle": true
                            },
                            {
                                "type": "TextBlock",
                                "text": "Model: ABC",
                                "size": "small"
                            }
                        ]
                    },
                    {
                        "type": "Column",
                        "size": "1",
                        "items": [
                            {
                                "type": "TextBlock",
                                "text": " "
                            },
                            {
                                "type": "Image",
                                "url": "https://path/to/image.jpg",
                                "size": "large",
                                "horizontalAlignment" :"right"
                            }
                        ]
                    }
                ]
            }
        ]
    },
    {

        "style":"normal",
        "type": "Container",
        "separation" : "strong",
        "actions": [
            {
              "type": "Action. OpenUrl",
              "url": "http://foo.bar.com",
              "title": "adaptivecards2"
            }
            ],
        "items": [
            {
                "type": "ColumnSet",
                "separation": "strong",
                "columns": [
                    {
                        "type": "Column",
                        "size":1,
                        "items": [
                            {
                                "type": "TextBlock",
                                "text": "Another Title",
                                "size": "large",
                                "isSubtle": true
                            },
                            {
                                "type": "TextBlock",
                                "text": "Model: XYZ",
                                "size": "small"
                            }                           ]
                    },
                    {
                        "type": "Column",
                        "size": "1",
                        "items": [
                            {
                                "type": "TextBlock",
                                "text": " "
                            },
                            {
                                "type": "Image",
                                "url": "https://path/to/other/image.jpg",
                                "size": "large",
                                "horizontalAlignment" :"right"
                            }
                        ]
                    }
                ]
            }
        ]
    }
]}

1 个答案:

答案 0 :(得分:1)

根据此GitHub issue,文档中似乎存在错误,并且actions上不存在Container属性。

相反,您应该在ActionSet数组中添加items类型的项目,其中包含actions列表。

根据您的示例,它应该如下所示:

{
    "type": "AdaptiveCard",
    "body": [
        {
            "style": "normal",
            "type": "Container",
            "separation": "strong",
            "items": [
                {
                    "type": "ActionSet",
                    "actions": [
                        {
                            "type": "Action.OpenUrl",
                            "url": "http://foo.bar.com",
                            "title": "adaptivecards1"
                        }
                    ]
                },
                {
                    "type": "ColumnSet",
                    "separation": "strong",
                    "columns": [
                        {
                            "type": "Column",
                            "size": 1,
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": "Title",
                                    "size": "large",
                                    "isSubtle": true
                                },
                                {
                                    "type": "TextBlock",
                                    "text": "Model: ABC",
                                    "size": "small"
                                }
                            ]
                        },
                        {
                            "type": "Column",
                            "size": "1",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": " "
                                },
                                {
                                    "type": "Image",
                                    "url": "https://path/to/image.jpg",
                                    "size": "large",
                                    "horizontalAlignment": "right"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "style": "normal",
            "type": "Container",
            "separation": "strong",
            "items": [
                {
                    "type": "ActionSet",
                    "actions": [
                        {
                            "type": "Action.OpenUrl",
                            "url": "http://foo.bar.com",
                            "title": "adaptivecards2"
                        }
                    ]
                },
                {
                    "type": "ColumnSet",
                    "separation": "strong",
                    "columns": [
                        {
                            "type": "Column",
                            "size": 1,
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": "Another Title",
                                    "size": "large",
                                    "isSubtle": true
                                },
                                {
                                    "type": "TextBlock",
                                    "text": "Model: XYZ",
                                    "size": "small"
                                }
                            ]
                        },
                        {
                            "type": "Column",
                            "size": "1",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": " "
                                },
                                {
                                    "type": "Image",
                                    "url": "https://path/to/other/image.jpg",
                                    "size": "large",
                                    "horizontalAlignment": "right"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

enter image description here

还讨论了here