Teneo Developers

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.

Global variable

Create a global variable

You can create global variables from the solution dashboard. In the Variables section in the Globals tile, click on the Add icon to add a new global variable. Give the variable a name, and assign it with a default value.

From the solution dashboard, you can also click on the arrow icon to view all existing global variables. From this view, you can click on the Create New Global Variable button to create a variable.

variables

Lifespan

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 would 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.

Flow Variable

Flow variables allow you to remember details during the processing of a flow. Anything you store in a flow variable will be forgotten once the flow has finished processing. If you want to share information between flows, you have to use global variables instead.

Create a Flow Variable

To create a flow variable you open a flow in 'Edit' mode, select the Variable icon under the minimap. Click on 'Add' and provide a name and a default value. In the example below, we have two variables, orderedCoffeeType and userNameForOrder, which both have an empty string "" as the default value.

variables-1

In Teneo, variables may be of any type that Groovy (and Java) supports, for example strings, booleans, maps, lists and custom objects. Its possible to populate and edit a variable In your flow, you can populate a flow variable using a script or you can store the results of an integration or a sub-flow in a 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.