I have defined FormAction to retrieve two slots. In this case, slot name and the entity name are different and this is not calling the validate_slot_name function where I have handled the entity. Below is the FormAction code.
class PriceRelatedInfoForm(FormAction):
def name(self):
return "price_related_info_form"
@staticmethod
def required_slots(tracker):
return ["p_test_name", "p_location"]
def slot_mapping(self):
return {
"p_test_name": [self.from_entity(entity="test_name")],
"p_location": [self.from_entity(entity="location"),
self.from_entity(entity="GPE"),
self.from_entity(entity="LOC")]
}
def validate_p_test_name(self, value, dispatcher, tracker, domain):
print("entity", tracker.get_latest_entity_values("test_name"))
if any(tracker.get_latest_entity_values("test_name")) or any(tracker.get_latest_entity_values("p_test_name")):
return {"p_test_name": value}
else:
dispatcher.utter_message(" Hmm, I'm not sure that's a valid test name, please make sure select the below options.")
return {"p_test_name": None}
def validate_p_location(self, value, dispatcher, tracker, domain):
if any(tracker.get_latest_entity_values("GPE")) or any(tracker.get_latest_entity_values("location")):
return {"p_location": value}
else:
dispatcher.utter_message("Not a valid city. Please enter the valid city.")
return {"p_location": None}`
I don’t know what’s wrong. I have noticed similar example in Sara - the Rasa Demo Bot https://github.com/RasaHQ/rasa-demo/blob/724e7ab2a92337d0516f2aedf6555dd11631fe6f/demo/actions.py#L84. Here SalesForm has a slot (business_email) and entity (email) which has validate function to map the these two attributes. Please let me know what wrong I’m doing.