Can intercept a message in FormFlow before it reaches recognizers?

160 views Asked by At

We have a bot that will be collecting information and we would like to utilize FormFlow. Using the custom prompter we can customize the outgoing messages, but is there any similar facility to let us intercept incoming messages before they hit the recognizers? The specific use case is based on the user input, we may want to immediately exist out of a flow and redirect to a different dialog.

1

There are 1 answers

0
TheCascadian On

You can use business logic to process user input when using FormFlow, where you can immediately exit out of a form flow and redirect to a different dialog.

Since the validate function cannot pass context, you can store the context in a form variable that is populated when constructed.

public MyFormClass(IDialogContext context)
{
    Context = context;
}
public IDialogContext Context { get; set; }
public int IntegerField { get; set; }

Later, call the validate function for a specific field. Here, you can use the stored context to start a new dialog.

return new FormBuilder<MyFormClass>()
    .Field(nameof(IntegerField),
        validate: async (state, value) =>
        {
            var result = new ValidateResult { IsValid = true };

            if (state.IntegerField > 10)
            {
                await state.Context.Call(new Dialog(), Dialog.ResumeMethod);
                return result;
            }
            else
            {
                return result;
            }
        }
    )
    .Build();

Note:

  • Even though the first return statement will never be reached, it is required to avoid throwing an error.
  • You may need to implement additional steps to properly manage the bot's dialog stack.

Even though the first return statement will never be reached, it is required