Teneo Developers

Variables and Listeners

How do Variables and Listeners work?

Teneo Studio allows to use Listeners and Variables in order to provide a conversational AI application with memory and context.

Listeners are often used to populate a Variable with a certain value if a specific (language) condition is met in the user input. Then, the value that was stored in the Variable can be used in the logic of the conversation. For example, capture the visitor's name using a Listener and then use the stored name in the application's response, saying things like Nice to meet you, Jane.

Variables and Listeners are closely connected; a Variable with an empty value must be declared so that a Listener can access it in its operation. This way, when the condition of a Listener is fulfilled (usually when a certain user input is found), the operation of the Listener will be able to assign a certain value to the Variable. The Variable could then be used in the answers given by the AI application.

Capture info from user input

  • Declare a Global or Flow Variable with an empty value ""
  • Add a Listener, which will listen for the expected input
  • When the user input is recognized in the dialogue, the Listener will populate the Variable with that value
  • Use the Variable in answer text; this way the AI application will seem to remember or acknowledge what the user said.

The below Flow captures user inputs where people say they like a specific planet, for example I like Venus or I like Mars.

The name of the mentioned planet is stored in the Variable sPlanetMetioned

The answer text uses the Variable as follows:
So you like ${sPlanetMentioned}? I am a big fan of Mars

Below image visualizes how the Data Action Listener of this example is set up:

Instead of using getUsedWords(), it is also possible to use getLangObjVariable('<var_name>').

Listener types

There are several types of Listeners available in Teneo Studio and depending on where in the solution it is needed to listen for user input, the below types of Listeners can be used.

  • A Global Listener listens for user input anywhere in the solution. This type of Listener can be used when wanting to listen for certain user input regardless of the Flow or Transition; it is possible to add both Global Pre-Listeners and Global Post-Listeners.
  • A Flow Post-Listener is used when only wanting to listen for user input in a certain Flow. This is useful to not overload the solution unnecessarily with Global Listeners.
  • Transition / Intent Trigger Post-Listener or Data Action Listener only affect one of the Transitions (or Intent Triggers) in the Flow. Again, these types of Listeners will prevent overloading the solution with Global Listeners when not needed.

When a transition is reached, all the configured Listeners that are in the scope will be checked in order. First Global Pre-Listeners will be checked, then Global Post-Listeners, then Flow Post-Listeners (configured in the current Flow) and finally, Transition/Intent Trigger Post-Listeners. Each Listener whose condition is met will be executed.

The script code in the operation of a Listener has access to all Global Variables and to the Flow variables of the current Flow (if this is a non-Global Listener). Flow Listeners furthermore read from and write to Global Variables.

Global Listeners

Global Listeners allow to choose their execution order by either selecting Global Pre-Listener or Post-Listener.

The Listeners are executed in a certain order; when a user input comes in, Global Pre-Listeners will be run first. Then, the Engine will match the input against a Flow transition or Flow Trigger, and after that it will execute Global Post-Listeners, Flow Post-Listeners and Intent Trigger/Transition Post-Listeners (Data Action Listeners). The matching Flow Transition or Trigger might depend on the Global Pre-Listeners set.

Pre-Listeners are run before the user input is tested against Flow Intent Triggers, so if the user input matches against the condition of a Global Pre-Listener, the Listener's operation will be executed immediately, before any Flow is triggered.

However, if using Global Post-Listeners, the Listener's operation is executed after the Flow is triggered. Using Pre-Listeners is useful when wanting something to happen before the Flow is triggered.

For example, if having two different Flows for the same user input, use a Global Pre-Listener for bad language to trigger one of those Flows first if bad language is used.

Or use a Post-Listener to perform a task after a user input has triggered a Flow that resides in a specific Flow folder; in this scenario, the Listener condition would be a script condition checking, for example, if the currently triggered Flow was stored in the Summer Campaign folder, and if true, the Listener would then perform the task specified in the Listener's operation.

Naming conventions for Variables

Variables are placeholders for changeable values and can be used to store text strings, Boolean, Lists, Maps (key/value pairs) and numbers.

A Variable needs to have a unique name and the following conventions are recommended when naming Variables.

The Variable name starts with a lowercase character, indicating the type of information that the Variable contains:

  • "s": used for strings
  • "b": used for Boolean
  • "n" or "i": used for numbers
  • "l": used for lists
  • "ss": used for lists containing strings
  • "nn" or "ii": used for lists containing numbers
  • "bb": used for lists containing Booleans
  • "m": used for maps

When using multiple words in a Variable name, the words should be concatenated with no separating characters between them. The first letter of each word should be capitalized, for example: sUserName, sCompanyName, nHour or iHour.

Global Variables coming with a Teneo Dialogue Resource are prefixed withLib_.

Scripts in Teneo solutions
Global Context
NLU Variables
Listeners and Variables in the User Guide
Language Object Variables
Global Variables available in Teneo Dialogue Resources