我已经创建了一个LUIS Template Bot Application (版本3),并且需要捕获Adaptive Card下拉列表的输出。我现在可以创建和渲染下拉列表,但是一旦点击按钮就很难捕捉到结果。你能给我一个解决方案,或者给出版本3的适当教程的链接,因为这个问题的资源主要是版本4的。
public Attachment PolicyAdaptiveCard()
{
var card = new AdaptiveCard();
var choices = new List<AdaptiveChoice>();
choices.Add(new AdaptiveChoice()
{
Title = "Category 1",
Value = "c1"
});
choices.Add(new AdaptiveChoice()
{
Title = "Category 2",
Value = "c2"
});
var choiceSet = new AdaptiveChoiceSetInput()
{
IsMultiSelect = false,
Choices = choices,
Style = AdaptiveChoiceInputStyle.Compact,
Id = "Category"
};
card.Body.Add(choiceSet);
card.Actions.Add(new AdaptiveSubmitAction() { Title = "Select Category", Data = Newtonsoft.Json.Linq.JObject.FromObject(new { button = "select" }) });
Attachment attachment = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = card,
Name = $"Card"
};
return attachment;
}这是我在Bot Emmulator中捕获的JSON输出
{
"channelData": {
"clientActivityID": "15547009411880.yfus2yy2mao",
"postBack": true
},
"channelId": "emulator",
"conversation": {
"id": "3f50f7c1-59be-11e9-98bd-17dcaa70e8d3|livechat"
},
"from": {
"id": "r_tckd4zoa8h",
"name": "User",
"role": "user"
},
"id": "48d27080-59be-11e9-93ff-a77a4eb2d000",
"localTimestamp": "2019-04-08T08:22:21+03:00",
"locale": "en-US",
"recipient": {
"id": "97e06f60-496a-11e9-9541-3d37a55e03cc",
"name": "Bot",
"role": "bot"
},
"serviceUrl": "http://localhost:56373",
"showInInspector": true,
"timestamp": "2019-04-08T05:22:21.192Z",
"type": "message",
"value": {
"Category": "c1",
"button": "select"
}
}如何在下一个方法中读取值并输出"c1“?这是我正在遵循的代码。您能告诉我可以用来捕获类别值的方法吗?
var reply = context.MakeMessage();
var activityValue = context.Activity.AsMessageActivity().Value as Newtonsoft.Json.Linq.JObject;
if (activityValue != null)
{
var categorySelection = activityValue.ToObject<CategorySelection>();
var category = categorySelection.Category;
await context.PostAsync(reply);
}发布于 2019-04-09 01:10:38
对于bot框架v3,你可以这样做作为你的回调函数:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
if (activity.Value != null)
{
dynamic value = activity.Value;
var category = value.Category;
await context.PostAsync(category);
}
context.Wait(MessageReceivedAsync);
}使用动力学可以很容易地访问这些值。只需在发送适配卡的初始提示中将此消息注册为context.Wait上的回调函数即可。
如果你想要一个更有类型的版本,你可以建模你的卡片的结果,并像这样解析它:
private static string GetTypedCategoryFromAdaptiveCard(Activity activity)
{
var content = JsonConvert.DeserializeObject<CategoryResponse>(activity.Value.ToString());
return content.Category;
}
public class CategoryResponse
{
public string Category { get; set; }
}https://stackoverflow.com/questions/55566750
复制相似问题