MS团队提供的动态自适应卡

时间:2019-10-21 16:14:14

标签: botframework microsoft-teams adaptive-cards

我们正在为基于MS Teams的BOT动态呈现自适应卡。我们面临的问题是,该卡在WebChat或Emulator上呈现良好,但在从MS Teams调用时捕获异常。

我们已经使用了自适应卡的文档以及设计人员的文档,但是似乎都不起作用。现在,我们很好奇渲染MS团队是否需要一些特殊的修复才能工作。根据在线提供的文档,我们尝试使用“ msteams”作为id。

自适应卡代码

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;

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 个答案:

答案 0 :(得分:1)

这为我们解决了这个问题。在Github的自适应卡问题中找到。

  

这与AdaptiveCard中的错误有关   包:microsoft / AdaptiveCards#2148尝试构建附件   像这样:

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