Exiting rasa form when user wants

Hi, I have an appointment form and this form gathers a lot of user’s information. If the user enters this form by mistake, I want it to exit at any time by typing cancel. In the end form is approved by the user if user approves the data in the form is registered in the database, but since there is too much data, it is very unreasonable for the person to enter entries until the very end for cancellation.

The code in action.py:

class GatherFormData(FormAction):
    def name(self) -> Text:
        return "form"

    @staticmethod
    def required_slots(tracker: "Tracker") -> List[Text]:
        return ["name", "number", "email", "date", "time", "notes"]

    def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:

        return {
            "name":[self.from_text()], 
            "number":[self.from_text()], 
            "email":[self.from_text()], 
            "date":[self.from_text()], 
            "time":[self.from_text()], 
            "notes":[self.from_text()]
            }

class SaveForm(Action):
    def name(self) -> Text:
        return "save_form"

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]:
        insert_data(tracker.get_slot("name"),
        tracker.get_slot("number"),
        tracker.get_slot("email"),
        tracker.get_slot("date"),
        tracker.get_slot("time"),
        tracker.get_slot("notes"))
        dispatcher.utter_message(text="Information registered.")

class ResetForm(Action):

    def name(self) -> Text:
        return "reset_form"

    async def run(self, dispatcher: "CollectingDispatcher", tracker: "Tracker", domain: "DomainDict") -> List[EventType]:
            return [SlotSet('isim', None), SlotSet('number', None), SlotSet('email', None), SlotSet('date', None), SlotSet('time', None), SlotSet('randevu_not', None)]

rules.yml file:

- rule: Activate form
  steps:
  - intent: get_appointment
  - action: form
  - active_loop: form

- rule: Add form to database
  condition: # Condition that form is active
  - active_loop: form
  steps:
  - action: form
  - active_loop: null # Stop the form
  - slot_was_set:
    - requested_slot: null
  - intent: approved
  - action: save_form

- rule: Cancel the form
  condition: # Condition that form is active
  - active_loop: form
  steps:
  - active_loop: null # Stop the form
  - slot_was_set:
    - requested_slot: null
  - intent: reddet
  - action: utter_form_iptal
  - action: formu_sıfırla

The financial demo has some similar examples here. These examples show switching from one form to another when you’re in the middle of a form. In your case, you would write a story that exits with form on a cancel intent.

@emel-kayaci image
you can use not_intent while defining slots. So whenever the stop intent is trigerred slot will not be filled And then you can add a rule to cancel the form using the stop intent. image