Botframework-webchat: Adaptive Card render error: Invalid or missing card type. Make sure the card's type property is set to \"AdaptiveCard\"

Created on 17 Dec 2019  路  1Comment  路  Source: microsoft/BotFramework-WebChat

Hi team,

We want to implement stars rating feedback for our bot service, and I am using the emulator to debug AdaptiveCard message but got a rendering issue:

image

Emulator version: 4.7.0
AdaptiveCard JSON: Card Json

Reference: https://stackoverflow.com/questions/53943396/in-microsoft-bot-framework-how-to-include-a-star-rating-feedback @tdurnford

my code:
`

public static Attachment GetSurveyCard(Activity activity)
 {
    string cardText = GetAdaptiveCardJson();            
     var card = AdaptiveCard.FromJson(cardText);
     Attachment attachment = new Attachment
     {
         ContentType = AdaptiveCard.ContentType,
         Content = card
     };
     return attachment;
 }

public static async Task ReplyToActivityAsync(Activity activity, string message)
{
    try
    {
        if (activity != null && !string.IsNullOrEmpty(message))
        {
                var replyActivity = activity.CreateReply(message);
                replyActivity.AttachmentLayout = AttachmentLayoutTypes.List;
                replyActivity.Attachments.Add(GetSurveyCard(activity));

                MicrosoftAppCredentials.TrustServiceUrl(ServiceURL);
                var connector = CreateConnectorClient(ServiceURL);
                await connector.Conversations.ReplyToActivityAsync(replyActivity);

          }
          else
          {

          }
        }
        catch (Exception ex)
        {               
            throw new ArgumentException(ex.Message);
        }

    }

   private static string GetAdaptiveCardJson()
    {
        string jsonString = string.Empty;
        using (StreamReader reader = new StreamReader($@".\SurveyStar.json"))
        {
            jsonString = reader.ReadToEnd();
        }
        return jsonString;
    }

`

I checked the JSON and can find the specific type for AdaptiveCard, I don't get the root cause, could you help me?

Bot Services Support customer-reported

Most helpful comment

WOW! I fixed this issue, it caused by the type for Attachment.Content, it should be AdaptiveCard.FromJson(cardText).Card instead AdaptiveCard.FromJson(cardText)

AdaptiveCard.FromJson return a type AdaptiveCardParseResult, this type has a property AdaptiveCard named Card.

image

Hope this can help other people.

>All comments

WOW! I fixed this issue, it caused by the type for Attachment.Content, it should be AdaptiveCard.FromJson(cardText).Card instead AdaptiveCard.FromJson(cardText)

AdaptiveCard.FromJson return a type AdaptiveCardParseResult, this type has a property AdaptiveCard named Card.

image

Hope this can help other people.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mmalaiarasan-conga picture mmalaiarasan-conga  路  3Comments

compulim picture compulim  路  3Comments

vikramdadwal picture vikramdadwal  路  3Comments

AndreMantas picture AndreMantas  路  4Comments

compulim picture compulim  路  3Comments