Custom actions in Forms

Hi, I have created a form and it fills in slots as it should when it correctly recognizes the entity but throws an error when the bot is unable to extract the location entity. What I want to do then is ask the location again inside the form and extract the complete text string because I am assuming that the user will respond with the location only.

The domain file is:

intents:

  • emergency: use_entities:
  • greet
  • inform
  • thankyou
  • goodbye
  • chitchat

entities:

  • etype
  • people
  • location

slots: etype: type: unfeaturized auto_fill: false people: type: unfeaturized auto_fill: false location: type: unfeaturized auto_fill: false

responses: utter_ask_etype: - text: “ہادثہ کی نوعیت کیا ہے” utter_ask_people: - text: “کتنے افراد متاثر ہیں” utter_ask_location: - text: “کہاں ہادثہ پیش آیا ہے”

I need to know where I can add code so that after utter_ask_location, I can check if the location slot was filled correctly and if not, utter another template and fill the location with the subsequent response from the user.

You can add a validate_location method in the form class, with something like this:

    def validate_location(self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> Dict[Text, Any]:

        # put your tests here

        # if value is not valid, return this:
        return {"location": None}

        # if value is valid, return this:
        return {"location": value}

If the location slot is still empty, Rasa will perform the utter_ask_location again.