Adding a node with slots to a dialog
In this tutorial, you add slots to a dialog node to collect multiple pieces of information from a user within a single node. The node that you create collects the information that is needed to make a restaurant reservation.
Learning objectives
By the time you finish the tutorial, you can learn how to:
- Define the intents and entities that are needed by your dialog
- Add slots to a dialog node
- Test the node with slots
Duration
This tutorial takes approximately 30 minutes to complete.
Prerequisite
Before you begin, complete the Getting Started tutorial. You use the dialog that you created, and add nodes to the simple dialog that you built as part of the getting started exercise.
Add intents and examples
Add an intent, which is the purpose or goal that is expressed in user input. You add a #reservation intent that recognizes user input that indicates that the user wants to make a restaurant reservation.
-
On the Intents page, click Create intent.
-
Add the following intent name, and then click Create intent:
reservation
The #reservation intent is added. A number sign (
#
) prefix is added to the intent name to label it as an intent. This naming convention helps you and others recognize the intent as an intent. It has no example user utterances that are associated with it yet. -
In the Add user examples field, type the following utterance, and then click Add example:
i'd like to make a reservation
-
Add these additional examples to help your assistant recognize the
#reservation
intent.I want to reserve a table for dinner Can 3 of us get a table for lunch? do you have openings for next Wednesday at 7? Is there availability for 4 on Tuesday night? i'd like to come in for brunch tomorrow can i reserve a table?
-
Click the Close arrow to finish adding the
#reservation
intent and its example utterances.
Add entities
An entity definition includes a set of entity values that represent vocabulary that is often used in the context of an intent. By defining entities, you can help your assistant identify references in the user input that are related to intents of interest. In this step, you enable system entities that can recognize references to time, date, and numbers.
-
Enable system entities that can recognize date, time, and number references in user input. Click System entities, and then turn on these entities:
@sys-time
@sys-date
@sys-number
You enabled the @sys-date, @sys-time, and @sys-number system entities. Now you can use them in your dialog.
Add a dialog node with slots
A dialog node represents the start of a thread of dialog between your assistant and the user. It contains a condition that must be met for the node to be processed by your assistant. At a minimum, it also contains a response. For example, a
node condition might look for the #hello
intent in user input, and respond with, Hi. How can I help you?
This example is the simplest form of a dialog node, one that contains a single condition and a single response.
You can define complex dialogs by adding conditional responses to a single node, adding child nodes that prolong the exchange with the user, and much more. (If you want to learn more about complex dialogs, you can complete the Building a complex dialog tutorial.)
The node that you add in this step is one that contains slots. Slots provide a structured format through which you can ask for and save multiple pieces of information from a user within a single node. They are most useful when you have a specific task in mind and need key pieces of information from the user before you can perform it. For more information, see Gathering information with slots.
The node that you add collects the information that is required to make a reservation at a restaurant.
-
Click Dialog to open the dialog tree.
-
Click the Node options icon on the Welcome node, and then select Add node below.
-
Start typing
#reservation
in the If assistant recognizes field, and then select it from the list. This node is used if the user input matches the#reservation
intent. -
Click Customize, set the Slots switch to On, and then click Apply.
-
In the Then check for section, add the following slots:
Slot details Check for Save it as If not present, ask @sys-date
$date
What day would you like to come in? @sys-time
$time
What time do you want for the reservation? @sys-number
$guests
How many people will be dining? -
In Assistant responds, enter the text response
OK. I am making you a reservation for $guests on $date at $time
. -
Click the Close icon to close the node edit view.
Test the dialog
-
Click Try it.
-
Type
i want to make a reservation
.The assistant recognizes the #reservation intent, and it responds with the prompt for the first slot
What day would you like to come in?
. -
Type
Friday
.The assistant recognizes the value, and uses it to fill the $date context variable for the first slot. It then shows the prompt for the next slot
What time do you want the reservation to be made for?
. -
Type
5pm
.The assistant recognizes the value, and uses it to fill the $time context variable for the second slot. It then shows the prompt for the next slot,
How many people will be dining?
. -
Type
6
.The assistant recognizes the value, and uses it to fill the $guests context variable for the third slot. Now that all of the slots are filled, it shows the node response,
OK. I am making you a reservation for 6 on 2021-04-09 at 17:00:00.
It worked! You created a node with slots.
Summary
You created a node with slots that can capture the information necessary to reserve a table at a restaurant.
Next steps
Improve the experience of users who interact with the node. Complete the follow-on tutorial, Improving a node with slots. It covers simple improvements, such
as how to reformat the date (2021-04-09
) and time (17:00:00
) values that are returned by the system. It also covers more complex tasks, such as what to do if the user does not provide the type of value that your dialog
expects for a slot.