Skip to main content

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.

Flow Script vs script node

A Flow Script should not be confused with a script node, which is executed in the middle of a Flow.

How To

Add

To add a Flow Script, follow the below steps:

  1. With the Flow open, click the Scripts button in the left hand side of the window.
  2. In the editor, write the On top and/or the On drop script.
  3. Click Confirm.
  4. Remember to Save the Flow to preserve the changes.
LARGER EDITOR

Clicking the Expand option in the lower right corner of the script editor allows to open the script editor in a bigger view.

Edit

To edit an existing Flow Script, simply follow the below steps:

  1. With the Flow open, click the Scripts button in the left hand side of the window.
  2. Now, edit the wanted script (either On top or On drop).
  3. Click Confirm.
  4. Remember to Save the Flow to preserve the changes.
LARGER EDITOR

Clicking the Expand option in the lower right corner of the script editor allows to open the script editor in a bigger view.

Delete

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

The Flow Scripts can accessed by selecting a Flow in the dashboard:

web flow scripts

Flow ScriptDescriptionRelated Pages
On topFlow 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 FlowScripting
Flow stack
On dropFlow 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 / CancelConfirm 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.

note

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:

  1. Open your Flow in edit mode.
  2. Click on the 'Flow' tab.
  3. Select 'Scripts', and then click 'On Drop'.
  4. 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)

  5. Hit 'Save' and close the flow.

Make sure a Flow populates the Global Variable

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:

  1. Open a Flow in edit mode.
  2. Click on the Plus icon next to the trigger and add a new Intent Trigger. This will add an additional trigger to the Flow.
  3. Name the trigger and add a few example intents.
  4. 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 }
  1. Now we will add the context restriction. Click on 'Add' in the Match section.
  2. Select 'Global Variable' and select the Global Variable that you created earlier.
  3. 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!