【问题标题】:Dynamically create adaptive card bot framework azure动态创建自适应卡片机器人框架 azure
【发布时间】:2021-05-01 10:14:43
【问题描述】:

我在 python 网络聊天机器人 (BotFrameWork) 中使用自适应卡片 JSON 时遇到问题,我想知道如何自定义 JSON 元素中的值,这些值是动态的。我解释了更多我必须在一张卡片中列出书籍信息,但标题、作者等......每次都会改变。那么我如何动态填充值呢? 那是我的 json 文件

{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.3",
"body": [
    {
        "type": "ColumnSet",
        "columns": [
            {
                "type": "Column",
                "width": "stretch",
                "items": [
                    {
                        "type": "TextBlock",
                        "text": "RISULTATI",
                        "horizontalAlignment": "center",
                        "spacing": "None",
                        "size": "Large",
                        "color": "Attention",
                        "wrap": true
                    }
                ]
            }
        ]
    },
    {
        "type": "ColumnSet",
        "separator": true,
        "spacing": "Medium",
        "columns": [
            {
                "type": "Column",
                "width": "stretch",
                "items": [
                    {
                        "type": "TextBlock",
                        "text": "Nome Libro e autore",
                        "isSubtle": true,
                        "weight": "Bolder",
                        "wrap": true
                    },
                    {
                        "type": "TextBlock",
                        "text": "Prezzo",
                        "spacing": "Small",
                        "wrap": true
                    },
                    {
                        "type": "TextBlock",
                        "text": "Disponibilità",
                        "spacing": "Small",
                        "wrap": true
                    },
                    {
                        "type": "TextBlock",
                        "text": "Link",
                        "spacing": "Small",
                        "wrap": true
                    }
                ]
            },
            {
                "type": "Column",
                "width": "auto",
                "items": [
                    {
                        "type": "TextBlock",
                        "text": "Genere",
                        "horizontalAlignment": "Right",
                        "isSubtle": true,
                        "weight": "Bolder",
                        "wrap": true
                    }   
                ]
            }
        ]
    },
    {
        "type": "ColumnSet",
        "spacing": "Medium",
        "separator": true,
        "columns": [
            {
                "type": "Column",
                "width": 1,
                "items": [
                    {
                        "type": "TextBlock",
                        "text": "Prezzo",
                        "spacing": "Small",
                        "wrap": true
                    },
                    {
                        "type": "TextBlock",
                        "text": "Disponibilità",
                        "spacing": "Small",
                        "wrap": true
                    },
                    {
                        "type": "TextBlock",
                        "text": "Link",
                        "spacing": "Small",
                        "wrap": true
                    }
                   
                ]
            }
          
        ]
    }
]

}

我必须在项目中填写文本值,我应该怎么做?

【问题讨论】:

    标签: python json azure botframework


    【解决方案1】:

    很遗憾,Adaptive Cards SDK 不支持 Python,因此您无法直接在机器人代码中制作动态卡片。不过,您仍然可以使用Adaptive Card Templating,因此您的卡片可以有些动态,尽管它仅限于您包含在卡片中的数据。

    所以,你真的有两个选择:

    1. 从 Python 更改为 .NET 或 JS,或
    2. 编写您的卡片 JSON,在 Python 中加载它,然后在代码中动态编辑它,然后再将其附加到活动中。我在 #3 here 中稍微介绍了这一点——它在 C# 中,但同样的概念也适用。

    【讨论】:

      猜你喜欢
      • 2017-10-18
      • 2020-03-01
      • 2019-12-02
      • 1970-01-01
      • 2019-08-26
      • 1970-01-01
      • 2020-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多