Creating a conversational order process in Teneo

Think about how much faster you could sell or help customers by having a chatbot or virtual assistant handling orders. An order process has certain information that needs to be filled out in order to complete the process. When you are building a bot, this is called slot filling. This guide is a walkthrough on how you create a slot filling flow.

Slot filling is about collecting certain bits of information from the user before a final response can be given. A typical use-case is to make an order of some kind where certain parameters need to be settled before the order can be placed, for example booking a flight or ordering a pair of shoes.

Here we will build a flow for ordering a coffee:

User: I’d like to order a coffee.
Bot: Ok, what coffee would you like?

User: A cappuccino, please.
Bot: What size would you like?

User: Small would be fine.
Bot: Ok, a small cappuccino will be ready for pickup in 5 minutes.

Sometimes the user will mention a specific type of coffee and/or size already in the first request, so your flow needs to cater for that too:

User: Can I have a small cappuccino please?
Bot: Ok, a small cappuccino will be ready for pickup in 5 minutes.

Other times the user may give more information than is requested at a certain point:

User: May I order a coffee please.
Bot: Ok, what coffee would you like?

User: A small cappuccino, please.
Bot: Ok, a small cappuccino will be ready for pickup in 5 minutes.

These are the steps to create a slot filling flow:

  1. Decide on the slots to be filled:
    • What information do you need?
  2. Create the basic flow:
    • Create the flow structure
    • Populate the nodes and transitions
    • Summarize the information gathered in a final Output.
  3. Pickup the entities:
    • Add a Flow Variable for each slot.
    • Add a Flow Listener for each slot.
  4. Specify when outputs should be skipped (the bot shouldn’t ask for things already known).
  5. Test all scenarios in the Try out panel.

When you’re done your flow will look something like this:

Structure of a slot filling flow

Decide on the slots

Before we start to create the flow, we first have to decide on which information we need to get from the user. Each piece of information we want to extract will correspond to one slot we want to fill. For the coffee order, our bot needs to gather two pieces of information: the type of coffee and its size. We will make user of the entities COFFEES_SERVED.ENTITY and COFFEE_SIZES.ENTITY that we have created earlier. These entities will be used in Flow Listeners to pick up the values whenever the user mentions them in the flow. They will also be used to check the user responses when the respective values are prompted for.

Create the Basic flow

We will now proceed to create a first simple version of our flow. This includes setting up the structure and populating the trigger, the transitions and the output nodes. We will go through each of these step by step.

Setup the flow structure

Let’s start:

  1. Create a new flow and call it User wants to order a coffee.
  2. Select the output node and add another output node to it.
  3. Then select the latest output node and add one more. Your flow should now consist of a class trigger and three consecutive output nodes.

Populate the trigger

Now it is time to populate the trigger:

  1. Copy the following learning examples to your clipboard:
    A small filter coffee, please
    Can I get a coffee?
    Can I have a coffee, please?
    Can I order a coffee
    Can I order an espresso?
    Can you get me a coffee
    Could I get a large macchiato?
    Could I have a flat white
    Could I order a large americano
    Give me a frappuccino, please
    I want a small cappuccino!
    I want espresso
    I want to order a coffee
    I would like a coffee
    I would like to order a coffee
    I'd like a large espresso
    I'd like to order an americano
    May I have a filter coffee?
  2. Select the trigger, open the ‘Learning Examples’ panel on the right, and click where it says ‘No positive learning examples’. Then hit Ctrl + V to paste the learning examples. You can see that it worked when the examples appear in the field. Have a look at the video below if you are unsure how to import all Examples at once.
  3. Name the trigger Can I order a coffee?.

Populate the first output node

In the first output node after the trigger, we want to prompt the user to indicate the desired coffee type in more detail:

  1. Select the first output node.
  2. Open the ‘Answer’ panel on the right an paste the following: Ok, what coffee would you like?.
  3. Name the node Ask for coffee type.

Configure the first transition

In the output node right above, we ask the user for the desired type of coffee. In this transition, we thus expect an answer that contains one of the coffee types we serve. If the user does not answer with a coffee type we serve, we shall not go on with the order process. We will thus put a condition onto this transition that requires a coffee type being mentioned:

  1. Select the outgoing transition from the ‘Ask for coffee type’ node.
  2. Open the ‘Examples’ panel to the right in order to set the toggles to:
    • ‘Conditional’ and
    • ‘Gets input before continuing’
  3. Paste the entity %COFFEES_SERVED.ENTITY into the condition field.
  4. Name the transition: User responds with coffee type.

Populate the second output node

In the first output node above, we have asked the user for the desired coffee type. Here, it is time to ask for the size of the coffee:

  1. Select the second output node.
  2. In the ‘Answers’ panel to the right paste What size would you like?.
  3. Name this node Ask for size.

Configure the last transition

Having asked the user in the previous output node for the coffee size, we now expect the user to give us a coffee type in his answer. We thus again make this transition conditional, but this time we require a size to be present in the user input in order for the transition to be traversed.

  1. Select the transition node between the last two output nodes in the flow.
  2. Use the toggles in the ‘Examples’ panel to make this transition:
    • ‘Conditional’ and
    • ‘Gets input before continuing’.
  3. Paste: %COFFEE_SIZES.ENTITY into the condition field of this transition.
  4. Name it User responds with size.

Populate the final output node

Now we are almost done! The only thing remaining is the final output node that summarizes and confirms the whole order:

  1. Select the final output node.
  2. Paste: Ok, a ${orderedCoffeeSize} ${orderedCoffeeType} will be ready for pickup in 5 minutes. into the ‘Answers’ field.
  3. Name this output node Summarize order.
  4. Hit ‘Save’.

Give it a first try!

Now go ahead and give it a first try in tryout. For example, you could try the following conversation:

User: I’d like to order a coffee.
Bot: Ok, what coffee would you like?

User: A cappuccino, please.
Bot: What size would you like?

User: Small would be fine.
Bot: Ok, a small cappuccino will be ready for pickup in 5 minutes.

You have certainly noted that the last output is not exactly what you have expected. While having guided you through the whole conversation, the bot shows in the last answer that he was not able to pick up your order. The reason is this: we used two flow variables (orderedCoffeeType, orderedCoffeeSize) in this output that we have neither defined nor have we assigned them any value. We will now change that in the following section.

Pickup the entities

So now we have the basic flow in place, but the bot does not yet pick up the coffee type or the coffee size that the user ordered. In order to be able to pick them up, we basically have to do two things:

  1. add flow variables
  2. add flow listeners that assign values to these variables.

We will guide you through both in the following.

Add flow variables

We will now add two flow variables, one to store the coffee type and one to store the coffee size.

  1. In the solution’s main window, move to the ‘FLOW’ tab, and select ‘Variables’ in the purple navigation bar on the left hand side.
  2. Add the following two variables, and initialize both them as empty strings "":
    • orderedCoffeeType
    • orderedCoffeeSize

Add flow listeners

Having created the variables alone is not enough. We now have to make sure that they get their respective values. We want our bot to store the coffee type and size wherever in the flow they are mentioned. Thus, we use two flow listeners. This is how to go about:

  1. Move to the ‘FLOW’ tab. Select ‘Listeners’ in the purple navigation bar on the left.
  2. Click on the little ‘Add’ icon in the upper right corner to create a flow listener.
  3. Create two listeners, one for types of coffee and one for sizes.
    • Listener for coffee type:
      • Name: Pick up coffee type
      • Condition: %COFFEES_SERVED.ENTITY^{ orderedCoffeeType = lob.coffeeType }
    • Listener for coffee size
      • Name: Pick up coffee size
      • Condition: %COFFEE_SIZES.ENTITY^{ orderedCoffeeSize = lob.coffeeSize }
  4. Save the flow.

Both listener conditions contain propagation scripts. For coffee types we tell Teneo to set the flow variable ‘orderedCoffeeType’ to the value of the entity variable coffeeType. As the name suggests, entity variables belong to Entities and Language Objects, and you access them in propagation scripts by using the prefix ‘lob’, as shown below:

Attached script for type

For sizes we do the same; we set the flow variable orderedCoffeeSize to the value of the entity variable coffeeSize.

Give it another try!

Now it’s time to give it another try! Go to try out and ask the bot the following:

User: I’d like to order a coffee.
Bot: Ok, what coffee would you like?

User: A cappuccino, please.
Bot: What size would you like?

User: Small would be fine.
Bot: Ok, a small cappuccino will be ready for pickup in 5 minutes.

This should now work out smoothly. However, as soon as you slightly change your answers you will get the following:

User: I’d like to order a coffee.
Bot: Ok, what coffee would you like?

User: A small cappuccino, please.
Bot: What size would you like?

User: Small would be fine.
Bot: Ok, a small cappuccino will be ready for pickup in 5 minutes.

The bot asks you which size you would like despite the fact that you already mentioned the size in your previous answer. It would be much nicer if the bot skipped questions to which the user already gave an answer, even though not having been explicitly prompted to do so. In Teneo, you may use ‘Skip conditions’ to accomplish that. The next section will show you how.

Specify when outputs should be skipped

As a final step we want to avoid prompting for things that the user has already mentioned. In Teneo you do that by adding ‘Skip conditions’ to your output nodes:

  1. Select the ‘Ask for coffee type’ node.
  2. Open its ‘Skip conditions’-panel on the right hand side.
  3. Click on ‘Add’ to create a skip condition. Paste orderedCoffeeType into the ‘Skip Condition’ field. This will be evaluated to true if the variable is set and to false if the variable is empty
  4. Now use the drop-down menu besides ‘Select a target’ to determine how the flow processing should go on. In this case it should be ‘User responds with coffee type’.
  5. Hit ‘Save’.

What we have done here is tell Teneo: if the orderedCoffeeType has a value when you reach the ‘Ask for coffee type’ output node, skip it and traverse the path ‘User responds with coffee type’ without waiting for an input from the user.

To complete the flow, do the same for the ‘Ask for size’ output node. But for that output node, you should condition the skip on whether the orderedCoffeeSize is known or not.

Test the scenarios

Now it’s time to test the flow!

User: I’d like to order a coffee.
Bot: Ok, what coffee would you like?

User: A small cappuccino, please.
Bot: Ok, a small cappuccino will be ready for pickup in 5 minutes.

It is now possible to put all details into one single request:

User: Can I have a large espresso please?
Bot: Ok, a large espresso will be ready for pickup in 5 minutes.

Teneo Developers

Try Before You Buy.
Build. Deploy. Analyze.

Sign up to get your own developer sandbox of Teneo containing all the tools needed to build and manage advanced conversational solutions.

Get Started For Free

Author:
Gareth Walters is Vice President of Innovation and Community. Having moved into IT 20 years ago, he was responsible for Professional Services teams in several ERP, Supply Chain Management and Content Management software companies in a variety of sectors including Central Government, FMCG, Automotive and Pharmaceutical.

Leave a Reply

Your email address will not be published. Required fields are marked *

[ Event ]
[ Event ]