Hi guys,
I want to add a validate function into my custom FormAction. The user is asking the bot for the foodmenu in a specific part of an organization. The entity/slot_name is called “gastro_loc”.
I added several training examples with the slot_values “mensa” and “canteen”.
Note: Only this two values appear in the examples, because the organization just has this two.
Now here is a part of my FormAction:
def gastro_loc_db(self):
# type: () -> List[Text]
"""
database of supported gastro locations
:return:
"""
return ["mensa",
"canteen"]
def validate_gastro_loc(self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> Optional[Text]:
"""Validate cuisine value."""
if value.lower() in self.gastro_loc_db():
# validation succeeded
return {'gastro_loc': value}
else:
self.deactivate()
dispatcher.utter_template('utter_wrong_gastro_loc', tracker)
# validation failed, set this slot to None, meaning the
# user will be asked for the slot again
return {'gastro_loc': None}
I also added the utter_wrong_gastro_loc in the domain.yml file.
Now I want to test the bot and I ask him about the food menu. I want the menu for the cafeteria, so the bot should know that cafeteria does not exist and print the utter_wrong_gastro_loc. But I just got following message:
2019-08-12 10:06:18 ERROR rasa_sdk.endpoint - Failed to extract slot gastro_loc with action gastronomy_form 127.0.0.1 - - [2019-08-12 10:06:18] “POST /webhook HTTP/1.1” 400 256 0.007018
So where is the mistake in my code? Do I need to add some examples with cafeteria value in my training examples? I just want to validate the users input for the location. If the users chooses any other location than “mensa” or “canteen” the bot should answer “please choose between mensa and canteen”
Thanks