Adaptive card rendering in bot framework SDK v4 using visual c#

568 Views Asked by At

Hi I have developed a chatbot using core bot template in bot framework SDK v4 and I have published it in my azure portal, and Im able to open it in webchat. I am trying to add styles to my adaptive card and I have checked Link , but I am not able to figure out how to render my card and set up the hostconfig.json to it.

this is my bot.cs file

  '''


  using Microsoft.Bot.Builder;
  using Microsoft.Bot.Builder.Dialogs;
  using Microsoft.Bot.Schema;
  using Microsoft.Extensions.Logging;
  using Newtonsoft.Json;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Threading;
  using System.Threading.Tasks;

   namespace asign.Bots
  {
   public class DialogAndWelcomeBot<T> : DialogBot<T>
     where T : Dialog
  {
      public DialogAndWelcomeBot(ConversationState conversationState, UserState 
    userState, T dialog, ILogger<DialogBot<T>> logger)
         : base(conversationState, userState, dialog, logger)
     {
     }

     protected override async Task OnMembersAddedAsync(IList<ChannelAccount> 
   membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, 
  CancellationToken 
cancellationToken)
    {
        foreach (var member in membersAdded)
        {
            // Greet anyone that was not the target (recipient) of this message.
            // To learn more about Adaptive Cards, see https://aka.ms/msbot- 
   adaptivecards for more details.
            if (member.Id != turnContext.Activity.Recipient.Id)
            {
                var welcomeCard = CreateAdaptiveCardAttachment();
                var response = MessageFactory.Attachment(welcomeCard, ssml: "Welcome 
   to Bot Framework!");
                await turnContext.SendActivityAsync(response, cancellationToken);
                await Dialog.RunAsync(turnContext, 
   ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);
            }
        }
    }

    // Load attachment from embedded resource.
    private Attachment CreateAdaptiveCardAttachment()
    {
        var cardResourcePath = 
   GetType().Assembly.GetManifestResourceNames().First(name => 
   name.EndsWith("welcomeCard.json"));

        using (var stream = 
  GetType().Assembly.GetManifestResourceStream(cardResourcePath))
        {
            using (var reader = new StreamReader(stream))
            {
                var adaptiveCard = reader.ReadToEnd();
                return new Attachment()
                {
                    ContentType = "application/vnd.microsoft.card.adaptive",
                    Content = JsonConvert.DeserializeObject(adaptiveCard),
                };
            }
        }
      }
    }
  }

   '''

Please help me understand how to add a rendering method to above code and setup hostconfig. I would really appriciate the solution.
0

There are 0 best solutions below