Flow Scripts
Flow Scripts are fully customizable scripts that can perform multiple actions, such as handle Flow and Global Variables. Please see scripting for more information on scripts.
The sections on this page cover the following topics related to Flow Scripts:
Concept
Flow Scripts are fully customizable scripts that can perform multiple actions, such as handle Flow and Global Variables. The scripting language in Teneo Studio is Groovy, and Teneo Studio provides basic support for syntax highlighting
They are executed when...
- The Flow reaches the flow stack.
- The Flow is dropped off the flow stack.
For example, this Flow Script stores a Flow Variable in a Global Variable and gives it a lifespan of two sessions:
// Save flow variable coffeeSuggestion in global variable coffeeTypeInFocus
coffeeTypeInFocus = coffeeSuggestion
// Set the lifespan of the global variable
_.setSessVarLifespan('coffeeTypeInFocus',2)
There are two types of Flow Scripts:
- On top Flow Scripts are executed when the Flow containing the script reaches the flow stack, either by being triggered or by regaining the top position after being interrupted by the triggering of another Flow.
- On drop Flow Scripts are executed when the Flow containing the script is dropped off the flow stack, either because the Flow has reached its end and is finished or because it becomes "stuck".
The On top and On drop scripts are executed when they reach the top of the flow stack or when dropped off the flow stack. You may, however, want to execute a script at a specific point in a Flow. In that case, you can use a script node. If it is a script you need to execute regularly in different Flows, you can consider storing it in an Integration.
A Flow Script should not be confused with a script node, which is executed in the middle of a Flow.
How To
Add
- Teneo Studio Desktop
- Teneo Studio Web
To add a Flow Script, follow the below steps:
- With the Flow open, click the Flow tab to go to the backstage of the Flow
- Select Scripts.
- Select if the script should be of type On top or On drop.
- In the script editor write the script syntax.
- Remember to Save the Flow to preserve the changes.
Open with... allows to select an external script editor to edit the Flow script. When scripts are edited in an external editor, the Flow's script editor is updated with the new, modified script once the user saves the changes in the external editor, but the changes are not saved in the Flow until the user also clicks Save in the Flow.
To add a Flow Script, follow the below steps:
- With the Flow open, click the Scripts button in the left hand side of the window.
- In the editor, write the On top and/or the On drop script.
- Click Confirm.
- Remember to Save the Flow to preserve the changes.
Clicking the Expand option in the lower right corner of the script editor allows to open the script editor in a bigger view.
Edit
- Teneo Studio Desktop
- Teneo Studio Web
To edit a Flow Script:
- With the Flow open, click the Flow tab to go to the backstage of the Flow.
- Select Scripts.
- Now, perform the needed edits in the On top and/or On drop script.
- Remember to Save the Flow to preserve the changes.
Open with... allows to select an external script editor to edit the Flow script. When scripts are edited in an external editor, the Flow's script editor is updated with the new, modified script ones the user saves the changes in the external editor, but the changes are not saved to the Flow until the user also clicks Save in the Flow.
To edit an existing Flow Script, simply follow the below steps:
- With the Flow open, click the Scripts button in the left hand side of the window.
- Now, edit the wanted script (either On top or On drop).
- Click Confirm.
- Remember to Save the Flow to preserve the changes.
Clicking the Expand option in the lower right corner of the script editor allows to open the script editor in a bigger view.
Delete
- Teneo Studio Desktop
- Teneo Studio Web
There is no Delete button available to remove an entire Flow Script. If the user needs to delete a script, the only option is to manually highlighting the entire script expression, pressing Delete on the keyboard, and leaving the script editor empty.
Remember to save the Flow to preserve the changes.
There is no Delete button available to remove an entire Flow Script. If the user needs to delete a script, the only option is to manually highlighting the entire script expression, pressing Delete on the keyboard, and leaving the script editor empty.
Remember to save the Flow to preserve the changes.
UI
Flow scripts overview
- Teneo Studio Desktop
- Teneo Studio Web
The Flow Scripts can be accessed by selecting the 'Flow' tab after opening a Flow:

| Flow Script | Description | Related Pages |
|---|---|---|
| On top | Flow Scripts are executed when the Flow containing the script reaches the flow stack, either by being triggered or by regaining the top position after being interrupted by the triggering of another Flow. | Scripting Flow stack |
| On drop | Flow Scripts are executed when the Flow containing the script is dropped off the flow stack, either because the Flow has reached its end and is finished or because it becomes "stuck". | Scripting Flow stack |
| Open with... | Allows to open the script in an external editor; if an editor was previously selected the script will automatically open in the preselected editor when the button is clicked. |
The Flow Scripts can accessed by selecting a Flow in the dashboard:

