使用python将自适应卡添加到bot框架 [英] Adding an adaptive card to bot framework with python

查看:109
本文介绍了使用python将自适应卡添加到bot框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从这里 https://在python中使用bot框架的示例. github.com/Microsoft/botbuilder-python 现在,我想在响应中添加一个简单的自适应卡,我认为它是它说等待context.send_activity(response)的部分,但是我无法附加该卡.我从文档样本中抓取了这张卡:

I am playing a little bit with the samples of the bot framework in python from here https://github.com/Microsoft/botbuilder-python Now I want to add a simple adaptive card to the response which I believe it is the part where it says await context.send_activity(response) but I can not attach the card. I grabbed the card from the docs sample:

{
"$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响应的方法.

I can not find a way to attach the card to the python response.

推荐答案

您需要创建

You need to create the Attachment for the activity that is sent to the user:

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

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

After this, you can attach it to your response activity like this:

response.attachments = [ADAPTIVE_CARD_ATTACHMENT]

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

Or you could add it when you create the response:

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

注意:为了简洁起见,我省略了创建有效活动所需的其他代码,您仍然需要添加诸如channel_idrecipientfrom_property等字段.

Note: I left out the additional code needed to create a valid activity for brevity, you still need to add the fields such as channel_id, recipient and from_property, etc.

这篇关于使用python将自适应卡添加到bot框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