0

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()}"),
            };
        }
    }
  • You've said "I'm not being able to do so" but that doesn't explain what you're having difficulty with. Could you let us know the desired behavior and the actual behavior of the code you posted, and also provide the Adaptive Card JSON and LG? – Kyle Delaney Jul 01 '20 at 19:27
  • Does this answer your question? [Bot Framework Maintaining User State](https://stackoverflow.com/questions/49079751/bot-framework-maintaining-user-state) –  Jul 02 '20 at 02:26
  • I have added some edits into the main post. I believe that now it is clear to understand what I have tried and what I'm failling to achieve. And ansewring @MickyD, I have read this post but is doesn't seems to be what I'm looking for. Appreciate you help. – IgorLima1740 Jul 02 '20 at 11:04
  • @IgorLima1740 - Thanks for the edits but you still haven't shown us your Adaptive Card so we don't know what information you're trying to retrieve and how it will be formatted when it gets sent to the bot. Is there a reason you haven't shared that? In any case, you should be able to start any dialog from an adaptive dialog using a BeginDialog step. (Since there are multiple people in this thread, you will need to @ mention me if you want me to see your reply.) – Kyle Delaney Jul 07 '20 at 23:12
  • @IgorLima1740 - Are you still working on this? – Kyle Delaney Jul 14 '20 at 23:58

0 Answers0