Back to the question before if the user were wrong

@erohmensing Hi,

Here is an example of my code. In a FormAction, I would like for the user to be able to correct his answer and go back to the former question. For example, the bot will ask for the name (“nom”) and the user will write it. The bot will then ask for the surname. At that moment, if the user write “retour”, the bot should ask again for the name (and put the right value in the slot).

action.py

Class CreateForm(FormAction): “”“Example of a custom form action”""

def name(self):
    # type: () -> Text
    """Unique identifier of the form"""

    return "formulaire"

@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
    """A list of required slots that the form has to fill"""

    return ["nom","surname","rest", "date"]

def slot_mappings(self):
    # type: () -> Dict[Text: Union[Dict, List[Dict]]]
    """A dictionary to map required slots to
        - an extracted entity
        - intent: value pairs
        - a whole message
        or a list of them, where a first match will be picked"""

    return {"nom": self.from_text(), "surname": self.from_text(), 
            "rest": self.from_text(), "date": self.from_text()}

def validate(self,
             dispatcher: CollectingDispatcher,
             tracker: Tracker,
             domain: Dict[Text, Any]) -> List[Dict]:
    """Validate extracted requested slot
        else reject the execution of the form action
    """
    # extract other slots that were not requested
    # but set by corresponding entity
    slot_values = self.extract_other_slots(dispatcher, tracker, domain)

    # extract requested slot
    slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
    if slot_to_fill:
        slot_values.update(self.extract_requested_slot(dispatcher,
                                                       tracker, domain))
        if not slot_values:
            # reject form action execution
            # if some slot was requested but nothing was extracted
            # it will allow other policies to predict another action
            raise ActionExecutionRejection(self.name(),
                                           "Failed to validate slot {0} "
                                           "with action {1}"
                                           "".format(slot_to_fill,
                                                     self.name()))

    # we'll check when validation failed in order
    # to add appropriate utterances
    for slot, value in slot_values.items():
       
            
        msg = tracker.latest_message.get('text')   
        if msg=="retour":
            return [FollowupAction("action_back")]
        
    # validation succeed, set the slots values to the extracted values
    return [SlotSet(slot, value) for slot, value in slot_values.items()]

def submit(self,
           dispatcher: CollectingDispatcher,
           tracker: Tracker,
           domain: Dict[Text, Any]) -> List[Dict]:
    """Define what the form has to do
        after all required slots are filled"""
    return []

actions.yml

  • utter_ask_nom
  • utter_ask_surname
  • utter_ask_rest
  • utter_ask_date
  • action_booking
  • utter_booking

forms.yml

  • formulaire

intents.yml

  • booking

entities.yml

  • nom
  • surname
  • rest
  • date

slots.yml

nom: type: text surname: type: text rest: type: text date: type: text


utter_ask_nom:

  • text: “What is your name?”

utter_ask_surname:

  • text: “What is your surname?”

utter_ask_rest:

  • text: “Which restaurant?”

utter_ask_date:

  • text: “Which date?”

utter_booking:

  • text: “The restaurant is booked.”

stories.md

story 1

  • booking
  • formulaire
  • form{“name”:“formulaire”}
  • slot{“nom”:“None”, “surname”:“None”, “rest”:“None”, “date”: “None”}
  • form{“name”:null}
  • utter_booking
  • action_restart

@JulianGerhard thank you i’ll check your solution.