Teneo Developers

Adapt to user input

Sometimes the user tells you the answer to certain questions earlier than expected. To make conversations flow more naturally, we can tell the bot not to ask questions it has already received answers to. We will do this by adding a Match requirement stating we will only ask the relevant question if the bot has not already received the answer. Otherwise, an additional path will skip the question.

Before adding the additional path:

User: I'd like to order a Cappuccino
Bot: Ok, what coffee would you like?
User: I already told you, a Cappuccino!
Bot: Ok, a cappuccino will be ready for pickup in 5 minutes.

After adding the additional path:

User: I'd like to order a Cappuccino.
Bot: Ok, a cappuccino will be ready for pickup in 5 minutes.

Extract entities from the first input

Currently, the first stage of the 'User wants to order a coffee' flow does not extract the coffee type entity if mentioned in the first input. To do that, we need to add another After Match on entities but this time for the trigger:

  1. Open the 'User wants to order a coffee' flow.
  2. Under the first User Intent node, 'Order a Coffee', click on the Plus icon followed by 'After Match' and 'Entity'. We will use this to extract values from our previously created entity.
  3. Select the entity COFFEES_SERVED.ENTITY.
  4. Click on 'Add Variable Mapping' below the entity name.
  5. Now use the drop-down menu below to determine the source coffeeType and the target orderedCoffeeType. This transfers the value from the source and assigns it to the target.

Specify when output should be given

Now it's time to add a new path to avoid asking the user for the coffee type if the user has already mentioned it in their first input.

  1. Click on the Plus icon above 'Ask for coffee type', followed by 'Continue with' and 'Junction'.
  2. Click on the Plus icon above 'Ask for coffee type' again, this time selecting 'Match' and 'Flow variable'.
  3. In the dropdown menu, select 'orderedCoffeeType'.
  4. Into the evaluation script, paste "".

The existing path will now only be executed if the value of the 'orderedCoffeeType' variable is empty. Let's add the path we want the bot to take if the variable has already been assigned a value in the After Match where we pick up a coffee type from the user's first input.

  1. Hover over the arrow beneath the junction that does not go to the existing path. You should see a small green dot.
  2. Click and drag to create a new path from the junction to the 'Summarize order' node.
  3. Hit 'Save'.

To summarize, what we have done here is to check whether the first user input contains a coffee type and, if it does, store that in the 'orderedCoffeeType' variable. After the junction, we then either ask the user what coffee type they want, if we haven't already extracted this, or we skip ahead to summarizing the order, if we have extracted it.

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.

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

User: I'd like to order a cappuccino.
Bot: Ok, a cappuccino will be ready for pickup in 5 minutes.