Hello fellow developers,
Currently, I’m trying to work on a project where my bot needs to ask survey questions received through an API call. The number of questions is dynamic since they are fetched from API. Each of the questions has payloads that need to be shown as options to users.
I’m stumped as I do not see any option for dynamically allocated slots that can be used in a form that can be activated as soon as I get the API call.
I tried looking for list type slot, but I don’t see how it can be used in different questions from the API.
Is there any way we can keep updating this list slot using custom action?
Dynamic Form Behavior is used exactly for that purpose
Hi ChrisRahme, I understand that using dynamic form behaviour we can change required_slots ie, add or remove slots as compared to when defined in the domain file.
The issue is, the survey can have an unknown number of questions, for example, the user_1 survey has 5 questions but for user_2 it has 8 and, for user_3 it needs 3 questions.
Is there any way dynamic form behaviour can handle this?
Hi Nimit, thanks for the reference, but I think this still does not solve my problem. All the slots added into required_slots inside the FormAction do exist in the domain file. What if the bot does not know how many questions the API is going to throw?
Can we define new slots in custom action?
Sure, you can set as many required slots as you want. I implement a way to get the slots from a database, and these slots change according to another slot outside the form, like in your case for users.
But all these slots are needed to be defined in the domain file right? Does that mean there all possible slots are required to be defined in domail.yml, i.e. the maximum questions possible?
That’s right, all the slot names at least should be present in the domain.
As for their mappings and validation, you can write custom code like for the required slots method (you can read about those in the link I sent above)
Okay, thanks Chris, I’ll try this way.
Let me know if you run into any difficulties - or not