使用python

时间:2018-05-21 16:39:26

标签: python botframework adaptive-cards

我正在使用python中的bot框架样本进行一些演示https://github.com/Microsoft/botbuilder-python 现在我想在响应中添加一个简单的自适应卡,我认为它是等待context.send_activity(响应)的部分,但是我无法附加卡。我从docs示例中抓住了这张卡片:

{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
    {
        "type": "Container",
        "items": [
            {
                "type": "TextBlock",
                "text": "Publish Adaptive Card schema",
                "weight": "bolder",
                "size": "medium"
            },
            {
                "type": "ColumnSet",
                "columns": [
                    {
                        "type": "Column",
                        "width": "auto",
                        "items": [
                            {
                                "type": "Image",
                                "url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
                                "size": "small",
                                "style": "person"
                            }
                        ]
                    },
                    {
                        "type": "Column",
                        "width": "stretch",
                        "items": [
                            {
                                "type": "TextBlock",
                                "text": "Matt Hidinger",
                                "weight": "bolder",
                                "wrap": true
                            },
                            {
                                "type": "TextBlock",
                                "spacing": "none",
                                "text": "Created {{DATE(2017-02-14T06:08:39Z, SHORT)}}",
                                "isSubtle": true,
                                "wrap": true
                            }
                        ]
                    }
                ]
            }
        ]
    },
    {
        "type": "Container",
        "items": [
            {
                "type": "TextBlock",
                "text": "Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation.",
                "wrap": true
            },
            {
                "type": "FactSet",
                "facts": [
                    {
                        "title": "Board:",
                        "value": "Adaptive Card"
                    },
                    {
                        "title": "List:",
                        "value": "Backlog"
                    },
                    {
                        "title": "Assigned to:",
                        "value": "Matt Hidinger"
                    },
                    {
                        "title": "Due date:",
                        "value": "Not set"
                    }
                ]
            }
        ]
    }
],
"actions": [
    {
        "type": "Action.ShowCard",
        "title": "Set due date",
        "card": {
            "type": "AdaptiveCard",
            "body": [
                {
                    "type": "Input.Date",
                    "id": "dueDate"
                }
            ],
            "actions": [
                {
                    "type": "Action.Submit",
                    "title": "OK"
                }
            ]
        }
    },
    {
        "type": "Action.ShowCard",
        "title": "Comment",
        "card": {
            "type": "AdaptiveCard",
            "body": [
                {
                    "type": "Input.Text",
                    "id": "comment",
                    "isMultiline": true,
                    "placeholder": "Enter your comment"
                }
            ],
            "actions": [
                {
                    "type": "Action.Submit",
                    "title": "OK"
                }
            ]
        }
    }
]}

我找不到将卡附加到python响应的方法。

1 个答案:

答案 0 :(得分:2)

您需要为发送给用户的活动创建Attachment

ADAPTIVE_CARD_ATTACHMENT = Attachment(content_type='application/vnd.microsoft.card.adaptive',
                                      content=ADAPTIVE_CARD)

在此之后,您可以将其附加到您的响应活动中,如下所示:

response.attachments = [ADAPTIVE_CARD_ATTACHMENT]

或者您可以在创建响应时添加它:

response = Activity(type='message', attachments=[ADAPTIVE_CARD_ATTACHMENT])

注意:为了简洁起见,我省略了创建有效活动所需的其他代码,您仍需要添加channel_idrecipientfrom_property等字段。< / p>