How to work properly with advanced Adaptive Cards?

后端 未结 2 1004
轮回少年
轮回少年 2020-12-22 06:30

Multiple question

1. Building Adaptive Cards dynamically

I\'m creating an Order confirm card where there\'s an entry for every product and q

相关标签:
2条回答
  • 2020-12-22 06:54

    As a side note to above,was briefly mentioned there but you should really have a look at what Adaptive Cards Templating can do for you.

    https://docs.microsoft.com/en-us/adaptive-cards/templating/

    Templating is in preview and works pretty much like data-binding data on a card template. You do not have to serialize/de-serialize your data or construct any containers, factsets etc.. the library does that for you.

    0 讨论(0)
  • 2020-12-22 06:55

    I've answered each of those questions a few times. I have a feeling you'll run into more, so feel free to search my user for Adaptive Card questions.

    For each of your questions, specifically:

    1. Build Adaptive Cards dynamically
    2. Updating the Adaptive card -- I do this in Teams. Generally speaking, if the channel has an "Edit" button for messages, you only need UpdateActivityAsync() (If you can't "Edit" a message, that channel won't support updating a previously-sent Adaptive Card). Teams just needs some additional steps.
      • Here's another example, in C#
    3. Handle submit actions - This is for Waterfall Dialogs, which is how you should do it. If you want to do it a different way, read the top half of the answer to understand how they work and implement it in OnMessageAsync.

    Other Resources

    • Official Botframework blog post on Adaptive Cards
    • AdaptiveCardPrompt. Auto-handles the Submit action and does a lot of other useful stuff. Might be integrated into the Botframework SDK someday. If you like it, show your support with a thumbs-up in that issue. You can still use the class, yourself, too.
    • Search Kyle Delaney's Adaptive Card answers. He handles a lot of Adaptive Card questions, too.
    • Adaptive Cards Templating - In Preview/Alpha, but allows you to create cards a little more dynamically within the card's JSON.

    Update to answer 2.1

    I believe this is possible. You'd need the Submit action and then also have a Container that contains the ToggleVisibility action (or vice versa). Something like this:

    {
        "type": "AdaptiveCard",
        "version": "1.0",
        "body": [
            {
                "type": "Container",
                "selectAction": {
                    "type": "Action.ToggleVisibility",
                    "targetElements": [
                        "showMe"
                    ]
                },
                "items": [
                    {
                        "type": "TextBlock",
                        "text": "Click me"
                    }
                ]
            },
            {
                "type": "Container",
                "id": "showMe",
                "items": [
                    {
                        "type": "TextBlock",
                        "text": "New TextBlock"
                    }
                ],
                "isVisible": false
            }
        ],
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "selectAction": {
            "type": "Action.Submit",
            "data": "ok"
        }
    }
    

    I haven't tested this in a bot, just played around in the card designer

    0 讨论(0)
提交回复
热议问题