0
votes

We are dynamically rendering adaptive cards for a MS Teams based BOT. The issue that we are facing is that the card renders fine when on WebChat or on Emulator but catches an exception when invoked from MS Teams.

We have used the documentation for adaptive cards as well as the designer but none of it seems to work. We are now curious if rendering MS Teams needs some special fixes to work. We have tried using "msteams" as an id as per the documentation provided online.

ADAPTIVE CARD CODE

cardRequest.Body.Add(new AdaptiveContainer()
        {
            Items = new List<AdaptiveElement>
            {
            new AdaptiveTextBlock()
            {
                 Text = CatalogSubject,
                 Size = AdaptiveTextSize.Default,
                 Weight = AdaptiveTextWeight.Bolder,
            },
            new AdaptiveColumnSet()
            {
                Columns = new List<AdaptiveColumn>()
                {
                    new AdaptiveColumn()
                    {
                        Items = new List<AdaptiveElement>()
                        {
                            new AdaptiveImage()
                            {
                               Style = AdaptiveImageStyle.Default,
                                 Url =new Uri("https://pleudepooopsdemo02.service-now.com/c4b933e9471211002ee987e8dee49064.iix"),

                                Separator=true,
                                Size =  AdaptiveImageSize.Large,
                            }
                        },
                       Separator =true,
                        Width="auto",
                    },
                    new AdaptiveColumn()
                    {
                        Items = new List<AdaptiveElement>()
                        {
                            new AdaptiveTextBlock()
                            {
                                Text=  subCatdescription,
                                Weight= AdaptiveTextWeight.Default,
                                Separator=true,
                                Size = AdaptiveTextSize.Small,
                                Wrap =true,

                            }

                        },
                        Separator =true,
                        Width="stretch",
                    },

                }

            },
            new AdaptiveFactSet()
            {
               Facts = new List<AdaptiveFact>()
               {
                new AdaptiveFact{Title =  "Price",Value =catalogType.scSubCategoryPrice},
                new AdaptiveFact{Title =  "Quantity",Value ="1"},
                new AdaptiveFact{Title = "Email",Value= serviceNowHelper.ParseEmailId(sc.Context.Activity.From.Id, sc.Context.Activity.Conversation.Id, sc.Context.Activity.ServiceUrl, sc.Context.Activity.ChannelId) },
                new AdaptiveFact{Title = "sysid",Value=catalogType1.scSubcategorySysid},
                new AdaptiveFact{Title="PassingValue",Value=catalogType.scSubCategoryName.Substring(catalogType.scSubCategoryName.IndexOf('.') + 1)}

               }
            },

            }


        });
        var button = new CardAction()
        {
            Type = "Action.Submit",
            Title="Create Request",
            DisplayText="I clicked this button",
            Value="{\"Create\": \"" + catalogType.scSubCategoryName.Substring(catalogType.scSubCategoryName.IndexOf('.') + 1) + "\"}"


        };

        AdaptiveAction actions =
                new AdaptiveSubmitAction()
                {
                    Title = "Create Request",
                    Type = "Action.Submit",                      
                    Data = "{\"Create\": \"" + catalogType.scSubCategoryName.Substring(catalogType.scSubCategoryName.IndexOf('.') + 1) + "\"}",



            Id = "create",

                };

        AdaptiveAction actions1 =
               new AdaptiveSubmitAction()
               {
                   Title = "Cancel Request",
                   Type = "Action.Submit",                      
                   Data = "Cancel",
                   Id = "cancel"

               };



        cardRequest.Actions.Add(actions);
        cardRequest.Actions.Add(actions1);

        Object displayCardJson = JsonConvert.DeserializeObject(cardRequest.ToJson());

        List<Attachment> attachmentsList = new List<Attachment>();


        Attachment att = new Attachment()
        {
            Content = displayCardJson,
            ContentType = AdaptiveCard.ContentType

        };

        reply.Attachments.Add(att);                  
        return reply;

