【问题标题】:Adding an adaptive card to bot framework with python使用 python 向 bot 框架添加自适应卡
【发布时间】:2018-10-31 08:45:09
【问题描述】:

我正在从这里https://github.com/Microsoft/botbuilder-python 使用 python 中的 bot 框架的示例玩一点点 现在我想在响应中添加一个简单的自适应卡,我相信这是它说等待 context.send_activity(response) 但我无法附加卡的部分。我从 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 响应的方法。

【问题讨论】:

    标签: python botframework adaptive-cards


    【解决方案1】:

    您需要为发送给用户的活动创建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等字段。

    【讨论】:

    • 谢谢,这很好用。只是出于好奇,您是否知道任何可能有助于在 python 上开发机器人框架的资源? :D
    • 目前没有使用 v4 botbuilder-python 进行开发的资源;但是您可以在这里提问,或者如果您查看docs/wiki,您将能够找到正在跨语言翻译的概念。这应该至少可以帮助您入门:)
    • 您的附件链接已损坏。
    猜你喜欢
    • 2020-03-21
    • 1970-01-01
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    • 2019-03-31
    • 2019-07-23
    • 1970-01-01
    • 2020-07-30
    相关资源
    最近更新 更多