I have a problem for implementing context switch in rasa forms. Suppose you have a very simple story like this:
## story_sms
* sms
- sms_form
- form{"name": "sms_form"}
- form{"name": null}
- action_reset_contact_slot
In this story, I want to send a text message to someone. For this story, I defined sms_form
and action_reset_contact_slot
actions:
class SmsForm(FormAction):
def name(self) -> Text:
return "sms_form"
@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
return ["contact"]
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
return {
"contact": self.from_entity(entity="contact"),
}
def validate_contact(self, value: Text, dispatcher: CollectingDispatcher,
tracker: Tracker, domain: Dict[Text, Any], ) -> Any:
"""Validate contact value."""
if self.get_entity_value('contact', tracker):
dispatcher.utter_template("utter_sms_slots_values", tracker, contact=value)
return {"contact": value}
else:
dispatcher.utter_template("utter_wrong_contact", tracker)
# validation failed, set slot to None
return {"contact": None}
def submit(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict]:
# utter submit template
dispatcher.utter_template("utter_sms_submit", tracker)
return []
class ResetContactSlot(Action):
def name(self):
return "action_reset_contact_slot"
def run(self, dispatcher, tracker, domain):
return [SlotSet("contact", None)]
I can handle the following conversations with my this definition of SmsForm
:
conversation 1:
* Send a text message to David
* Receiver: David (utter_sms_slots_values)
* Ok! (utter_sms_submit)
conversation 2:
* Send a text message
* To whom? (utter_ask_contact)
* David
* Receiver: David (utter_sms_slots_values)
* Ok! (utter_sms_submit)
In the second conversation, If I don’t enter a valid contact name then utter_wrong_contact
show (based on validate_contact). I want to change this part. What if I want to change the flow of conversation like this:
* Send a text message
* To whom?
* Hello (greet)
* Hi! (utter_greet)
I want to check if the answer to utter_ask_contact
was not a valid contact name then rasa deactivates this form, remove possible slots and answer user message. In this case, I want to get utter_greet
as the response. (I can not handle this case using an unhappy story for each possible intent because I have 42 other intents.)