I am using Bot framework V4.3, I want to retrieve adaptive card submit values

前端 未结 1 649
抹茶落季
抹茶落季 2020-12-07 00:02

I\'m using Bot framework V4.3, I have been using adaptive card in waterfall dialog, to get user information, I would want to get values once user clicks submit button and al

相关标签:
1条回答
  • 2020-12-07 00:50

    Dealing with the Re-Prompt

    The issue is with your OnTurnAsync() method:

     if (turnContext.Activity.Type == ActivityTypes.Message)
     {
          await Dialog.Run(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);
     }
    

    Every time a user sends a message, it causes a new instance of your dialog to be run. Since Adaptive Card Input gets sent as a PostBack message (which is still a message), it causes the Dialog to run again, re-prompting the user.

    If you're going to run dialogs from OnTurnAsync() or OnMessageAsync(), there's a couple of different things you should do, either:

    1. Use if/switch statements. For example, if the message contains "help", run the HelpDialog, or

    2. Start a dialog that saves user responses and skips steps as necessary. You can see an example of this in Core Bot's Booking Dialog. Notice how it's saving the user response in each step with something like bookingDetails.TravelDate = (string)stepContext.Result; and checks to see if it exists in the previous step before prompting with something like if (bookingDetails.TravelDate == null). For yours, you might store something like userProfile.AdaptiveCardDetails or something.

    Back Button

    To get the back button working, let's say it looks like this in your Adaptive Card:

    {
        "type": "Action.Submit",
        "title": "Back",
        "data": {
            "goBack": "true",
        }
    },
    

    When the user clicks "Back", the bot will receive an activity with:

    Since the user wants to go back and you don't need the data, you could do something like:

    var activity = turnContext.Activity;
    
    if (string.IsNullOrWhiteSpace(activity.Text) && activity.Value.GetType().GetProperty("goBack"))
    {
        dc.Context.Activity.Text = "Back";
    }
    

    and then in your Dialog step:

    if (stepContext.Result == "Back")
    {
        stepContext.ActiveDialog.State["stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 2;
    }
    
    0 讨论(0)
提交回复
热议问题