| Flow Script | Description | Related Pages |
|---|---|---|
| On top | Flow Scripts are executed when the Flow containing the script reaches the flow stack, either by being triggered or by regaining the top position after being interrupted by the triggering of another Flow | Scripting Flow stack |
| On drop | Flow Scripts are executed when the Flow containing the script is dropped off the flow stack, either because the Flow has reached its end and is finished or because it becomes "stuck". | Scripting Flow stack |
| Confirm / Cancel | Confirm the script and proceed to Save the Flow, or Cancel to omit the changes. |
Practical Examples
Share Information between Flows
Just as in human conversations, the user will assume your bot remembers what they recently have been talking about. Using Flow Scripts, you can make sure your bot remembers information from one Flow to another. This logic can be applied to a variety of contexts.
Consider the following conversation with a coffee shop bot:
User: Which coffee would you recommend? (Flow 1, handling logic to recommend coffees)
Bot: Easy choice, a flat white of course!
User: I'll go for one of those then. (Flow 2, handling logic to take coffee orders)
Bot: Ok, a flat white will be ready for pickup in 5 minutes.
To make sure a Global Variable works in two Flows, you should:
- Create a Global Variable and Flow Variable.
- Assign Flow Variable to Global Variable.
- Make sure a Flow populates the Global Variable.
- Make sure another Flow retrieves the Global Variable and triggers on inputs.
Assign Flow Variable to Global Variable.
- Teneo Studio Desktop
- Teneo Studio Web
This example assumes you have already created a Flow Variable and a [Global Variable].
To assign a Flow Variable value to a Global Variable, we will add an 'On Drop' Flow script:
- Open your Flow in edit mode.
- Click on the 'Flow' tab.
- Select 'Scripts', and then click 'On Drop'.
- Populate the script field with the following lines and your Flow Variable name and Global Variable name.
// Save flow variable in global variable
globalVariableName = flowVariableName
// Set the lifespan of the global variable
_.setSessVarLifespan('globalVariableName',2) - Hit 'Save' and close the flow.
This example assumes you have a Flow Variable which you want to turn into a Global Variable.
To assign a Flow Variable value to a Global Variable, we will add an 'On Drop' Flow script:
- Open a Flow.
- Click on the Scripts button.
- Populate the script field with the following lines and your Flow Variable name and Global Variable name.
// Save flow variable coffeeSuggestion in global variable coffeeTypeInFocus
coffeeTypeInFocus = coffeeSuggestion
// Set the lifespan of the global variable
_.setSessVarLifespan('coffeeTypeInFocus',2) - Hit 'Confirm' and save the Flow.
Make sure a Flow populates the Global Variable
- Teneo Studio Desktop
- Teneo Studio Web
We then need to make sure the Flow uses the Global Variable. First, we need to make sure that the Flow triggers on inputs referring to the Global Variable, such as "I'll go for one of those then".
Let's create a trigger with a context restriction and a Global Variable:
- Open a Flow in edit mode.
- Click on the Plus icon next to the trigger and add a new Intent Trigger. This will add an additional trigger to the Flow.
- Name the trigger and add a few example intents.
- Add a Match for 'TLML Syntax' and define the inputs that should be linked to the Global Variable.
This could look something like the following syntax, where references like "one of those" or "it" are linked to the Global Variable coffeeTypeInFocus:
(
(%I.FW.LEX &^ %WANT.VB.LEX &^ (one/%IT.FW.LEX))
/
(%I_WILL.PHR &^ %GO_FOR.VB.MUL &^ %IT.FW.SYN)
)^{ orderedCoffeeType = coffeeTypeInFocus }
- Now we will add the context restriction. Click on 'Add' in the Match section.
- Select 'Global Variable' and select the Global Variable that you created earlier.
- Hit 'Save'.
We then need to make sure the Flow uses the Global Variable. First, we need to make sure that the Flow triggers on inputs referring to the Global Variable, such as "I'll go for one of those then".
Let's create a trigger with a context restriction and a Global Variable:
-
Open a Flow.
-
Click on the Plus icon next to the trigger and add a new trigger based on intent.
-
Name the trigger and add a few example intents.
-
Beneath this new trigger, click on the Plus icon and add a Match for 'TLML Syntax'. Define the inputs that should be linked to the Global Variable.
This could look something like the following syntax, where references like "one of those" or "it" are linked to the Global Variable
coffeeTypeInFocus:
(
(%I.FW.LEX &^ %WANT.VB.LEX &^ (one/%IT.FW.LEX))
/
(%I_WILL.PHR &^ %GO_FOR.VB.MUL &^ %IT.FW.SYN)
)^{ orderedCoffeeType = coffeeTypeInFocus }
- Now we will add the context restriction. Click on 'Add match requirement' at the bottom of the new Match node.
- Select 'Global Variable' and, in the dropdown, select the Global Variable that we created earlier.
- Hit 'Save'.
Populate the Flow Variable with a Script
We need to populate the Flow Variable with the value stored in the Global Variable when the new trigger kicks in. This can be done by either using an Attached script or a Listener. Here we will go for the former and attach a script to the trigger's TLML.
An attached script is executed when the TLML syntax matches the input. The Flow Variable will therefore be set to the value of the Global Variable when the TLML syntax is evaluated to true and our new trigger kicks in. This way, we can skip the questions we already have answers to, such as "what coffee type do you want" (see the conversation in Share Information between Flows).
Try it out!
That's it! Now go ahead and give it a try in Tryout!