Hello,
so I recently work on some kind of accident bot. The bot asks several questions and slots get only filled by the user input. I do some background checks within the validate functions. For example connect to a database and check if the given name is present in the database. Check if street and zip is valid and so on.
The user should be able to break the form at any point he want. I created a intent stop
. If the input gets classified as stop
and the user afirms the question with yes the bot should say goodbye.
There are several questions regarding this feature and it seems this is not as easy as expected. I tried several approaches but nothing worked like expected. There is a form example on Rasa GitHub page. I cloned the restaurant form bot and there it workes perfectly to break the form.
I set up my project like the restaurant form bot but I cant break the form.
So here are some parts of my project:
domain.yml
intents:
- affirm
- deny
- goodbye
- greet
- start_accident_report
- stop
- who_are_you
slots:
name:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: accidentForm
requested_slot: name
forms:
accidentForm:
required_slots:
- name
- <and some other slots>
responses:
utter_greet:
- text: "Hallo, Ich bin der Unfall Bot. Ich helfe dir einen Arbeitsunfall aufzunehmen."
utter_goodbye:
- text: "Auf Wiedersehen"
- text: "Servus"
- text: "Schönen Tag noch"
utter_ask_accidentForm_name:
- text: "Bitte nenne mir den Vor- und Nachnamen der verunfallten Person"
utter_submit:
- text: "Alles erledigt!"
utter_slots_values:
- text:
"Hier ist eine Übersicht der Meldung\n:
- Opfer: {name}
- something else
utter_ask_continue:
- text: "Möchtest du wirklich beenden?"
utter_wrong_name:
- text: "Namen richtig eingeben!"
actions:
- validate_accidentForm
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
rules.yml
version: "3.1"
rules:
- rule: Greet user
steps:
- intent: greet
- action: utter_greet
- rule: activate accident form
steps:
- intent: start_accident_report
- action: accidentForm
- active_loop: accidentForm
- rule: submit accident form
condition:
- active_loop: accidentForm
steps:
- action: accidentForm
- active_loop: null
- action: utter_submit
- action: utter_slots_values
stories.yml
version: "3.1"
stories:
- story: stop form + continue
steps:
- intent: start_accident_report
- action: accidentForm
- active_loop: accidentForm
- intent: stop
- action: utter_ask_continue
- intent: affirm
- action: accidentForm
- active_loop: null
- action: utter_submit
- action: utter_slots_values
- story: stop form + stop
steps:
- intent: start_accident_report
- action: accidentForm
- active_loop: accidentForm
- intent: stop
- action: utter_ask_continue
- intent: deny
- action: action_deactivate_loop
- active_loop: null
- story: interactive_story_1
steps:
- intent: start_accident_report
- action: accidentForm
- active_loop: accidentForm
- slot_was_set:
- requested_slot: name
- intent: stop
- slot_was_set:
- name: beenden
- action: utter_ask_continue
- intent: affirm
- action: action_deactivate_loop
- active_loop: null
- slot_was_set:
- requested_slot: null
Action
class ValidateAccidentForm(FormValidationAction):
def name(self):
return 'validate_accidentForm'
def validate_name(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
if len(value) <= 5: # dummy check
dispatcher.utter_message(response='utter_wrong_name')
return {"name": None}
return {"name": value}
As you see in my stories I tried the interactive learning to learn the bot then to exit the form. Without success. Whats wrong in my project?
Any help I highly appreciate.