Dialogflow Restaurant Chatbot Tutorial | 4

Part 4: Entities

Adi Cucolaș
Chatbots Life

--

OBJECTIVES

In this part, we will cover Entities and personalize the responses based on them.

By the end of this part, your bot will be able to understand when the user wants to make a booking for a given number of guests and date and send a personalized confirmation response.

CONVERSATIONAL FLOW DIAGRAM

During this part, the diagram will suffer 2 changes.

First one is caused by being able to specify the number of guests for the booking.

And the second one is because of the date and time.

Top 3 Bot Tutorials

1. Which are the best chatbot frameworks?

2. How we wrote a Wirecutter-like bot with Reply.ai in just a few hours

3. How to Create a Facebook Messenger Bot with Ruby on Rails

ENTITIES

An entity is a keyword extracted from a Training phrase. The value can then be further used as a parameter. It is not necessary to create entities for every word in the sentence, but rather only for the ones needed for Fulfillment. Dialogflow has already many pre-built system (they start with sys) entities to facilitate handling the most popular concepts.

We are going to use 3 of the system entities:

  • @sys.number — for the number of guests
  • @sys.date — for the date of the booking
  • @sys.time — for the time of the booking

It would also be possible to use @sys.date-time to handle the date and time simultaneously, but it would be harder for Dialogflow to interpret some user requests and the values extracted won’t satisfy our needs, that’s why we will keep them separated. But if you want to experience, this is how the flow diagram could look like.

GUESTS ENTITY

Since we’re using the system entities, we don’t have to create new ones for our Intent. So we’ll just jump into adding Training phrases.

Step 1: Add Training phrases

If you take a look at the first diagram you will notice what kind of sentences we need to add. The new phrases should include the date of the reservation, like:

  • “Book a table for 3”
  • “Make reservations for 5”
  • “Reserve a table for 2”

Add them in the Training phrases section and press ENTER after each one.

You should see the numbers highlighted. This means that the entity is mapped correctly. If you don’t see them highlighted, simply select the number with the cursor and a list of entities will pop.

Step 3: Change the parameter’s name

Our parameter is now named number, but a better guests would be more recognizable.

Go to Action and parameters section and just press on the parameter name and edit it.

You’ll notice that the value also changed to $guests, the parameter name will be useful for validation and the value will be used in responses. But we’ll get there.

Step 4: Add prompts

In case a user only asks to “book a table” without specifying the number of guests from the start, we still need to get that information somehow. The best way to do it is to simply prompt the user with a question regarding that parameter (ex: “For how many guests?”). This is very easy to implement, first of all we need to mark the guests parameter as required.

This means that every time a user tries to book a table, Dialogflow will check for a @sys.number entity which will map to our guests parameter. If there is no such entity present in the user’s request, then Dialogflow will prompt the user with a question to get that parameter’s value. You can leave the prompts empty and Dialogflow will create a default one, but I would really advise you to add some questions by yourself.

To do that press on Define prompts, add relevant questions and press ENTER after each of them.

Dialogflow will choose one randomly and send it to the user. So, add as many as you want. The more you have, the more conversational the bot seems.

Step 5: Update the responses

We want the user to see that the bot understood for how many people to book the table for, so we will add that number to the response. To add the value of the guests parameter, use $guests in the responses.

Step 6: Save

Don’t forget to always Save before you test the Intent or if you leave the page. Otherwise the changes won’t take effect.

Also, you should wait for Dialogflow’s training to be complete if you know you did everything right, but it’s not working. Two pop-ups will appear in the bottom right corner of the screen when the Agent started and finished training.

TRY OUT

Now, the bot should be able to understand the number of guests. Try both ways to get the guests parameter:

  1. Ask to book a table without specifying the number of guests.
  2. Tell the bot the number of guests when booking.

If you properly followed the tutorial, you should be able to see both responses.

CONCLUSION

In this part we used Entities to determine the number of guests for the booking. We also personalised the response with that parameter’s value.

TO DO: Now that you know how Entities work, try making the bot recognise the date and time of the booking. Follow the same steps using @sys.date and @sys.time. Use the diagram to model your conversation.

In the end the bot should be able to give proper prompts and a confirmation for all these requests:

  • “book a table”
  • “reserve a table for 2”
  • “make reservations for 6 pm”
  • “book a table tonight”
  • “reserve a table for 5 guests tomorrow”
  • “book a table at 9 pm for 5”
  • “reserve a table tonight at 7 pm for 6 guests”
  • “book a table for 5 tonight at 8 pm”
  • etc.

Give this part some claps if you consider that you’ve learned something out of it and ask as many questions as you want, I’m here to answer them all.

--

--