# How to Calculate the time

I’m trying to train a table reservation bot for a restaurant and the test case requires to intake a time or an amount of the time interval from user, add the time amount to the system time and finally check a condition if the result time belongs in the available time slot for the restaurant. Below is the sample bot-user convo and later is the condition -

" User: I want to reserve a table

Bot: How many seats would you like to reserve

Step 2

User: 2 seats

Bot: Which section would you like to book

• AC
• Non-AC

Step 3

User: (Clicks on Button 1)

Bot: When would you like to book a reservation? (We are only open from 7pm to 10pm)

Step 4 (Assuming conversation time is 7:10pm)

User: In half an hour

Bot: You have reserved 2 seats in our AC section for 7:30pm. Thanks!"

Explanation: “…In step 4, it extracts the reservation time (7:10pm + 30 mins → 7:30pm slot) based on the relative time input by the user (‘In half an hour’).”

I have written this python code in actions.py -

from datetime import datetime import datetime as dt

class CheckWorkingHours(Action): def name(self): # type: () → Text return “action_check_working_hours”

``````def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

now = dt.datetime.now()
today19pm = now.replace(hour=19, minute=0, second=0, microsecond=0)
today22pm = now.replace(hour=22, minute=0, second=0, microsecond=0)

if today19pm <= now <= today22pm:
message = 'You have reserved {number} seats in our {section} section for {7:30pm.} Thanks!'
else:
message = 'We are not open at that time. We are only open from 7pm to 10pm'

dispatcher.utter_message(message)

return []
``````

But I’m confused how to take the time input from the customer and also in a form of a string ("…half an hour") and convert it to the integer form to add the hour to the current hour and output it.

N.B.- I am a noob in RASA. I’m trying to do an industry level project which has given me only 1 day of time to learn and implement rasa and python. I’m still struggling with understanding the logics and implementations. Any detailed lead would help.

1 Like

DucklingEntityExtractor will be your friend here, it’s excellent at extracting structured time info from sentences like that. See [Tuning Your NLU Model](entity extraction docs)

What you are describing also sounds like a use case for a form - see this usage doc also - , and you’d put your logic re. validating the time the user enters in a custom validation action.