Extract Entities

Sometimes it's not enough to recognize which flow to trigger. Your bot may also need to extract some piece of information from the input to respond appropriately. A typical use case is picking up the user's order and repeating it, like in this example:

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

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

In the following, we will show you how to create a flow that enables users to have this kind of conversation with your bot. These are the steps involved:

  • Add a new flow.
  • Set up a flow variable.
  • Add another output node.
  • Configure a data action to extract information.
  • Use the information in the output.

End result of your first flow

Create a new flow

We begin by creating a new flow. Just as previous flows we have built, it will have a trigger and an output node.

Setup the flow

Let's start by creating a new flow and call it User wants to order a coffee.

Populate the trigger

  1. Name the trigger Order a Coffee.

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, go to the 'Examples' panel on the right, and click where it says 'No Positive 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. Scroll down to 'Match Requirements' and select the 'Generate' button, this will automatically generate a class trigger.
  4. Your trigger is now configured.

Populate the output node

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

  1. Select the output node.
  2. Name the node Ask for coffee type.
  3. Go to the 'Answer' panel on the right and paste the following: Ok, what coffee would you like?.

Extract information from the user input

So far so good. You now have a flow which triggers when users want to order a coffee and it answers with a question about the coffee type. In order to be able to pickup the coffee type from the user input, we now need to proceed with the following:

  • Setup a flow variable to store the coffee type.
  • Add an additional output node which will summarize the order including the coffee type.
  • Extract the coffee type on the transition between the two output nodes using a data action.

Create a flow variable

The flow variable we create here will later hold the coffee type that the user has mentioned:

  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 a variable and name it orderedCoffeeType.
  3. Put "" in the 'Evaluation Script' field. This initializes the variable with the empty string.

Add an additional output node

Now it's time to add an additional output node which will hold the summary of the user's order. Note that we add the newly created variable orderedCoffeeType to the output despite the fact that it has not yet received a value. This will happen in the next step below. First, we have to:

  1. Select the output node.
  2. Go to the top ribbon and add a new output node. It will be attached to the existing output node.
  3. Name this output node Summarize order.
  4. Select the 'Answer' field of the new output node and paste Ok, a ${orderedCoffeeType} will be ready for pickup in 5 minutes..

Configure the transition

The transition between the two output nodes should only be traversed if the user mentions a coffee type. In order to ensure that, we need to:

  1. Select the transition between the two output nodes.
  2. Name the transition User responds with coffee type.
  3. Go to 'Match Requirements' and click 'Add' and then 'Entity' from the drop-down menu.
  4. Enter COFFEES_SERVED in the Entity field. This means that Teneo will only continue when the user mentions something which matches the entity.

Extract information from the entity

Finally, we will store the coffee type that the user has mentioned in the flow variable orderedCoffeeType, and we will do so using a data action:

  1. Select the User responds with coffee type transition
  2. In the panel on the right, go to 'Data Actions', click 'Add' and hover over 'Entity' from the drop-down menu. When on the little triangle, all available entities will appear. Select COFFEES_SERVED.
  3. Now click into the 'Entity' field, which will make the 'Add Mapping' button clickable. Click the 'Add Mapping' button.
  4. The 'Source' field denotes the value of the NLU variable of the entity 'COFFEES_SERVED' that we want to store. In our case coffeeType.
  5. The 'Target' field denotes the name of the variable where the extracted value is to be stored. In our case orderedCoffeeType.
  6. Save the flow and you're done!

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 cappuccino, please.
Bot: Ok, a cappuccino will be ready for pickup in 5 minutes.

Test yourself

Now if you have done the previous test yourself there should be a working entity for Coffee Sizes. Add that entity here and don't forget to try it on Try Out.

What's next?

Next page is about Skipping Conditions In case the user already has mentioned the coffee type they're interested in before the bot.

Was this page helpful?