动态创建自适应卡bot框架azure

2024-10-02 16:22:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我在将AdaptiveCardJSON用于python web聊天机器人(BotFrameWork)时遇到了一个问题,我想知道如何自定义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
                    }
                   
                ]
            }
          
        ]
    }
]

}

我必须填写项目中的文本值,我应该如何做


Tags: columnstextjsontruetype动态itemscolumn
1条回答
网友
1楼 · 发布于 2024-10-02 16:22:59

不幸的是,Adaptive Cards SDK没有Python支持,因此您无法直接在bot代码中制作动态卡。但是,您仍然可以使用Adaptive Card Templating,因此您的卡可以是动态的,尽管它仅限于卡中包含的数据

因此,您确实有两种选择:

  1. 从Python更改为.NET或JS,或
  2. 编写卡JSON,在Python中加载,并在将其附加到活动之前在代码中动态编辑它。我在#3 here中讨论过这一点,它在C#中,但同样的概念也适用

相关问题 更多 >