我有一个从Azure机器人发布到团队的自适应卡,要求用户为显示的字段输入值。当用户点击Submit按钮时,什么也不会发生。然而,在WebChat或自适应卡设计器中,它可以完美地工作。当我使用逻辑应用程序将自适应卡发布到团队时,我甚至会工作。
这是自适应卡:
{
"$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"
}
]
}
构建自适应卡的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),
};
}
}
}
发送自适应卡的Azure机器人的代码如下:
var startVMCard = CreateAdaptiveCardAttachment();
var response = MessageFactory.Attachment(startVMCard);
await turnContext.SendActivityAsync(response, cancellationToken);
提前感谢!
发布于 2021-01-02 16:08:37
我找到问题了。
看起来团队使用的是Skype Framework3.0,没有postBack方法。自适应卡提交在ChannelData中不包含postBack
。使用框架仿真器的自适应卡提交在ChannelData中包含postBack
。
为了解决这个问题,我添加了以下代码:
var channelData = JObject.Parse(turnContext.Activity.ChannelData.ToString());
JObject activity = JObject.Parse(turnContext.Activity.Value.ToString());
if (channelData.ContainsKey("postBack") || activity.HasValues == true)
{
...
}
发布于 2020-12-07 19:23:22
首先,感谢您联系我们。
我已经检查并测试了您实现的适配卡json和方法。
能够获取"adaptivecards.io/designer“中的值,
此外,我也在微软团队中尝试过,能够获得代码"turnContext“中的值。
因此,在Submit按钮操作中,您必须实现在Bot中显示值的代码。
请通过document,您将获得有关卡的完整知识以及如何实现卡。
发布于 2020-12-23 15:02:14
好的--试着调试这个神秘的东西。在Visual Studio中,我可以在Azure中查看Bot中的流日志。
当通过远程连接到Bot的Bot框架模拟器测试Bot时,它可以完美地工作。单击日志中的submit按钮后,我看到以下内容:
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
这是Bot Framework Emulator中的结果
当通过团队测试机器人时,它不工作。单击日志中的submit按钮后,我看到以下内容:
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
这是团队中的结果:
我会继续寻找,但如果任何人有任何想法,我将不胜感激!
https://stackoverflow.com/questions/65152305
复制相似问题