Slot-filling
Slot-filling is a common design-pattern in spoken design, where you typically want to allow users to more freely answer a broad question instead of directly asking many detailed questions. For example, a travel agent bot asking "How can I help you?" is typically a better user-experience than initiating a sequence of questions "Do you want to book a trip?" -> "What city is your destination?" -> "Where do you want to go from?" etc. To this more broad question "How can I help you", users may for example say "I want to book a trip", but they may also provide more information right away - for example "I want to book a trip to Stockholm from New York for two people". In the first example, we have to ask followup questions since we have slots unfilled - i.e. we have to know what destination, departure city and how many people are travelling. For the second example, we could instead proceed to the next step of the dialog since these "slots are already filled.
To accomplish slot-filling in Narratory, you combine the two concepts discussed above: optional entities and conditionals. An example follows:
First, we define our bookingIntent to have examples using a variety of our three entities, and a simple BotTurn where we expect an answer matching this intent:
This means that the slots toCity, fromCity and numPeople may or may not have been set after this. No matter what, we reply "Excellent". If these slots have not been filled, we want to ask following questions to fill these slots. To do this, we create 3 new intents, one for each slot and then three following BotTurns each with a condition:
Here, we see that each of these BotTurns have a cond {}
parameter, with each one checking if a variable is null (which we learned in logic & conditionals means the variable is not set).
Note that different syntax is used in each cond and in the followups to repeat the entity value the user said. This is to show that there are different ways of doing it, based on preference. The
${user.numPeople}
syntax is an experimental feature that requires you to runnpm run watch
while building your app, but it gives you autocomplete for all variables. Also note that above it might make sense to use the entities instead of creating individual intents for each "slot-filling" intent. This will be supported shortly.
Finally, it is a good practise to confirm that we filled all the slots properly. This can be done as shown below, also allowing users to repair the turn (as shown in repair in bulding blocks). An example of this below:
As you see here, the same slot-filling intents are used again, here combined with repair which makes Narratory stay in the same BotTurn. If the user finally confirms that the details are correct, we move on with a followup - which takes us to the next turn in the narrative.
IMPORTANT: Don't forget to add all turns together to a narrative: