Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

python - Dynamically create adaptive card bot framework azure

i have a problem using adaptive card JSON into python web chat bot (BotFrameWork), i want to know how to customize values in the JSON element, these values are dynamic. I explain more i have to do a list of books information in one card, but title,author,etc... changes everytime. So how i can fill values dynamically? That's my json file

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

}

I have to fill the text values in items, how i should do this?

question from:https://stackoverflow.com/questions/65921505/dynamically-create-adaptive-card-bot-framework-azure

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Adaptive Cards SDK doesn't have Python support, unfortunately, so you won't be able to make dynamic cards directly in your bot code. However, you can still use Adaptive Card Templating, so your cards can be somewhat dynamic, although it's limited to the data you include in the card.

So, you really have two options:

  1. Change from Python to .NET or JS, or
  2. Write your card JSON, load it in Python, and edit it dynamically in your code before attaching it to an activity. I go over that a bit in #3, here--it's in C#, but the same concept applies.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...