ERROR MESSAGE IN COSMOSDB

        {
"User": {
    "id": "29:1j50LiW4dYQyZQ6T44RruVxuaBfatlBHX0YuD7Hly8pNNAiQuWgcoD5jRGHLphLgokeJ6N6b7O7GODLy2QU3G_A",
    "name": "Mary OfEngland",
    "aadObjectId": "98a69ea5-8d65-4264-9d5c-2f12171258a2",
    "role": "user"
},
"Exception": "Cannot perform runtime binding on a null reference",
"StackTrace": "   at CallSite.Target(Closure , CallSite , Object )\r\n   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)\r\n   at FepdePleu.PA.Chatbot.PoC.Dialogs.TicketOpen.GenericRequest.GenericRequestDialog.<>c__DisplayClass40_0.<CreateRequestTicket>b__0(scCatalogCategoryListDetails a) in C:\\Mary\\BotProject\\FepdePleuBOT\\FepdePleu.PA.Chatbot.PoC\\FepdePleu.PA.Chatbot.PoC\\Dialogs\\TicketOpen\\GenericRequest\\GenericRequestDialog.cs:line 355\r\n   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()\r\n   at System.Linq.Enumerable.DistinctIterator`1.MoveNext()\r\n   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)\r\n   at FepdePleu.PA.Chatbot.PoC.Dialogs.TicketOpen.GenericRequest.GenericRequestDialog.CreateRequestTicket(WaterfallStepContext sc, CancellationToken cancellationToken) in C:\\Mary\\BotProject\\FepdePleuBOT\\FepdePleu.PA.Chatbot.PoC\\FepdePleu.PA.Chatbot.PoC\\Dialogs\\TicketOpen\\GenericRequest\\GenericRequestDialog.cs:line 355\r\n   at Microsoft.Bot.Builder.Dialogs.WaterfallDialog.OnStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.Dialogs.WaterfallDialog.RunStepAsync(DialogContext dc, Int32 index, DialogReason reason, Object result, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.Dialogs.WaterfallDialog.ResumeDialogAsync(DialogContext dc, DialogReason reason, Object result, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.Dialogs.DialogContext.EndDialogAsync(Object result, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.Dialogs.Prompt`1.ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken)\r\n   at FepdePleu.PA.Chatbot.PoC.InterruptableDialog.OnContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken) in C:\\Mary\\BotProject\\FepdePleuBOT\\FepdePleu.PA.Chatbot.PoC\\FepdePleu.PA.Chatbot.PoC\\Dialogs\\Shared\\InterruptableDialog.cs:line 39\r\n   at Microsoft.Bot.Builder.Dialogs.ComponentDialog.ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken)\r\n   at FepdePleu.PA.Chatbot.PoC.RouterDialog.OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken) in C:\\Mary\\BotProject\\FepdePleuBOT\\FepdePleu.PA.Chatbot.PoC\\FepdePleu.PA.Chatbot.PoC\\Dialogs\\Shared\\RouterDialog.cs:line 29\r\n   at Microsoft.Bot.Builder.Dialogs.ComponentDialog.ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken)\r\n   at FepdePleu.PA.Chatbot.PoC.ChatbotPoC.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken) in C:\\Mary\\BotProject\\FepdePleuBOT\\FepdePleu.PA.Chatbot.PoC\\FepdePleu.PA.Chatbot.PoC\\ChatbotPoC.cs:line 95\r\n   at Microsoft.Bot.Builder.AutoSaveStateMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.TranscriptLoggerMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate nextTurn, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)",
"date": "2019-10-21T11:03:56.4735109+00:00",
"id": "360c5e3a-98ee-47a6-96c7-c2d135cc6dcd",
"_rid": "V8ZNAMmmWUa-BgAAAAAAAA==",
"_self": "dbs/V8ZNAA==/colls/V8ZNAMmmWUY=/docs/V8ZNAMmmWUa-BgAAAAAAAA==/",
"_etag": "\"05006368-0000-0300-0000-5dad909c0000\"",
"_attachments": "attachments/",
"_ts": 1571655836

}

1
Could you please check the data is coming or not? It seems data is nullTrinetra-MSFT
Yes, it is coming for WebChat and for the Emulator but not for MS Teams. We dont understand why it would happen that way. In fact, we have hard-coded the same email address on emulator, it returns the data. Any insights would be helpfulSash Sheen
Could you please check the delegated and application permissions?Trinetra-MSFT
@SashSheen Can you update your question with the contents of displayCardJson (you'll need a breakpoint or Console.Write())?mdrichardson
Added referenceSash Sheen

1 Answers

1
votes

This solved the issue for us . Found under Github issues for adaptive cards.

This is related to a bug in the AdaptiveCards package: microsoft/AdaptiveCards#2148 Try constructing your attachment like this:

Attachment attachment = new Attachment() {  ContentType = AdaptiveCard.ContentType,     Content = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(card)), };