matthidinger / ContosoScubaBot

Sample bot built with rich Adaptive Cards
https://contososcubademo.azurewebsites.net
MIT License
40 stars 36 forks source link

use Configuration with JSON cards #7

Closed vovanb closed 6 years ago

vovanb commented 6 years ago

Adaptive card enable create configuration - Configuration editor on http://adaptivecards.io/visualizer/ How I can use it with MS bot?

vovanb commented 6 years ago

any update?

EricDahlvang commented 6 years ago

Hi @vovanb

It's possible to take the .json from the visualizer, include it as a file in the bot, and add it to a return message with the following code:

var path = HostingEnvironment.MapPath($"/Cards/{cardName}.JSON");

using (var f = File.OpenText(path))
{
     string json = await f.ReadToEndAsync();

     var results = AdaptiveCard.FromJson(json);
     var card = results.Card;
     returnMessage.Attachments.Add(new Attachment()
     {
         Content = card,
         ContentType = AdaptiveCard.ContentType,
         Name = "Card"
     }) ;
     return returnMessage;
}

There is no "Export to C#" option for Adaptive Cards though.