Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Cards with different schema's #14

Open
dazinator opened this issue Jun 17, 2020 · 0 comments
Open

Question: Cards with different schema's #14

dazinator opened this issue Jun 17, 2020 · 0 comments

Comments

@dazinator
Copy link

dazinator commented Jun 17, 2020

I have an API on the backend that returns a collection of "Notifications".
Each Notification has some common properties like "NotificationId" etc etc. However it also has some Data associated with it which is some JSON. The schema of that JSON data depends upon the notification type.

For example here are 3 notifications, the first two are "Alert" and the third is a "Message" notification:

[
   {
    "NotificationId": 1
    "Type": "Alert",
    "Data": "{\"severity\":\"warning\"}"
   },
   {
    "NotificationId": 2
    "Type": "Alert",
    "Data": "{\"severity\":\"error\"}"
   },
  {
    "NotificationId": 3
    "Type": "Message",
    "Data": "{\"content\":\"hi there\"}"
   },
]

Is it possible for me to render these "Notifications" as a Card Collection, whilst also rendering the "Data" - which is JSON, in the template?

The nearest example I can find is this: https://www.adaptivecardsblazor.com/cards/templateselector.html

The issue though with the above example, is that there seems to be one schema for the card collection as a whole, where as for my case, I would need to vary the schema for each individual item based on its notification type. For example Id like to display a card list for the above notifications that resembles something like this:

  • Card 1 = Alert: "Warning"
  • Card 2 = Alert: "Error"
  • Card 3 = Message: "Hi There"

Also my "Notification" objects all have a Data property but that is just a JSON string. It seems I'd need to turn that into a C# object instance in order to be able to use it in an adaptive card template is that correct?

Perhaps this is possible by somehow nesting adaptive cards? So I'd have an outer card for the "Notification" which always renders the same, but then it conditionally renders another Adaptvie Card inside itself, based on it's "notification type" to pick the schema / template used - and passing its JSON "Data" as a C# object instance to that sub-card. Do you think an approach like that could work?

Many Thanks

P.S I only recently stumbled accross adaptive cards and am investigating whether I can switch to it. Right now, I use scriban on the backend to generate the HTML for each notification and it's JSON data, and the resulting HTML is delivered to the browser and displayed within each card as Raw html, meaning there is no templating to do on the client. This approach has its downsides however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant