Global variables

Variables are important when building bots. Not least, your bot's memory will rely on what is stored in variables. Global variables in Teneo are accessible from all flows, script nodes in flows, listeners and most script events in your solution. In that way, they differ from flow variables, which only exist during the processing of a flow, and will be forgotten as soon as a flow is dropped from the flow stack.

Create a global variable

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

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


By default, the value of a global variable lives for the entire session, or until it's reset. You can however make a global variable forget its 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 is to remember something the user says in one flow, so that it can be used in another flow.

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

_.setSessVarLifespan('topic', 2) 

You would typically set the value of the variable at the end of a flow and at the same time set its lifespan. 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. Each subsequent request (or input or turn) will consume one of the lifespans and when the lifespan reaches 0, topic will be reset to the value that was used when it was initialized. However, any flow can overwrite the value of the global variable at any time and give it a new lifespan.

Was this page helpful?