Skip to main content

Flow Listeners

Flow Listeners help your bot pick up relevant pieces of information, such as Entities, from user inputs within the Flow, even when these have not been explicitly prompted for. Listeners are useful as tools for slot filling within a Flow.

The sections on this page provide information about the various aspects of Flow Listeners:

Concept

Flow Listeners help your bot pick up relevant pieces of information, such as Entities, from user inputs within the Flow, even when these have not been explicitly prompted for. You can think of a Listener as a fly on the wall, silently listening and registering things, or as a tool for slot filling within a Flow.

As opposed to Global Listeners, Flow Listeners work on a Flow level, listening for all inputs that trigger or pass through the Flow.

A Flow Listener is made up of two parts: a TLML Syntax, which determines what patterns should be listened for, and an optional execution script, which defines what should happen when the TLML Syntax matches.

For example, you may have a Listener where:

  • The TLML Syntax is set to match the name of a city, e.g. %TO.FW.LEX >> %CITY.ENTITY^{destination = lob.city}
  • The Execution Script then finds airports close to the city, e.g. nearbyAirports = AirportChecker.findAirports(destination)
LISTENER FOR A SPECIFIC NODE

If you need to extract information from a particular trigger or transition, you should use a Listener After Match instead.

In general, if you do not know what you want to extract from the user input and when you want to extract it in the Flow, it is a good idea to use a Flow Listener. Additionally, you want to use a Flow Listener if...

  • The user input contains information that the bot has not yet asked for.
  • You find yourself creating the same Listener After Match on multiple triggers or transitions.

A powerful way to add programmatic logic to your solution is to combine propagation scripts with Flow Listeners. This enables you to extract the information you need at any point of the conversation and to propagate the value to a Global Listener so that the value can be used in the entire solution.

Please see below how to add, edit, and delete a Flow Listener.

How To

Add

To add a Flow Listener, follow these steps:

  1. Click the Flow tab in the top of the Flow window to go to the backstage of the Flow.
  2. Select Listeners.
  3. Click Add in the top right corner.
  4. Give the Listener a name.
  5. Write the TLML Syntax which should be matched.
  6. Optionally, specify what the Execution Script (Groovy) should do.
  7. Select if the sentence should be tested from Last to first (default) or First to last.
  8. Check Limit unused words to and select the number if the number of unused words during the matching process should be limited.
  9. Stop after allows to select between First match, Current sentence tested and All sentences.
  10. Click OK when finished.
  11. Remember to Save the Flow to preserve the changes.
info

All Flow Listeners are also called Flow Post-Listeners in Teneo Studio Desktop, because they are executed after the Flow was triggered.

Edit

To edit a Flow Listener, follow the below steps:

  1. Click the Flow tab in the top of the Flow window to go to the backstage of the Flow.
  2. Select Listeners.
  3. Select the Listener to edit and click Edit in the top right corner.
  4. Now modify the wanted specifications.
  5. Click OK.
  6. Remember to Save the Flow to preserve the changes.

Delete

To delete a Flow Listener, follow the below steps:

  1. Click the Flow tab in the top of the Flow window to go to the backstage of the Flow.
  2. Select Listeners.
  3. Select the Listener to delete and click Delete in the top right corner.
  4. Remember to Save the Flow to preserve the changes.

UI

Listeners Backstage View

ItemDescriptionRelated Pages
Listeners tabShows all Flow Listeners and Global Listeners in a Flow.Global Listeners
AddOpens a new window to add a new Listener.Add
EditOpens a new window to edit the selected Listener.Edit
DeleteDeletes selected Listener.Delete
info

All Flow Listeners are also called Flow Post-Listeners in Teneo Studio Desktop, because they are executed after the Flow was triggered.

Flow Listener Window

ItemDescriptionRelated Pages
NameAdds name for Listener.
TLML SyntaxDefines TLML Syntax for matching.TLML Syntax match
TLML
Execution ScriptAn optional groovy script that will be executed if TLML Syntax matches.Execution script
Groovy
Test sentences fromSelects how sentences in input are tested.
Limit unused words toSpecifies a maximum number of words which the user input may contain (beside those matching the TLML syntax) for the match to be satisfied. The Listener will only execute if the TLML Syntax has fewer unused words than the defined limit.
Stop after*Determines when TLML Syntax will stop evaluating.

*The Teneo Engine stops testing sentences and user inputs once a match is found, but the Stop after setting allows to modify this behavior providing the following options:

  • First match (Default): testing is stopped when a match is found
  • All sentences tested: the TLML Syntax of the Global Listener is tested against all the sentences in the user input creating an array of results
  • Current sentences tested (only Post-Listeners): the TLML Syntax of the Global Listener attempts to match against the most recent syntax (the previous trigger or input consuming transition).

Practical Examples

Slot filling

The following example demonstrates how to accomplish slot filling in a flow by accessing and propagating Entity variables.

You can use a Flow Listener with an attached script to access Entity variables and propagate their values to Global or Flow variables. Propagation scripts attached directly to a Language Object/Entity reference in any TLML syntax have access to a special read-only variable called lob. This lob variable is a read-only map containing the NLU variable values for that Language Object/Entity.

In this Flow Listener, the Flow Variable orderedBeverage retrieves the value of the Entity variable lob.beverageType from the Entity BEVERAGES_SERVED.ENTITY.

flow listener

So for example, if the user input is 'I want an Americano', then the value 'americano' will be assigned to the flow variable orderedBeverage.

What happens is the following:

  1. All entries of BEVERAGES_SERVED.ENTITY are searched through to match the user input.
  2. A match is found in the language object AMERICANO.NN.LEX of the nested entity COFFEES_SERVED.ENTITY.
  3. The value "americano" of the entity variable coffeeType is propagated up to the entity variable beverageType.
  4. The value of the variable beverageType is accessed via the propagation script in the listener condition and assigned to the flow variable orderedCoffeeType.

value propagation