Teneo Developers

Theory/Core Concepts

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 in the main solution window. Open the 'Solution' tab and select 'Globals'. Then select 'Variables' at the top, and click 'Add' in the upper right corner. Give the variable a name, and assign it with a default value.

1-global vars

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 your bot 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, open a flow in 'Edit' mode, go to the 'FLOW' tab and select 'Variables'. 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, including strings, booleans, maps, lists, and custom objects. It's 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.

Next page
Sub-Flows
Was this page helpful?