Hi, I have created an insurance form that requires validation. I’m facing issues, particularly in running the action file I’m getting an indentation error. I have created slots in the domain file and my action file has a code as follows. Can someone help me figure out what’s wrong with this? class InsuranceForm(FormAction): def name(self): return “insurance_form”
def required_slots(self,tracker) -> List[Text]:
return ["name","email","dateofbirth","number","address","zip"]
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
return {
"name": [
self.from_text(),
],
"email": [
self.from_text(),
],
"dateofbirth": [
self.from_text(),
],
"number": [
self.from_text(),
],
"address": [
self.from_text(),
],
"zip": [
self.from_text(),
],
}
def validate(self, dispatcher, tracker, domain):
slot_values = self.extract_other_slots(dispatcher, tracker, domain)
slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
if slot_to_fill:
slot_values.update(self.extract_requested_slot(dispatcher, tracker, domain))
for slot, value in slot_values.items():
if slot == 'name':
if value.replace(" ","").isalpha() == False:
dispatcher.utter_template('utter_wrong_name', tracker)
slot_values[slot] = None
else:
dispatcher.utter_message("Hi {}".format(value))
elif slot == 'address':
if value.replace(" ","").isalpha() == False:
dispatcher.utter_template('utter_wrong_address', tracker)
slot_values[slot] = None
elif slot == 'dateofbirth':
try:
datetime.strptime(value, '%d-%m-%Y')
except ValueError:
dispatcher.utter_template('utter_wrong_dob', tracker)
slot_values[slot] = None
elif slot == 'email':
email = re.compile(r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)')
mo = email.search(value)
if mo == None:
dispatcher.utter_template('utter_wrong_email', tracker)
slot_values[slot] = None
elif slot == 'number':
if len(value) != 10 or value.isdigit() == False:
dispatcher.utter_template('utter_wrong_contact', tracker)
slot_values[slot] = None
elif slot == 'zip':
if len(value) != 5 or value.isdigit() == False:
dispatcher.utter_template('utter_wrong_zipcode', tracker)
slot_values[slot] = None
return [SlotSet(slot, value) for slot, value in slot_values.items()]
def submit( self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> List[Dict]:
name=tracker.get_slot("name")
dateofbirth=tracker.get_slot("dateofbirth")
email=tracker.get_slot("email")
contact=tracker.get_slot("number")
address=tracker.get_slot("address")
zipcode=tracker.get_slot("zipcode")
dispatcher.utter_template("utter_insurance", tracker)
return []