Variables

Just as variables are important for programming in general, they are important when building bots. Not least, your bot's memory will rely on what is stored in variables.

Data types

In Teneo, variables may be of any type that Groovy or Java support. For example strings, booleans, maps, lists and custom objects.

Scopes

Variables may be created with three different scopes in Teneo:

  • Global variables: accessible from all flows, listeners and script events in your solution (except solution loaded).
  • Flow variables: accessible from the flow they belong to.
  • Local script variables: accessible in the local script.

There are also a special kind of variables, called entity variables, that belong to Language Objects and Entities.

Global Variables

You create global variables in the main solution window. Open the 'Solution' tab, select 'Globals' in the purple navigation bar. Then select 'Variables', and click 'Add' in the upper right corner. Give the variable a name, and assign a default value.

global variable

Lifespan

By default, a global variable assignment lives for the entire session or until it's reset. You can however make a global variable forget the value after a specified number of turns. The variable will then be cleared and get back its default value. In Teneo this is called 'setting the lifespan' of a variable. A common use-case for this is to remember something the user says in one flow, so that it can be used in the trigger of another flow. You can read more about how to keep to track of conversational context using global variables here: How to share information between flows.

If you have a global variable called topic you set set its lifespan like so:

_.setSessVarLifespan('topic', 2) 

In this example, the lifespan is set to two turns, but you are free to choose whatever value you see fit. Note, however, that the lifespan includes the request/input that is currently being processed.

Flow variables

Flow variables live as long as the flow they belong to.

To create a flow variable you first need to open the flow. Go to its 'FLOW' tab and select 'Variables' in the purple navigation bar. Click on 'Add' in the upper right corner, and provide a name and a default value.

flow variable

Local variables

Local variables are only available in the script node (or script event) in which you created them. You must define or specify the type of the local variable like so: def name = "Guillaume". You can see an example of a script with local variables here: How to add a script to your flow.

Was this page helpful?