Scripts can be used to extend the functionality of an NLI application, providing it with capabilities that are not available out-of-the-box. For example, use scripts to look up information in internal resources, calculate values, test a condition, etc.
The scripting language used is Groovy and Teneo Studio provide basic support for Groovy syntax highlighting, including support for different identifiers (type name, literals, keywords, etc.).
Script code can be used in, for example:
- Script nodes
- TLML syntaxes
- Listener operations
- Skip condition expressions
- Prompt trigger expressions
- Global scripts
- Flow scripts
Ctrl+F: Find in scripts and TLML syntax editors
Pressing Ctrl+F will bring up a find text box, typing in the text box will find matching text in the editor and highlight it. Pressing the up and down buttons will navigate between the instances.
Indent/outdent in scripts and TLML syntax editors
Selecting some lines in a script or TLML syntax and pressing Tab or Shift+Tab, respectively indents or outdents the selected lines.
Script code in script nodes
It is possible to add programmatic functionalities to a flow by including a script node. The code in a script node has access to all global variables and to all flow variables of the current flow.
In the below image, the script node determines if today's date is prior to the release date of a game.
Embedded script in TLML syntax
It is possible to add embedded script code in the TLML syntax, as long as the user protects the code by surrounding it with curly brackets and makes sure that whatever is returned by the script code is either
In the below image, the syntax of a transition only evaluates to true if the variable
bAvailable has the value
Script code in listener operations
Listener operations expect programming code in Groovy.
When creating a skip condition, the expression that determines when to skip the output node is written in raw script code.
Note that it is necessary to declare a Variable and set up a Listener to use Skip Conditions.
Important: do not put curly brackets around the expression, or the skip condition will not work.
The above example means that the Output will be skipped when a Variable is filled with a certain value. The double equal sign is known as the compare operator; it compares the left operand to the right operand and returns
true if they are the same.
In the below image, the selected output node will be skipped if the flow variable
sDestType contains either of the values
It is possible to assign Boolean values to the Variable; for example, set it to
false and then create a Listener so that when a certain input is matched, the Variable value is set to
true, and then add a Skip Condition to the Output node which should be skipped when the Variable value is set to
Bear in mind that an empty variable, in Groovy, evaluates to
false and a non-empty string variable evaluates to
Prompt trigger expressions
Prompt triggers are not triggered by user input and therefore their triggering logic must be configured using programmatic code.
The below image displays a prompt trigger which will only trigger when the flow stack is empty and if more than 3 exchanges have taken place between the end-user and the chatbot application and if the value of the global variable
nAge (in which the end-user's age is stored) is higher than 17.
Flows can execute script code when they reach the top of the flow stack or when they are dropped off the flow stack. The scripts are a bit hidden: go to the backstage of the flow and click the Scripts tab.
In the below image, the Safetynet flow updates the global counter
nSafetyNetCounter and populates another global variable
sReviewReason with a string if the counter goes beyond 5.