I have created a Bot Framework project and am using LUIS intents and entities to populate the fields of an AdaptiveCard, which then gets attached to an Activity and posted to the user. I've placed a SubmitAction as part of the card, and the relevant code is as follows:
[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);
}
I'm trying to retrieve the contents of this form when the user clicks on the Submit button, which seems to send a message Activity to the Post method in my MessagesController. However, the contents of this message activity is null. How do I retrieve the payload associated with the submit action from this message activity? In the example above, how would I retrieve the value for the "GPN" key? I've tried looking in the attachments but it doesn't seem to be there as well:
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);
}
}