Reuse table reservation module to build chatbot
OpenCUI provides a mechanism for builders to share modules with each other. This means that you can take advantage of the expertise of others, which can save time and effort in building new chatbots.
Modules are reusable and composable, and can be enabled or disabled service as needed. In some cases, it may be possible to reuse one or more modules within a chatbot. However, when doing this, it is important to ensure that the modules are compatible with each other and the corresponding implementations of service interfaces are also wired. This will ensure that the module works as expected in the chatbot.
To use a pre-existing module, you first need to find a module that you are interested in. Then, you can simply import it into your chatbot, and use the functionality of the module directly in your chatbot. Modules are developed and maintained by other builders, so you can be confident that they are of high quality. You can also update modules as needed, which ensures that your chatbot always has the latest features and functionality. For more background and details about modules, see "Reuse an hours module".
This guide will use table reservation as an example to show how to reuse the tableReservation module in your chatbot. When you are done with this guide, the chatbot can help users make, view, and cancel table reservations. For example, a user might say the following to the chatbot:
User: "Hi, I'd like to reserve a table, please."
Chatbot: "How many people will you need the reservation for?"
User: "There will be two of us."
Chatbot: "Which day will you be joining us on?"
User: "This Sunday."
Chatbot: "What time would you like the reservation for?"
User: "About 3pm."
Chatbot: "Are you sure to book a table for 2 at 3:00 PM on Sunday, December 25, 2022?"
User: "Yes."
Chatbot: "Your reservation has been made. We'll see you at 3:00 PM on Sunday, December 25, 2022. You can check the reservation under your ID: xxxx."
To reuse the tableReservation
module, you need to understand the following dependencies:
- Table reservation CUI design: This is is the blueprint for the user experience and service scope of the table reservation module.
- Reservation API: This is the API that the module relies on.
- Google Calendar provider: This is the backend that the chatbot uses to store reservations. It means that you need a Google Workspace account.
Before you start
- Log in to OpenCUI.
- Follow the quickstart guide to learn the basics of OpenCUI.
- Set up Google Workspace and service account.
Set up Google Calendar
Under the design of the reservation API, resources are the entities that users can book, reserve or make appointment, such as tables in a restaurant or hairdressers. Resources are always associated with a specific location, and before users can book a resource, you need to first prepare the business-specific locations and resources in the backend. Different backends may have different ways of defining which resources are available for booking. Google Calendar based backend use Google Admin console to define table resources and Google Calendar to store reservations.
To set up your table resources:
- In the Google Admin console, add buildings as locations first and then add resources for each location to make them available for users to book.
- In the Google Calendar, set your business hours, including blocking off times when users cannot book tables (e.g., when you are closed)."
We will use the following business information as an example to show you how to set up your resources.
- Restaurant name: My First Restaurant
- Timezone: America/Los_Angeles
- Business hours
- Monday: Closed
- Tuesday to Sunday: 11:00 AM - 10:00 PM
- Bookable resources
Resource name | Resource type | Capacity | Duration |
---|---|---|---|
Small table | table | 2 guests | 2 hours |
Medium table | table | 4 guests | 2 hours |
Large table | table | 8 guests | 2 hours |
Add resources in Admin console
To add resources, it is important to specify the location, or building in Google Calendar, they belong to. Once you have added a building, you can then add the desired resources. Before you start, make sure you sign in to your Google Admin console.
Add a building
To go the Buildings section:
- From the Main Menu in the Google Admin console, select Directory > Buildings and resources > Manage resources.
- Click ADD BUILDING.
To add a building:
- In the Buildings section, click Add building.
- Fill in the form with the following information and add:
- Id: 1
- Name: My First Restaurant
- Description:
{"timezone": "America/Los_Angeles"}
- Floors: 1
- Click ADD BUILDING.
- Switch back to Resources.
Add resources
To add the first resource in the business information :
- In the Resources section, click Add new resource.
- Fill in the form with the following information:
- Category: Other resource
- Type: table
- Building: My First Restaurant
- Resource name: Small table
- Description (internal):
{"@class":"me.restaurant.tableReservation.Table", "durations": [3600], "capacity": 2}
- Click ADD RESOURCE.
To add the other two resources, repeat the same steps but change each value in the Description field.
- For the medium table:
{"@class":"me.restaurant.tableReservation.Table", "durations": [3600], "capacity": 4}
- For the large table:
{"@class":"me.restaurant.tableReservation.Table", "durations": [3600], "capacity": 8}
- For the medium table:
After completing these steps, your building and resources should look like the screenshot below.
Block time in Google Calendar
In order to prevent users making reservations when the restaurant is closed, you should block off any times outside of its opening hours. To do this:
[//]:<>(should we explain what is the primary calendar and resource calendar so that they know their way around?)
- Add events in your primary calendar to block time.
- Add resource calendars to your calendar so you can manage events in those calendars.
- Respond to event invitations in those calendars to confirm that the time slots are blocked off.
[//]:<>(Should we make this a tip) Before you start, make sure you are an admin first, then sign in to your Google Calendar.
Add events to block time
In your primary calendar, double-click the schedule.
Specify the event details below and click Save:
- Title: Closed
- Time:
12:00am
to11:00am
(Select appropriate start and end dates based on the current date.) - Repeat: Weekly on Sunday, Tuesday, Wednesday, Thursday, Friday, Saturday
- Rooms:
- (table)-My First Restaurant-1-Large table
- (table)-My First Restaurant-1-Medium table
- (table)-My First Restaurant-1-Small table
[//]:<>(step 6?) 3. Repeat step 6 to create additional events with the following details, then adjust the time and Repeat fields as needed:
- Event 2
- Time:
10:00pm
to11:59am
(Select appropriate start and end dates based on the current date.) - Repeat: Weekly on Sunday, Tuesday, Wednesday, Thursday, Friday, Saturday
- Time:
- Event 3
- Time: Select appropriate start and end dates based on the current date. (e.g.,
Mar 6, 2023
toMar 6, 2023
) - Repeat: Weekly on Monday
- Time: Select appropriate start and end dates based on the current date. (e.g.,
Add resources calendar
On Other calendars, click + > Browse resources. If you don't see this option, wait a few hours for ACL changes to take effect before managing resources.
Tick the table resources you need.
Back to your calendars, choose one resource calendar, and click Settings and sharing.
Ensure the resource calendar's timezone matches its location to avoid scheduling errors.
Repeat steps 3-4 to check the timezone of the other two resource calendars.
Respond to event invitations
- Open each resource calendar and locate the three events that you added.
- At the bottom of each event, select Yes as a response for all recurring events.
After completing these steps, your resource calendars should resemble the example below.
Reuse tableReservation module
Import the module
Now it's time to create a table reservation chatbot and reuse the table reservation module.
- Create a chatbot and add the English(en) language.
- Import the table reservation module into your chatbot.
Wire the provider
Before you can use the functionality provided by the reservation API, you should declare a reservation service first, then wire the reservation provider to the service.
To wire the reservation provider:
- Enter the chatbot you just created.
- In the navigation bar, select the Settings tab and head to Integrations page. In the Debug service provider section:
- Click Select service and select
services.opencui.reservation.IReservation
. - Follow set up Google calendar reservation provider to complete this integration.
- Click Select service and select
Test the chatbot
Finally, you can try to use your chatbot to make a table reservation. To test the chatbot:
Use Debug to send "I want to book a table" to start making a reservation. Then provide the number of guests, date and time. If there is an available table, you can book it successfully. For example:
Once you've made a reservation, you can go to your Google Calendar and check that reservation. Here is the reservation made by the above example:
The picture below shows how the reservation is made.
:🎉: Well done! You've built a table reservation chatbot. To explore more use cases, you can check the Test cases in the tableReservationApp chatbot.