Hello,
I have a form with questions to ask depending on the user’s answers.
Let’s say the answer to req1 is yes, if the question for slt_opt1 hasn’t been asked it will add it to the array additional_slots and it will get asked next.
The validation for the required slot slt_req1 is working, however it doesn’t work for the additional slots.
Any idea why, and how to fix this ?
Thank you.
code
domain.yml
forms:
myForm:
required_slots:
- slt_req1
# - slt_opt1 only if int_slt_req1_yes
actions.py
class ValidateNameForm(FormValidationAction):
def name(self) -> Text:
return "validate_myForm"
async def required_slots(
self,
domain_slots: List[Text],
dispatcher: "CollectingDispatcher",
tracker: "Tracker",
domain: "DomainDict",
) -> List[Text]:
additional_slots = []
if tracker.slots.get("slt_req1") == "/int_slt_req1_yes":
if tracker.slots.get("slt_opt1") is None:
additional_slots.append("slt_opt1")
return additional_slots + domain_slots
def validate_slt_req1(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate 'slt_req1' value."""
# If the name is super short, it might be wrong.
if (len(slot_value) < 10):
dispatcher.utter_message(text="Answer should be at least 10 characters")
return {"slt_req1": None}
return {"slt_req1": slot_value }
def validate_slt_opt1(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate 'slt_opt1' value."""
if not slot_value:
# If slot_value is empty
return {"slt_opt1": None}
if ((slot_value.isdigit()) == False):
dispatcher.utter_message(text="Entered value has to be an Integer" )
return {"slt_opt1": None}
return {"slt_opt1": slot_value }