def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: slot_values = self.extract_other_slots(dispatcher, tracker, domain) # extract requested slot slot_to_fill = tracker.get_slot(REQUESTED_SLOT) if slot_to_fill: slot_values.update(self.extract_requested_slot(dispatcher, tracker, domain)) if not slot_values: # reject form action execution # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection(self.name(), "Failed to validate slot {0} " "with action {1}" "".format(slot_to_fill, self.name())) # we'll check when validation failed in order # to add appropriate utterances # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate(self, dispatcher, tracker, domain): """Validate extracted requested slot else reject the execution of the form action """ # extract other slots that were not requested but set by corresponding entity slot_values = self.extract_other_slots(dispatcher, tracker, domain) # extract requested slot slot_to_fill = tracker.get_slot(REQUESTED_SLOT) if slot_to_fill: slot_values.update(self.extract_requested_slot(dispatcher, tracker, domain)) if not slot_values: # Reject form action execution if some slot was requested but nothing was extracted. # It will allow other policies to predict another action raise ActionExecutionRejection(self.name(), f"Failed to validate slot {slot_to_fill} with action {self.name()}") # we'll check when validation failed in order to add appropriate utterances image_replaced = False dim_state = tracker.get_slot('dim_state') for slot, value in slot_values.items(): if slot == 'images': # flag width has just replaced if dim_state indicate a width has already been set before image_replaced = 'I' in dim_state if dim_state else False dim_state = self._update_dim_state(dim_state, 'I') slot_values['dim_state'] = dim_state # utter a message to acknowledge the change (if any) if image_replaced: dispatcher.utter_message(f"Good, I got the new image!") # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
async def _validate_no_code_solution(value: Text, dispatcher: CollectingDispatcher, tracker: Tracker) -> List[EventType]: slots = [SlotSet(NO_CODE_SOLUTION_SLOT, value)] # User corrects phone number phone_number_in_message = _get_phone_number( tracker.latest_message.get("text", "")) if phone_number_in_message is not None: dispatcher.utter_message( template="utter_daily_ci_enroll_acknowledge_new_phone_number") return [ SlotSet(NO_CODE_SOLUTION_SLOT, "change_phone"), SlotSet(PHONE_NUMBER_SLOT, phone_number_in_message), ] + await _send_validation_code(tracker, dispatcher, phone_number_in_message) if value == "change_phone": return [ SlotSet(NO_CODE_SOLUTION_SLOT, "change_phone"), SlotSet(PHONE_NUMBER_SLOT, None), SlotSet(PHONE_TO_CHANGE_SLOT, True), ] if value == "new_code": return slots + await _send_validation_code(tracker, dispatcher) raise ActionExecutionRejection(VALIDATE_ACTION_NAME)
def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: """Validate extracted requested slot else reject the execution of the form action """ # extract other slots that were not requested # but set by corresponding entity 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)) if not slot_values: # reject form action execution # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), "Failed to validate slot {0} " "with action {1}" "".format(slot_to_fill, self.name())) # we'll check when validation failed in order # to add appropriate utterances for slot, value in slot_values.items(): if slot == 'name': #logging.debug('Names in dataset =======>' +str(names)) #print('Names in dataset =======>',names) value = value.capitalize() if value not in names: dispatcher.utter_template('utter_wrong_name', tracker) # validation failed, set slot to None slot_values[slot] = None else: value = value.capitalize() slot_values[slot] = value elif slot == 'account_id': value = re.sub(r'(\d)\s+(\d)', r'\1\2', value) print("ACCOUNT ID SAVED => " + value) if not self.is_int( value) or int(value) <= 0 or len(value) != 16: dispatcher.utter_template('utter_wrong_account_id', tracker) # validation failed, set slot to None slot_values[slot] = None else: slot_values[slot] = value elif slot == 'age': if not self.is_int(value) or int(value) <= 0 or int( value) > 150 or int(value) < 15: dispatcher.utter_template('utter_wrong_age', tracker) # validation failed, set slot to None slot_values[slot] = None # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
async def validate( self, dispatcher: "CollectingDispatcher", tracker: "Tracker", domain: Dict[Text, Any], ) -> List[EventType]: # slot_values = self.extract_other_slots(dispatcher, tracker, domain) slot_values = {} # extract requested slot slot_to_fill = tracker.get_slot(REQUESTED_SLOT) if slot_to_fill: slot_values.update(self.extract_requested_slot( dispatcher, tracker, domain)) if not slot_values: # reject to execute the form action # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), f"Failed to extract slot {slot_to_fill} with action {self.name()}", ) logger.debug(f"Validating extracted slots: {slot_values}") return await self.validate_slots(slot_values, dispatcher, tracker, domain)
def validate(self, dispatcher:CollectingDispatcher, tracker:Tracker, domain: Dict[Text, Any]) -> List[Dict]: 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)) if not slot_values: raise ActionExecutionRejection(self.name(),"Failed to validate slot {0}""with action {1}""".format(slot_to_fill, self.name())) for slot,value in slot_values.items(): if slot =='cuisine': if value.lower() in self.cuisine_db(): slot_values[slot]= value else: dispatcher.utter_template("utter_wrong_cuisine", tracker) slot_values[slot] =None if slot == 'num_people': if self.is_int(value) and int(value): slot_values[slot]= value else: dispatcher.utter_template("utter_wrong_num_people",tracker) slot_values[slot] =value if slot =='outdoor_seating': if type(value)== str: if 'out' in value: slot_values[slot] =True elif 'in' in value: slot_values[slot] =False else: dispatcher.utter_template("utter_wrong_outdoor_seating",tracker) slot_values[slot]=None return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: """Validate extracted requested slot else reject the execution of the form action """ for slot_name in CreateTaskForm.required_slots(tracker): print(slot_name, tracker.get_slot(slot_name)) # extract other slots that were not requested # but set by corresponding entity slot_values = self.extract_other_slots(dispatcher, tracker, domain) # extract requested slot slot_to_fill = tracker.get_slot(REQUESTED_SLOT) if slot_to_fill: slot_values.update( self.extract_requested_slot(dispatcher, tracker, domain)) print("#### slot_to_fill", slot_to_fill) print("#### slot_values", slot_values) if slot_to_fill == 'org_id' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message slot_values['org_id'] = (tracker.latest_message)['text'] elif slot_to_fill == 'ws_id' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message intent = tracker.latest_message.get("intent", {}).get("name") # validation failed, set slot to user message print(intent + "from validation") if intent == "inform": slot_values['ws_id'] = (tracker.latest_message)['text'] else: SlotSet(REQUESTED_SLOT, "0") elif slot_to_fill == 'stream_name' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message slot_values['stream_name'] = (tracker.latest_message)['text'] if not slot_values: print("********** validation failed") # reject form action execution # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), "Failed to validate slot {0} " "with action {1}" "".format(slot_to_fill, self.name())) # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: """Validate extracted requested slot else reject the execution of the form action """ # extract other slots that were not requested # but set by corresponding entity slot_values = self.extract_other_slots(dispatcher, tracker, domain) # extract requested slot slot_to_fill = tracker.get_slot(REQUESTED_SLOT) if slot_to_fill: slot_values.update( self.extract_requested_slot(dispatcher, tracker, domain)) if not slot_values: # reject form action execution # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), "Failed to validate slot {0} " "with action {1}" "".format(slot_to_fill, self.name())) # we'll check when validation failed in order # to add appropriate utterances for slot, value in slot_values.items(): if slot == 'cuisine': if value.lower() not in self.cuisine_db(): dispatcher.utter_template('utter_wrong_cuisine', tracker) # validation failed, set slot to None slot_values[slot] = None elif slot == 'num_people': if not self.is_int(value) or int(value) <= 0: dispatcher.utter_template('utter_wrong_num_people', tracker) # validation failed, set slot to None slot_values[slot] = None elif slot == 'outdoor_seating': if isinstance(value, str): if 'out' in value: # convert "out..." to True slot_values[slot] = True elif 'in' in value: # convert "in..." to False slot_values[slot] = False else: dispatcher.utter_template( 'utter_wrong_outdoor_seating', tracker) # validation failed, set slot to None slot_values[slot] = None # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate( self, dispatcher: "CollectingDispatcher", tracker: "Tracker", domain: Dict[Text, Any], ) -> List[Dict]: 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)) if not slot_values: raise ActionExecutionRejection( self.name(), "form,failed to validateSlot {0} with action {1}".format( slot_to_fill, self.name())) for slot, value in slot_values.items(): if slot == 'name': name, massage = name_test(value) if name is None: slot_values[slot] = None dispatcher.utter_message(text=massage) else: slot_values[slot] = value dispatcher.utter_message(text=massage) elif slot == 'phone': phone, massage = phone_test(value) if phone is None: slot_values[slot] = None dispatcher.utter_message(text=massage) else: slot_values[slot] = phone dispatcher.utter_message(text=massage) elif slot == "email": email, massage = email_test(value) if email is None: slot_values[slot] = None dispatcher.utter_message(text=massage) else: slot_values[slot] = email dispatcher.utter_message(text=massage) elif slot == "problem": problem, massage = problem_test(value) if problem is None: slot_values[slot] = None dispatcher.utter_message(text=massage) else: slot_values[slot] = problem dispatcher.utter_message(text=massage) return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate(self, dispatcher, tracker, domain): """Validate extracted requested slot else reject the execution of the form action """ # extract other slots that were not requested but set by corresponding entity slot_values = self.extract_other_slots(dispatcher, tracker, domain) # extract requested slot slot_to_fill = tracker.get_slot(REQUESTED_SLOT) if slot_to_fill: slot_values.update(self.extract_requested_slot(dispatcher, tracker, domain)) if not slot_values: # Reject form action execution if some slot was requested but nothing was extracted. # It will allow other policies to predict another action raise ActionExecutionRejection(self.name(), f"Failed to validate slot {slot_to_fill} with action {self.name()}") # we'll check when validation failed in order to add appropriate utterances width_replaced = False height_replaced = False dim_state = tracker.get_slot('dim_state') for slot, value in slot_values.items(): if slot == 'width': if not self.is_int(value) or int(value) <= 0: dispatcher.utter_template('utter_wrong_width', tracker) # validation failed, set slot to None slot_values[slot] = None else: # make sure width is stored as an integer slot_values[slot] = int(value) # flag width has just being replaced if dim_state indicate a width has already been set before width_replaced = 'W' in dim_state if dim_state else False dim_state = self._update_dim_state(dim_state, 'W') elif slot == 'height': if not self.is_int(value) or int(value) <= 0: dispatcher.utter_template('utter_wrong_height', tracker) # validation failed, set slot to None slot_values[slot] = None else: # make sure height is stored as an integer slot_values[slot] = int(value) # flag height has just being replaced if dim_state indicate a height has already been set before height_replaced = 'H' in dim_state if dim_state else False dim_state = self._update_dim_state(dim_state, 'H') slot_values['dim_state'] = dim_state # utter a message to acknowledge the change (if any) if width_replaced and height_replaced: dispatcher.utter_message(f"I got it, the new dimension is {slot_values['width']}x{slot_values['height']}.") elif width_replaced: dispatcher.utter_message(f"I got it, the new width is {slot_values['width']}.") elif height_replaced: dispatcher.utter_message(f"I got it, the new height is {slot_values['height']}.") # compare source and target dimension ratio success, same_ratio = self._compare_dimension_ratio(tracker, slot_values) if success and not same_ratio: slot_values['dim_state'] = self._update_dim_state(dim_state, 'R') # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: """Validate extracted requested slot else reject the execution of the form action """ # extract other slots that were not requested # but set by corresponding entity slot_values = self.extract_other_slots(dispatcher, tracker, domain) # extract requested slot slot_to_fill = tracker.get_slot(REQUESTED_SLOT) if slot_to_fill: slot_values.update( self.extract_requested_slot(dispatcher, tracker, domain)) print("#### slot_to_fill", slot_to_fill) print("#### slot_values", slot_values) if slot_to_fill == 'org_id' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message slot_values['org_id'] = (tracker.latest_message)['text'] elif slot_to_fill == 'workspace_type' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message slot_values['workspace_type'] = ( tracker.latest_message)['text'] elif slot_to_fill == 'workspace_name' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message slot_values['workspace_name'] = ( tracker.latest_message)['text'] elif slot_to_fill == 'workspace_description' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message slot_values['workspace_description'] = ( tracker.latest_message)['text'] if not slot_values: # reject form action execution # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), "Failed to validate slot {0} " "with action {1}" "".format(slot_to_fill, self.name())) for slot, value in slot_values.items(): if slot == 'workspace_type': if value not in self.workspace_type_db(): dispatcher.utter_template('utter_wrong_workspace_type', tracker) slot_values[slot] = None if slot == 'workspace_name': if value in self.workspace_name_db(tracker): dispatcher.utter_template('utter_wrong_workspace_name', tracker) slot_values[slot] = None # validation failed, set slot to None # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: """Validate extracted requested slot else reject the execution of the form action """ #SlotSet("stream_id", tracker.slots['stream_id']) # extract other slots that were not requested # but set by corresponding entity slot_values = self.extract_other_slots(dispatcher, tracker, domain) print("slot_values *****") print(slot_values) # extract requested slot slot_to_fill = tracker.get_slot(REQUESTED_SLOT) if slot_to_fill: slot_values.update( self.extract_requested_slot(dispatcher, tracker, domain)) print("#### slot_to_fill", slot_to_fill) print("#### slot_values", slot_values) if slot_to_fill == 'org_id' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message slot_values['org_id'] = (tracker.latest_message)['text'] elif slot_to_fill == 'ws_id' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message intent = tracker.latest_message.get("intent", {}).get("name") # validation failed, set slot to user message print(intent + "from validation") if intent == "inform": slot_values['ws_id'] = (tracker.latest_message)['text'] else: SlotSet(REQUESTED_SLOT, "0") elif slot_to_fill == 'stream_id' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) intent = tracker.latest_message.get("intent", {}).get("name") # validation failed, set slot to user message print(intent + "from validation") if intent == "inform": slot_values['stream_id'] = (tracker.latest_message)['text'] else: SlotSet(REQUESTED_SLOT, "0") elif slot_to_fill == 'task_name' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message slot_values['task_name'] = (tracker.latest_message)['text'] elif slot_to_fill == 'task_priority' and not slot_values: print("###### tracker.latest_message.text", (tracker.latest_message)['text']) # validation failed, set slot to user message slot_values['task_priority'] = (tracker.latest_message)['text'] if not slot_values: # reject form action execution # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), "Failed to validate slot {0} " "with action {1}" "".format(slot_to_fill, self.name())) # we'll check when validation failed in order # to add appropriate utterances for slot, value in slot_values.items(): if slot == 'task_priority': if value not in self.task_priority_db(): dispatcher.utter_template('utter_wrong_task_priority', tracker) # validation failed, set slot to None slot_values[slot] = None # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: 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)) if not slot_values: # reject form action execution # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), "Failed to validate slot {0} " "with action {1}" "".format(slot_to_fill, self.name())) for slot, value in slot_values.items(): global try_OTP_counts if slot == 'OTP': checking_otp = int(value) print("OTP : " + str(OTP), "checking OTP : " + str(checking_otp)) #print(self.is_int(value)," ",len(value)," ", len(value)) if not self.is_int(value) or len(value) <= 0 or len(value) > 6: dispatcher.utter_message( 'OTP is incorrect. Please try again ') try_OTP_counts += 1 slot_values[slot] = None if try_OTP_counts > 4: #print("EXCEEDED 1") dispatcher.utter_message( 'You have exceeded the number of tries. Try again later.' ) slot_values[slot] = None return [] else: print("IN ELSE") if checking_otp == int(OTP): print("MATCHED") dispatcher.utter_message( 'Transaction completed successfully') slot_values[slot] = value return [ SlotSet(slot, value) for slot, value in slot_values.items() ] else: dispatcher.utter_message( 'OTP is incorrect. Please try again ') try_OTP_counts += 1 print("Number of tries OTP " + str(try_OTP_counts)) if try_OTP_counts < 3: slot_values[slot] = None else: dispatcher.utter_message( 'You have exceeded the number of tries .') dispatcher.utter_message( ' ...Transaction canceled...') slot_values[slot] = "000000" # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: """Validate extracted requested slot else reject the execution of the form action """ # extract other slots that were not requested # but set by corresponding entity #intent = tracker.latest_message['intent'].get('name') #print("----INTENT-----",intent) 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)) if not slot_values: # reject form action execution # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), "Failed to validate slot {0} " "with action {1}" "".format(slot_to_fill, self.name())) # we'll check when validation failed in order # to add appropriate utterances for slot, value in slot_values.items(): #if slot == 'name': # if value.lower() not in self.clientNames_db(): # dispatcher.utter_template('utter_wrong_name', tracker) # validation failed, set slot to None # slot_values[slot] = None if slot == 'account_id': value = re.sub(r'(\d)\s+(\d)', r'\1\2', value) if not self.is_int( value) or int(value) <= 0 or len(value) != 16: dispatcher.utter_template('utter_wrong_account_id', tracker) # validation failed, set slot to None slot_values[slot] = None else: slot_values[slot] = value elif slot == 'transfer_to_id': value = re.sub(r'(\d)\s+(\d)', r'\1\2', value) if not self.is_int( value) or int(value) <= 0 or len(value) != 16: dispatcher.utter_template('utter_wrong_account_id', tracker) # validation failed, set slot to None slot_values[slot] = None else: slot_values[slot] = value elif slot == 'amount_transfer': if not self.is_int(value) or int(value) <= 0: dispatcher.utter_template('utter_wrong_amount_transfer', tracker) # validation failed, set slot to None slot_values[slot] = None if int(value) > 2000 or int(value) < 50: dispatcher.utter_message( "Wrong amount, Please enter amount with minimum limit 50 and maximum limit 2000." ) slot_values[slot] = None elif slot == 'name': global name slot_values[slot] = name #logging.debug('name =======>'+str(name)) if not name: # if name is empty #logging.debug('slot_values[slot] =======>' +str(slot_values[slot])) #logging.debug('Names in dataset =======>' +str(names)) #print('Names in dataset =======>',names) value = value.capitalize() if value not in names: dispatcher.utter_template('utter_ask_rephrase', tracker) # validation failed, set slot to None if name: slot_values[slot] = name else: slot_values[slot] = None else: #value = value.capitalize() slot_values[slot] = value name = value #print(name,value) dispatcher.utter_message("Welcome " + name) # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: """Validate extracted requested slot else reject the execution of the form action """ # extract other slots that were not requested # but set by corresponding entity #print("Fall back count in Account form after reseting",fallback_counts) slot_values = self.extract_other_slots(dispatcher, tracker, domain) # extract requested slot slot_to_fill = tracker.get_slot(REQUESTED_SLOT) if slot_to_fill: slot_values.update( self.extract_requested_slot(dispatcher, tracker, domain)) if not slot_values: # reject form action execution # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), "Failed to validate slot {0} " "with action {1}" "".format(slot_to_fill, self.name())) # we'll check when validation failed in order # to add appropriate utterances for slot, value in slot_values.items(): #if slot == 'name': # if value.lower() not in self.clientNames_db(): # dispatcher.utter_template('utter_wrong_name', tracker) # validation failed, set slot to None # slot_values[slot] = None if slot == 'accountType': if value.lower() not in self.accountType_db(): dispatcher.utter_template('utter_wrong_accountType', tracker) # validation failed, set slot to None slot_values[slot] = None else: value = value.capitalize() slot_values[slot] = value elif slot == 'mobileNumber': print(value, type(value)) value = re.sub(r'(\d)\s+(\d)', r'\1\2', value) print(value) if not self.is_int(value) or int(value) <= 0: dispatcher.utter_template('utter_wrong_mobileNumber', tracker) # validation failed, set slot to None slot_values[slot] = None elif len(value) > 12 or len(value) < 9: dispatcher.utter_template('utter_wrong_mobileNumber', tracker) # validation failed, set slot to None slot_values[slot] = None else: slot_values[slot] = value elif slot == 'residence': value = value.capitalize() slot_values[slot] = value elif slot == 'age': if not self.is_int(value) or int(value) <= 0 or int( value) > 150 or int(value) < 15: dispatcher.utter_template('utter_wrong_age', tracker) # validation failed, set slot to None slot_values[slot] = None elif slot == 'profession': value = value.capitalize() slot_values[slot] = value elif slot == 'name': global name slot_values[slot] = name logging.debug('name =======>' + str(name)) if not name: # if name is empty #logging.debug('slot_values[slot] =======>' +str(slot_values[slot])) #logging.debug('Names in dataset =======>' +str(names)) #print('Names in dataset =======>',names) value = value.capitalize() if value not in names: dispatcher.utter_template('utter_ask_rephrase', tracker) # validation failed, set slot to None if name: slot_values[slot] = name else: slot_values[slot] = None else: #value = value.capitalize() slot_values[slot] = value name = value #print(name,value) dispatcher.utter_message("Welcome " + name) # validation succeed, set the slots values to the extracted values return [SlotSet(slot, value) for slot, value in slot_values.items()]
def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: #def validate(self, dispatcher, tracker, domain): # type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict] """"Validate extracted requested slot else raise an error""" slot_values = self.extract_other_slots(dispatcher, tracker, domain) # extract requested slot slot_to_fill = tracker.get_slot(REQUESTED_SLOT) if slot_to_fill: slot_values.update( self.extract_requested_slot(dispatcher, tracker, domain)) if not slot_values: # reject form action execution # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), "Failed to validate slot {0} " "with action {1}" "".format(slot_to_fill, self.name())) for slot, value in slot_values.items(): if slot == 'dept': if value.lower() not in self.dept_db(): dispatcher.utter_template('utter_incorrect_dept', tracker) slot_values[slot] = None # validation failed, set this slot to None elif slot == 'time': dept = tracker.get_slot('dept') if value[11:19] == "00:00:00": dispatcher.utter_template("utter_incorrect_time", tracker) slot_values[slot] = None else: flag = 0 file = pd.read_csv('DocAvail.csv') date = value[0:10] time_slot = value[11:19] date_time = datetime.datetime.strptime(date, "%Y-%m-%d") weekday = datetime.datetime.strftime(date_time, "%A") Dept = file[file['Department'].str.lower() == dept].reset_index().drop('index', axis=1)[[ 'Physician name', weekday ]] print(Dept) for i in range(len(Dept)): avail_time = Dept.ix[i, weekday].split('-') low = int(avail_time[0].split(':')[0]) high = int(avail_time[1].split(':')[0]) time_slot_int = int(value[11:19].split(':')[0]) if time_slot_int > low and time_slot_int < high: flag = 1 break if flag == 1: pass else: dispatcher.utter_template("utter_incorrect_time", tracker) slot_values[slot] = None return [SlotSet(slot, value) for slot, value in slot_values.items()]