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)
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
- Teneo Studio Desktop
- Teneo Studio Web
To add a Flow Listener, follow these steps:
- Click the Flow tab in the top of the Flow window to go to the backstage of the Flow.
- Select Listeners.
- Click Add in the top right corner.
- Give the Listener a name.
- Write the TLML Syntax which should be matched.
- Optionally, specify what the Execution Script (Groovy) should do.
- Select if the sentence should be tested from Last to first (default) or First to last.
- Check Limit unused words to and select the number if the number of unused words during the matching process should be limited.
- Stop after allows to select between First match, Current sentence tested and All sentences.
- Click OK when finished.
- Remember to Save the Flow to preserve the changes.
All Flow Listeners are also called Flow Post-Listeners in Teneo Studio Desktop, because they are executed after the Flow was triggered.
To add a Flow Listener simply follow the below steps:
- In the Flow editor, click the Listener button available in the left side of the Flow window.
- Click the Plus icon to add a listener.
- Give the Listener a name in the first text box.
- Now write the TLML Syntax needed for If Input Matches.
- Optionally, Execute should be filled out with the Groovy code to execute.
- Click Confirm to close the Listener editor.
- Remember to Save the Flow to preserve the changes.
Edit
- Teneo Studio Desktop
- Teneo Studio Web
To edit a Flow Listener, follow the below steps:
- Click the Flow tab in the top of the Flow window to go to the backstage of the Flow.
- Select Listeners.
- Select the Listener to edit and click Edit in the top right corner.
- Now modify the wanted specifications.
- Click OK.
- Remember to Save the Flow to preserve the changes.
To edit a Flow Listener, follow the below steps:
- Click the Listener button.
- Next to the name of an existing Listener, click the pencil icon.
- Now, modify the wanted specifications.
- Click Confirm.
- Remember to Save the Flow to preserve the changes.
Delete
- Teneo Studio Desktop
- Teneo Studio Web
To delete a Flow Listener, follow the below steps:
- Click the Flow tab in the top of the Flow window to go to the backstage of the Flow.
- Select Listeners.
- Select the Listener to delete and click Delete in the top right corner.
- Remember to Save the Flow to preserve the changes.
To delete a Flow Listener, follow the below steps:
- Click the Listener button
- Next to the name of an existing Listener, click the Recycle bin.
- Remember to Save the Flow to preserve the changes.
UI
- Teneo Studio Desktop
- Teneo Studio Web
Listeners Backstage View

| Item | Description | Related Pages |
|---|---|---|
| Listeners tab | Shows all Flow Listeners and Global Listeners in a Flow. | Global Listeners |
| Add | Opens a new window to add a new Listener. | Add |
| Edit | Opens a new window to edit the selected Listener. | Edit |
| Delete | Deletes selected Listener. | Delete |
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

| Item | Description | Related Pages |
|---|---|---|
| Name | Adds name for Listener. | |
| TLML Syntax | Defines TLML Syntax for matching. | TLML Syntax match TLML |
| Execution Script | An optional groovy script that will be executed if TLML Syntax matches. | Execution script Groovy |
| Test sentences from | Selects how sentences in input are tested. | |
| Limit unused words to | Specifies 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).
Flow Listener Window

| Item | Description | Related Pages |
|---|---|---|
| Add Name | Adds name for Listener. | |
| If input matches (TLML) | Defines TLML Syntax for matching. | TLML Syntax match TLMLadd link) |
| Then execute (Groovy) | An optional groovy script that will be executed if TLML Syntax matches. | Execution script Groovy |
Practical Examples
Slot filling
The following example demonstrates how to accomplish slot filling in a flow by accessing and propagating Entity variables.
- Teneo Studio Desktop
- Teneo Studio Web
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.

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:
- All entries of BEVERAGES_SERVED.ENTITY are searched through to match the user input.
- A match is found in the language object AMERICANO.NN.LEX of the nested entity COFFEES_SERVED.ENTITY.
- The value "americano" of the entity variable coffeeType is propagated up to the entity variable beverageType.
- The value of the variable beverageType is accessed via the propagation script in the listener condition and assigned to the flow variable orderedCoffeeType.

You can use a Flow Listener to access Entity variables and propagate them. In this Flow Listener, the Flow Variable orderedBeverage is assigned an entity variable lob.beverageType. This lob points to the language object (hence lob) to which the script has been attached to, BEVERAGES_SERVED.ENTITY, and retrieves the value of the entity variable beverageType.

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:
- All entries of BEVERAGES_SERVED.ENTITY are searched through to match the user input.
- A match is found in the language object AMERICANO.NN.LEX of the nested entity COFFEES_SERVED.ENTITY.
- The value "americano" of the entity variable coffeeType is propagated up to the entity variable beverageType.
- The value of the variable beverageType is accessed via the propagation script in the listener condition and assigned to the flow variable orderedCoffeeType.
