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

Global Variable

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 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, go to the 'FLOW' tab of a flow and select 'Variables' in the navigation bar on the left. Click on 'Add' in the upper right corner, and provide a name and a default value. In the example below, we have two variables, flavor and size, which both have an empty string "" as the default value.

Flow Variable

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.

Was this page helpful?