简体   繁体   English

提交不适用于 Azure Bot 发布的团队中的自适应卡

[英]Submit not working for Adaptive Card in Teams posted by Azure Bot

I have an Adaptive Card posted to Teams from an Azure Bot requesting the user to enter values for the fields displayed.我从 Azure Bot 向 Teams 发布了一张自适应卡片,要求用户为显示的字段输入值。 When the user hits the Submit button, nothing happens.当用户点击提交按钮时,什么也没有发生。 Yet in WebChat or Adaptive Card Designer, it works perfectly.然而在 WebChat 或 Adaptive Card Designer 中,它可以完美运行。 I even use to work when I use to post the Adaptive Card from a Logic App to Teams.当我将自适应卡从逻辑应用程序发布到团队时,我什至习惯于工作。

Here's the Adaptive Card:这是自适应卡:

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.0",
    "body": [
        {
            "type": "TextBlock",
            "size": "medium",
            "weight": "bolder",
            "text": "Start VM"
        },
        {
            "type": "TextBlock",
            "text": "Enter the details of the Virtual Machine to restart",
            "wrap": true
        },
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "VM Name",
                            "wrap": true
                        }
                    ]
                },
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "Input.Text",
                            "placeholder": "e.g. servername",
                            "id": "vmName"
                        }
                    ]
                }
            ]
        },
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "VM Resource Group",
                            "wrap": true
                        }
                    ]
                },
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "Input.Text",
                            "placeholder": "e.g. resourcegroup",
                            "id": "vmResourceGroup"
                        }
                    ]
                }
            ]
        },
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "Username",
                            "wrap": true
                        }
                    ]
                },
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "Input.Text",
                            "placeholder": "e.g. joe.bloggs@contoso.com",
                            "id": "username"
                        }
                    ]
                }
            ]
        },
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "ServiceNow SysID for Change Record",
                            "wrap": true
                        }
                    ]
                },
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "Input.Text",
                            "placeholder": "e.g. 11cef313db4ce0d012d9147a3a961909",
                            "id": "sysId"
                        }
                    ]
                }
            ]
        }
    ],
    "actions": [  
        {  
            "type": "Action.Submit",  
            "title": "Submit"
        }  
    ]
}

The C# Code in the Azure Bot the constructs the Adaptive Card is the following: Azure Bot 中的 C# 代码构建自适应卡如下:

private Attachment CreateAdaptiveCardAttachment()
{
    var cardResourcePath = "EchoBot.Cards.startVMCard.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),
            };
        }
    }
}

The Code for the Azure Bot that sends the Adaptive Card is the following:发送自适应卡的 Azure Bot 的代码如下:

var startVMCard = CreateAdaptiveCardAttachment();
var response = MessageFactory.Attachment(startVMCard);
await turnContext.SendActivityAsync(response, cancellationToken);

Thanks in advance!提前致谢!

Firstly thanks for reaching us.首先感谢您联系我们。

I have gone through and tested your adaptive card json and method that you implemented.我已经通过并测试了您的自适应卡 json 和您实施的方法。

Able to get the values in "adaptivecards.io/designer",能够获取“adaptivecards.io/designer”中的值, 在此处输入图像描述

Also, i have tried in Microsoft Teams too, able to get the values in code "turnContext"另外,我也在 Microsoft Teams 中尝试过,能够获取代码“turnContext”中的值在此处输入图像描述

在此处输入图像描述

So, in Submit button action, you have to implement your code to display the values in Bot.因此,在提交按钮操作中,您必须实现代码以在 Bot 中显示值。

Please go through the document , you will get complete knowledge on cards and how to implement the cards.请通过文档go ,您将获得有关卡片的完整知识以及如何实现卡片。

OK - Trying to debug this mystery.好的 - 试图调试这个谜。 In Visual Studio I can view the Streaming log from the Bot in Azure.在 Visual Studio 中,我可以从 Azure 中的 Bot 查看 Streaming 日志。

When testing the Bot via the Bot Framework Emulator connected to the Bot remotely it works perfectly.通过远程连接到 Bot 的 Bot Framework Emulator 测试 Bot 时,它可以完美运行。 I see the following after clicking the submit button in the logs:单击日志中的提交按钮后,我看到以下内容:

