Добавление адаптивной карты в бот-фреймворк с помощью Python

Я немного поиграю с примерами бот-фреймворка на python отсюда https://github.com/Microsoft/botbuilder-python Теперь я хочу добавить к ответу простую адаптивную карточку, которая, как мне кажется, является той частью, где написано await context.send_activity (response), но я не могу прикрепить карточку. Я взял карточку из образца документации:

{
"$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"
                }
            ]
        }
    }
]}

Не могу найти способ привязать карту к ответу питона.


person Alejandro Peña    schedule 21.05.2018    source источник


Ответы (1)


Вам необходимо создать Attachment < / a> для действия, отправляемого пользователю:

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_id, recipient и from_property и т. Д.

person Steven G.    schedule 21.05.2018