我创建了一个Bot Framework项目,并使用LUIS意图和实体来填充AdaptiveCard的字段,然后将其附加到Activity并发布给用户。我已将SubmitAction作为卡片的一部分,相关代码如下:
[LuisIntent("Query GPN")]
public async Task QueryGPN(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
EntityRecommendation GPN;
AdaptiveCard gpnCard = new AdaptiveCard();
gpnCard.Body.Add(new TextBlock()
{
Text = "GPN Lookup Form",
Size = TextSize.Large,
Weight = TextWeight.Bolder
});
gpnCard.Body.Add(new TextBlock()
{
Text = "GPN",
Weight = TextWeight.Bolder
});
TextInput gpnInput = new TextInput()
{
Id = "GPN",
IsMultiline = false
};
gpnCard.Body.Add(gpnInput);
gpnCard.Actions.Add(new SubmitAction()
{
Title = "Submit"
});
if (result.TryFindEntity("GPN", out GPN))
{
await context.PostAsync($"You want to know about a GPN {GPN.Entity}? Prepopulating form.");
gpnInput.Value = GPN.Entity;
}
else
{
await context.PostAsync("It seems like you wanted to know about a GPN, but I couldn't find a GPN in your request.");
}
Attachment gpnCardAttachment = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = gpnCard
};
IMessageActivity gpnFormMessage = context.MakeMessage();
gpnFormMessage.Attachments = new List<Attachment>();
gpnFormMessage.Attachments.Add(gpnCardAttachment);
await context.PostAsync(gpnFormMessage);
context.Done<IMessageActivity>(null);
}
当用户点击“提交”按钮时,我正在尝试检索此表单的内容,这似乎是在我的MessagesController中向Post方法发送消息Activity。但是,此消息活动的内容为null。如何从此消息活动中检索与提交操作关联的有效内容?在上面的示例中,如何检索“GPN”键的值?我已经尝试查看附件,但它似乎并不存在:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
try
{
IMessageActivity message = await result;
if(message.Text == null)
{
await context.PostAsync("Received null message.");
if (message.Attachments != null)
{
await context.PostAsync($"Attachments: {message.Attachments.Count}");
}
else
{
await context.PostAsync($"No attachments.");
}
if(message.ChannelData != null)
{
await context.PostAsync("ChannelData contains something");
}
else
{
await context.PostAsync($"No channel data.");
}
context.Wait(MessageReceivedAsync);
}
else
{
await context.Forward(new IntentDialog(), IntentDialogAfter, message, CancellationToken.None);
}
}
catch (Exception e)
{
await context.PostAsync(e.Message);
}
}