I have a rather larger form in which I want to remove slots several times if other slots get filled with FALSE.
I found two approaches for removing slots. The first one worked fine but I could not find a way to make the same logic several times. So in this example I would not only remove exercise if confirm_exercise is FALSE but also remove goal if stress is FALSE.
from typing import Text, List
from rasa_sdk import Tracker, FormValidationAction
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.types import DomainDict
class ValidateHealthForm(FormValidationAction):
def name(self) -> Text:
return "validate_health_form"
async def required_slots(
self,
slots_mapped_in_domain: List[Text],
dispatcher: "CollectingDispatcher",
tracker: "Tracker",
domain: "DomainDict"
) -> List[Text]:
if tracker.get_slot("confirm_exercise") == True:
return ["confirm_exercise", "exercise", "sleep", "diet", "stress", "goal"]
else:
return ["confirm_exercise", "sleep", "diet", "stress", "goal"]
Thank you for your quick answer! I do not get the error message anymore but unfortunately the slot question_ball_main is not removed. The bot is still asking that question…
Any idea if I need to change something else?
Actually, I solved it by using the append functionality instead of remove while also removing the slots that get appended from the required_slots in the domain.yml. Now it works
I need to delete 1st_reason slot if the 1st_qn slot is rated below 4
and remove 2nd_reason slot if the 2nd_qn slot is rated below 4 likewise for a couple of questions
action.py
class ValidateSurveyForm(FormValidationAction):
def name(self) -> Text:
return "validate_survey_form"
async def required_slots(
self,
domain_slots: List[Text],
dispatcher: "CollectingDispatcher",
tracker: "Tracker",
domain: "DomainDict",
) -> List[Text]:
l = ["3", "2", "1"]
updated_slots = domain_slots.copy()
if tracker.slots.get("1st_qn") not in l:
updated_slots.remove("1st_reason")
return updated_slots
elif tracker.slots.get("2nd_qn") not in l:
updated_slots.remove("2nd_reason")
return updated_slots
elif tracker.slots.get("3rd_qn") not in l:
updated_slots.remove("3rd_reason")
return updated_slots