Hi, I am tying to make a reservation bot, when user says in what reservation area he wants the reservation I request info for which date and which time he wants to make reservation,
user can answer in one line: i want to come on monday at 14:10:
but i can catch only time and as date not filled bot awaits new input. I didn’t create any intent for this input, I just ask the question and gather the input in forms. my code is as follows. is there any way to catch the day and time at once.
class GetCustomerReservationTimeDateForm(FormAction):
"""Example of a custom form action"""
def name(self) -> Text:
"""Unique identifier of the form"""
return "get_customer_reservation_form"
@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
"""A list of required slots that the form has to fill"""
return ["reservation_time", "reservation_date"]
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
"""A dictionary to map required slots to
- an extracted entity
- intent: value pairs
- a whole message
or a list of them, where a first match will be picked"""
print(self.from_text())
return {"reservation_time":[self.from_text()],
"reservation_date":[self.from_text()]
}
def validate_reservation_time(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
### Check if name is correct \!!!!
print("Time ", tracker.get_slot("reservation_date"), tracker.get_slot("reservation_time"))
reservation_time = re.findall(r"(2[0-3]:[0-5]{1}[\d]{1})|([0-1]?[\d]{1}:[0-5]{1}[\d]{1})", value)
if reservation_time:
reservation_time = reservation_time[0]
reservation_time = ' '.join(reservation_time).split()[0]
dispatcher.utter_message(text = "Rezervasyon Saatiniz {} olarak alındı.".format(reservation_time))
return {"reservation_time":reservation_time}
else:
dispatcher.utter_message(template="utter_wrong_time")
return {"reservation_time":None}
def validate_reservation_date(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
print("Date ", tracker.get_slot("reservation_date"), tracker.get_slot("reservation_time"))
reservation_date = re.findall(r"(pazartesi|salı|çarşamba|perşembe|cuma|cumartesi|pazar)", value, re.IGNORECASE)
if reservation_date:
reservation_date = reservation_date[0]
reservation_date = ''.join(reservation_date).split()[0]
dispatcher.utter_message(text = "Rezervasyon Gününüz {} olarak alındı.".format(reservation_date))
return {"reservation_date":reservation_date}
else:
dispatcher.utter_message(template="utter_wrong_date")
return {"reservation_date":None}
# USED FOR DOCS: do not rename without updating in docs
def submit(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict]:
dispatcher.utter_message(text="{} günü saat {} için rezervasyonunuz alındı.".format(tracker.get_slot("reservation_date"), tracker.get_slot("reservation_time")))
return []