FormAction ask for different slots based on user input?

Hi all, hope you’re having a lovely day.

I am facing a slightly intricate problem, but I will explain it as simple as possible:

I have a FormAction used for authentication and takes in multiple credentials from the user.

credential1 and credential2 are mandatory, but then the user has the option to choose credential3 or credential4 as their final credential to authenticate.

These are the credentials the bot should ask for: consumer id (cid) -> this is credential1 pin code -> credential2 ssn code -> credential3 phone number -> credential4

So, cid and pin are mandatory, but only one of ssn and phone number is needed.

Whether the bot asks for the ssn code or the phone number is based on user input after entering the consumer id and pin code.

How do I model this in a form action?

Basically the trouble I’ve been having is changing the list returned by the required_slots() method, based on the user input to choose the ssn code or phone number, half way through the form action.

Alternatively, if there’s a much better and cleaner approach, please let me know.

Many thanks in advance, and happy coding!


Well i think that’s not a bad way to do it.

You can ask the user: “Please choose 1 of these 2 credentials that you wish to provide” and prepare an intent inform_credential with a corresponding credential slot for it. After that i can think 2 of directions:

  1. Manipulate the requested_slots (what you are trying to do):

    In the function requested_slots():

    • Check if the credential slot is ‘ssn code’ or ‘phone number’

    • Return a list of requested slots without the slot which isn’t picked.

  2. Using validate_{slot_name}:

    • You can check what optional credential the user entered in the function validate_credential(). Then if assuming ‘ssn code’ was picked, you assign a value to the ‘phone number’ slot (anything as long as it’s not null) so the bot won’t ask for it.

Thanks for your response @fuih. I decided to do it by defining the final credential(s) needed with a setup script which creates a configuration file read in by

1 Like

A more easy solution for your case is to replace the slots “ssn” and “phonenumber” with a single slot “number” and ask something like 'Write your ssn or phone number" and validate it in the submit method of the form, because the ssn has 9 digits and the cellphone has 10.