Reputation: 477
I'm creating an Order
confirm card where there's an entry for every product and quantity. There's also a button to delete the entry and another button to modify its quantity.
The amount of products displayed will vary based on the amount of Product
objects I've stored in a list. The card is a JSON template without any products that I want to be able to modify through my code (add the product columns, the buttons, their respective actions), etc.
What is the best way to accomplish that without having to build a Deserializer? (I don't want to be deserializing every Container
, FactSet
, etc. into useless objects).
Every Product
row will have a button to delete from the Order
I can achieve that making it inivisble and then deleting the object with a submit action*. But when I change the amount of Products an entry has, how can I update the Product
quantity value without resending the adaptive card?
"selectAction": "Action.toggleVisibility"
and an "type": "Action.Submit"
at the same time?All these buttons will have a set of different submit actions. Let's say something like this:
switch(action)
{
case "delete1":
//Deletes product 1 from the Order
break;
case "delete2":
//Deletes product 2 from the Order
break;
...
}
Should this handler go to some type of Middleware, maybe in the bot class (i suppose this shouldn't go in the MainDialog since mine is a WaterFallDialog
). What is the advisable way of handling those?
Upvotes: 0
Views: 2334
Reputation: 1565
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://learn.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.
Upvotes: 0
Reputation: 7241
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:
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.
OnMessageAsync
.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
Upvotes: 3