Use listeners

Listeners can be used in multiple ways in Teneo. For this example, we will demonstrate one way of using a listener inside a flow. In the previous page on how to handle ambigous inputs, we demonstrated a way to handle partial understanding and catch keywords. Adding on to that, we will now add a listener to recognize if a coffee type is mentioned and the user wants to order it.

Before our changes, we would have a conversation like this:

User: espresso
Bot: You're talking about coffee. Would you please tell me what you wanted exactly? Did you want to order a coffee or see our selection coffees?

User: order
Bot: Ok, what coffee would you like?

After our modifications, it will look like this:

User: espresso
Bot: You're talking about coffee. Would you please tell me what you wanted exactly? Did you want to order a coffee or see our selection coffees?

User: order
Bot: Ok, a espresso will be ready for pickup in 5 minutes.

To achieve this we need to do the following:

Create a flow variable

Let us start off by opening the Partial Understanding: Coffee flow and creating a new flow variable to store the coffee type mentioned by the user.

  1. Open the Partial Understanding: Coffee flow in edit mode.
  2. While inside the flow, click on the 'Flow' button located in the top left corner.
  3. Navigate to 'Variables' in the left sidebar and add a new variable that has the name coffeeType and the value "".

Create a flow listener

Now it is time to add a flow listener to listen for the coffee type. We will also use the previously created COFFEES_SERVED.ENTITY for the condition.

  1. While inside the 'Variables' section, switch over to 'Listeners' located one step down in the sidebar.
  2. Click on the green 'Add' button. This will open up a new flow listener.
  3. Name the listener Listen for coffee types.
  4. In the condition field, paste in the following: %COFFEES_SERVED.ENTITY^{coffeeType = lob.coffeeType}.

This can also be done by adding an Entity Match Requirement to the intent trigger.

The next step is to modify the flow link to send over the flow variable that stores the mentioned coffee type to the 'User wants to order a coffee' flow.

  1. Go back to the flow's main window.
  2. While inside the flow, select the flow node 'User wants to order a coffee'. This will open the Flow Link configuration panel to the right.
  3. Navigate to the 'Target' section and select the white drop-down menu right beside 'orderedCoffeeType'.
  4. From the drop-down menu, select the previously created flow variable 'coffeeType'. This will send the value from this flow variable to the 'orderedCoffeeType' flow variable inside 'User wants to order a coffee'.
  5. Save the flow.

Try it out

Let's go ahead and test the modified flow by mentioning a coffee type:

User: espresso
Bot: You're talking about coffee. Would you please tell me what you wanted exactly? Did you want to order a coffee or see our selection coffees?

User: order
Bot: Ok, a espresso will be ready for pickup in 5 minutes.

What's next?

Now that we are done with the Conversations chapter, we will move on to Language Understanding to learn more about different languages and the hybrid approach of Teneo.

Was this page helpful?