Application:2020-12-23 06:41:39.456 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request starting HTTP/1.1 POST https://startvmbot.azurewebsites.net/api/messages application/json 678
Application:2020-12-23 06:41:39.456 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executing endpoint 'StartVMBot.Controllers.BotController.PostAsync (startvmbot)'
Application:2020-12-23 06:41:39.456 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Route matched with {action = "Post", controller = "Bot"}. Executing controller action with signature System.Threading.Tasks.Task PostAsync() on controller StartVMBot.Controllers.BotController (startvmbot).
Application:2020-12-23 06:41:39.456 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Executing action method StartVMBot.Controllers.BotController.PostAsync (startvmbot) - Validation state: Valid
Application:2020-12-23 06:41:39.460 +00:00 [Information] Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: Received an incoming activity.  ActivityId: e920c600-44e9-11eb-aa2c-f5a359761b0e
Application:2020-12-23 06:41:39.657 +00:00 [Information] Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: Sending activity.  ReplyToId: e920c600-44e9-11eb-aa2c-f5a359761b0e
Application:2020-12-23 06:41:39.658 +00:00 [Information] Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: GetTokenAsync: Acquired token using ADAL in 0.
Application:2020-12-23 06:41:40.128 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Executed action method StartVMBot.Controllers.BotController.PostAsync (startvmbot), returned result Microsoft.AspNetCore.Mvc.EmptyResult in 671.7897ms.
Application:2020-12-23 06:41:40.128 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Executed action StartVMBot.Controllers.BotController.PostAsync (startvmbot) in 672.1344ms
Application:2020-12-23 06:41:40.128 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executed endpoint 'StartVMBot.Controllers.BotController.PostAsync (startvmbot)'
Application:2020-12-23 06:41:40.129 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request finished in 673.416ms 200

This is the result in Bot Framework Emulator这是 Bot Framework Emulator 中的结果机器人模拟器

When testing the Bot via Teams it doesn't work.通过 Teams 测试 Bot 时,它不起作用。 I see the following after clicking the submit button in the logs:单击日志中的提交按钮后,我看到以下内容:

Application:2020-12-23 06:39:56.705 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request starting HTTP/1.1 POST https://startvmbot.azurewebsites.net/api/messages application/json; charset=utf-8 1136
Application:2020-12-23 06:39:56.705 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executing endpoint 'StartVMBot.Controllers.BotController.PostAsync (startvmbot)'
Application:2020-12-23 06:39:56.705 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Route matched with {action = "Post", controller = "Bot"}. Executing controller action with signature System.Threading.Tasks.Task PostAsync() on controller StartVMBot.Controllers.BotController (startvmbot).
Application:2020-12-23 06:39:56.705 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Executing action method StartVMBot.Controllers.BotController.PostAsync (startvmbot) - Validation state: Valid
Application:2020-12-23 06:39:56.707 +00:00 [Information] Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter: Received an incoming activity.  ActivityId: f:6238602817490478374
Application:2020-12-23 06:39:56.708 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Executed action method StartVMBot.Controllers.BotController.PostAsync (startvmbot), returned result Microsoft.AspNetCore.Mvc.EmptyResult in 2.2726ms.
Application:2020-12-23 06:39:56.708 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Executed action StartVMBot.Controllers.BotController.PostAsync (startvmbot) in 2.5461ms
Application:2020-12-23 06:39:56.708 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executed endpoint 'StartVMBot.Controllers.BotController.PostAsync (startvmbot)'
Application:2020-12-23 06:39:56.708 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request finished in 3.6941ms 200 

This is the result in Teams:这是 Teams 中的结果: 团队

I'll keep looking, but if anyone has any ideas, I'd appreciate them!我会继续寻找,但如果有人有任何想法,我将不胜感激!

I found the issue.我发现了这个问题。

It appears that Teams is using Skype Framework 3.0 and doesn't have the postBack method.看来 Teams 正在使用 Skype Framework 3.0 并且没有 postBack 方法。 An Adaptive Card submit does not contain postBack in the ChannelData.自适应卡片提交在 ChannelData 中不包含postBack An Adaptive Card submit using the Framework Emulator contains postBack in the ChannelData.使用 Framework Emulator 提交的自适应卡片在 ChannelData 中包含postBack

I added the following code to cater for this issue:我添加了以下代码来解决这个问题:

var channelData = JObject.Parse(turnContext.Activity.ChannelData.ToString());
JObject activity = JObject.Parse(turnContext.Activity.Value.ToString());

if (channelData.ContainsKey("postBack") || activity.HasValues == true)
{
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM