I'm trying to get the result of my AdaptiveCard.
My bot uses waterfalldialogs. In one Waterfallstep i present the user a number of Rooms with the time and date. The user then can choose a room. I tried it like shown below. Sadly the activity
stays null. How do I get the result of the adaptive card
private async Task<DialogTurnResult> AfterChoice(WaterfallStepContext step, CancellationToken cancellationToken)
{
if (step.Result is Activity activity && activity.Value != null && ((dynamic)activity.Value).chosenRoom is JValue chosenRoom)
{
dynamic requestedBooking = JsonConvert.DeserializeObject<ExpandoObject>((string)chosenRoom.Value);
this.roomemail = requestedBooking.roomEmail;
return await step.EndDialogAsync();
}
else
{
return await step.BeginDialogAsync(whatever, cancellationToken: cancellationToken);
}
}
How do I get the users choice?
Adaptive Cards send their Submit results a little different than regular user text. When a user types in the chat and sends a normal message, it ends up in
Context.Activity.Text
. When a user fills out an input on an Adaptive Card, it ends up inContext.Activity.Value
, which is an object where the key names are theid
in your card and the values are the field values in the adaptive card.For example, the json:
.. creates a card that looks like:
If a user enters "Testing Testing 123" in the text box and hits Submit,
Context.Activity
will look something like:The user submission can be seen in
Context.Activity.Value.userText
.Note that adaptive card submissions are sent as a postBack, which means that the submission data doesn't appear in the chat window as part of the conversation--it stays on the Adaptive Card.
Using Adaptive Cards with Waterfall Dialogs
Your question doesn't quite relate to this, but since you may end up attempting this, I thought it might be important to include in my answer.
Natively, Adaptive Cards don't work like prompts. With a prompt, the prompt will display and wait for user input before continuing. But with Adaptive Cards (even if it contains an input box and a submit button), there is no code in an Adaptive Card that will cause a Waterfall Dialog to wait for user input before continuing the dialog.
So, if you're using an Adaptive Card that takes user input, you generally want to handle whatever the user submits outside of the context of a Waterfall Dialog.
That being said, if you want to use an Adaptive Card as part of a Waterfall Dialog, there is a workaround. Basically, you:
In your Waterfall Dialog class (steps 1 and 2):
In your main bot class (
<your-bot>.cs
) (step 3):