Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last user input triggering activity events after being processed #6675

Open
thiagocezario opened this issue Oct 22, 2024 · 0 comments
Open

Comments

@thiagocezario
Copy link

Hi all

I have a problem on a project i’m working on at the moment, for security reasons I cannot share detailed information, but it’s a marketing chatbot.
Our project is currently on the SDK 3.1, and we’re having a problem where the last input from the user is triggering events, even though it was already processed earlier.

  1. User says hello and starts the conversation
  2. The bot asks for some information to login/register the user
  3. The user enters said information and proceeds down the flow
  4. The bot asks some extra information
  5. The user enters their answer for that
  6. The bot continues and processes the user input again
  7. After finishing the login/register process, regardless if the user left the conversation hanging for a bit or continued the flow, the bot uses the information from the last step as an input for the current flow. Let’s say the question on step 4 was answered with an YES, and now the user was given a list of options to select, but somehow OnTurnAsync/OnMessageActivityAsync gets triggered and tries to use the YES from the previous question and continue the flow with that, and this can happen in parallel with the user actual answer, so it will have 2 difference messages processed at the same time.

The dialog flow we have is like this:

RootDialog -> BeginDialogAsync(MainDialog) -> BeginDialogAsync(RegistrationDialog) -> BeginDialogAsync(EmailDialog) -> BeginDialogAsync(TextPrompt) -> EndDialogAsync(TextPrompt) -> BeginDialogAsync(LoginValidationDialog) -> BeginDialogAsync(TextPrompt) -> EndDialogAsync(TextPrompt) -> BeginDialogAsync(TextPrompt) -> EndDialogAsync(TextPrompt) -> EndDialogAsync(LoginValidationDialog) -> EndDialogAsync(EmailDialog) -> BeginDialogAsync(UpdateUserDialog) -> EndDialogAsync(UpdateUserDialog) -> BeginDialogAsync(SignInUserDialog) -> EndDialogAsync(SignInUserDialog) -> BeginDialogAsync(LoggedInDialog) …

There are some APIs called in the background at some points in the flow and depending on the results, the user might be asked other questions or not, this example is the “happy” flow.
So far all that was tested and found was:

  • This issue so far does not happen at all on the emulator, only on WhatsApp.
  • This is not exclusive to a specific flow/set of dialogs, it can happen basically at any point
  • This is an intermittent issue, does not happen 100% of the time
  • Our dialogs only references and adds to the Dialog Set the Dialog classes that it can call directly. Ex.: RootDialog has AddDialog(MainDialog) and AddDialog(new WaterfallSteps[]), MainDialog has AddDialog(FirstDialog) and AddDialog(new WaterfallSteps[]) and so on...
  • All Dialog classes have the InitialDialogId set as their own name
  • OnMessageActivityAsync override there’s only a logger call and an await dialog.RunAsync(turnContext, _conversationState.CreateProperty(nameof(DialogState)), cancellationToken)
    • dialog is of type T : Dialog
  • OnTurnAsync override has a few more steps, but it’s simple as well:
    • Gets userState
    • Checks session expiration
    • await base.OnTurnAsync(turnContext, cancellationToken)
    • saves conversation and user state
  • Tried changing BeginDialogAsync for ReplaceDialogAsync
  • Managed to reproduce locally by creating a tunnel from WhatsApp to the project, but after a few iterations I stopped getting the bug
  • Tried adding a Load and Save for the conversation and user state in the ActivityHandler, both on OnMessageActivityAsync and OnTurnAsync
  • During the small time I actually was able to debug I saw that the Message Activity was being passed down and went from Responded True to Responded False;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant