The idea here is pretty simple. I have written a code to display an adaptive card (with the command - new SendActivity("${AdaptiveCard()}")) asking for user's name and email. After the user submit those inputs I just want to retrieve those for future implementations, but I'm not being able to do so.
I have found several implementations of this using Waterfall dialog, but none using adaptive dialogs.
Here, it can be found a stack overflow post How to retrieve user entered input in adaptive card to the c# code and how to call next intent on submit button click - about How to retrieve user entered input in adaptive card to the c# code and how to call next intent on submit button click. However, if you check the anwser the user says it is for Waterfall Dialogs, perhaps the code is alike, but I wasn't able to convert it to Adaptive Dialogs implementation.
There is another reference, that may be useful. https://blog.botframework.com/2019/07/02/using-adaptive-cards-with-the-microsoft-bot-framework/. Although this tutorial shows how to implement adaptive cards using waterfall dialog, the code might look similar. More specifically, the implementation in this tutorial to retrieve user input, can be seen below. It is crucial to note that this implementation uses turnContext.Activity.Text to access user response from the Adaptive Card, however how can I access such a variable turnContext in Adaptive Dialogs?
var txt = turnContext.Activity.Text;
dynamic val = turnContext.Activity.Value;
// Check if the activity came from a submit action
if (string.IsNullOrEmpty(txt) && val != null)
{
// Retrieve the data from the id_number field
var num = double.Parse(val.id_number);
// . . .
}
Here, we can see the code for my RootDialog class from Adaptive Dialog implementation. Where in my code can I retrieve the user information as in the example above?
public class RootDialog : ComponentDialog
{
private readonly IConfiguration configuration;
public RootDialog(IConfiguration configuration)
: base(nameof(RootDialog))
{
this.configuration = configuration;
string[] paths = { ".", "Dialogs", $"{nameof(RootDialog)}.lg" };
string fullPath = Path.Combine(paths);
// Create instance of adaptive dialog.
var rootDialog = new AdaptiveDialog(nameof(AdaptiveDialog))
{
// These steps are executed when this Adaptive Dialog begins
Triggers = new List<OnCondition>()
{
// Add a rule to welcome user
new OnConversationUpdateActivity()
{
Actions = WelcomeUserSteps()
},
// Respond to user on message activity
new OnUnknownIntent()
{
Actions = OnBeginDialogSteps()
}
},
Generator = new TemplateEngineLanguageGenerator(Templates.ParseFile(fullPath))
};
// Add named dialogs to the DialogSet. These names are saved in the dialog state.
AddDialog(rootDialog);
// The initial child Dialog to run.
InitialDialogId = nameof(AdaptiveDialog);
}
private static List<Dialog> WelcomeUserSteps()
{
return new List<Dialog>()
{
// Iterate through membersAdded list and greet user added to the conversation.
new Foreach()
{
ItemsProperty = "turn.activity.membersAdded",
Actions = new List<Dialog>()
{
// Note: Some channels send two conversation update events - one for the Bot added to the conversation and another for user.
// Filter cases where the bot itself is the recipient of the message.
new IfCondition()
{
Condition = "$foreach.value.name != turn.activity.recipient.name",
Actions = new List<Dialog>()
{
new SendActivity("Hi there, I'm here to help you!")
}
}
}
}
};
}
private static List<Dialog> OnBeginDialogSteps()
{
return new List<Dialog>()
{
new SendActivity("${AdaptiveCard()}"),
};
}
}