Teneo Developers

Global Scripts

Introduction

A script is a text with a defined syntax in which a sequence of instructions is given to the conversational AI application. Data resulting from a conversation (session) between the AI application and an end-user can be processed further in scripts.

An essential function of scripts is the administration of script Variables. Variables are placeholders for changeable values and they have a unique name. Script Variables must be declared before their use. Script Variables retain their value during the predefined scope, which is valid during the entire session in the case of Global Variables.

The scripting language in Teneo is Groovy.

Session scripts versus Engine Scripts

There are two kinds of scripts available in Teneo Studio Session scripts and Engine scripts.

The Session scripts have read and write access to session data, read-only access to solution data and are connected to and occur within the scope of a session (or dialogue with an end-user). Furthermore Session scripts can control and manipulate input processing.

The Engine scripts have read and write access to solution data and are not connected to nor have access to any particular session.

Session scripts

The Session scripts include the following scripts:

  • Begin dialog: scripts here will be executed at session start.
  • The New session script runs following the Begin dialog script, subsequent to the beginning of a new session started by a new user. If the session was started by a user whose session was timed out, the Timed-out session script will run instead.
  • The Timed-out session script will run when an end-user, whose session timed out, resumes the dialogue with the AI application. Usually, a session will time out after 10 minutes of inactivity.
  • The Pre-processing script runs before the sentences in the user input are separated for processing (before simplification). In the Pre-processing Global Script, the user input string can be manipulated before Engine tests it against flow triggers or transitions. A more common use of the pre-processing script is to access other elements of the incoming http request than the user input string.
  • The Pre-matching scripts are run before matching, but after the input is separated into words.
  • Post-processing scripts are executed after the AI application has created a response, consisting of output text, emotion and output parameters, but before the response is sent into cyberspace. The post-processing script makes it possible to change the response data.
  • End dialog scripts will be executed once, at the end of each session; for example, (Database Connections) "Close all database connections".
  • Pre-logging: allows for (partial) access to the dialogue history through engineAccess and is executed after a session has completed, after End dialog, but before the data is written to the logs. The Pre-logging script allows to modify, for example, input/output text, input/output parameter values, and Variable values.
  • On top: the scripts here will be executed whenever a flow reaches the top of the flow stack (either by being triggered or by regaining the top position after being interrupted by the triggering of another flow).
  • On drop: the scripts here will be executed when a flow is finished and the task is removed.

Engine scripts

There are two available options for Engine scripts:

  • Solution loaded: this script runs once subsequent to loading of the knowledge base (the solution). It usually contains definitions of utility functions that are called from other script locations. This is where general scripting functionalities are written.
  • Solution unloaded: this script runs once directly before the knowledge base (the solution) is unloaded.

Add Global Script

To add a Global Script in the solution, follow the below steps:

  • Click the Solution tab, in the main Teneo Studio window, to go to the backstage
  • Then select Globals and finally Scripts
  • Select the script to add, and click the Add button next to the script, or in the right side area of the screen
  • The Script window will open, now enter the script and remember to click Save when done to preserve the changes.

Edit Global Script

To manage Global Scripts in the solution, follow the below steps:

  • Click the Solution tab, in the main Teneo Studio window to go to the backstage
  • Then select Globals and finally Scripts
  • Select the script to edit, and click Edit in the panel in the right side of the window
  • The Script window will open, now enter the script and remember to click Save when done to preserve the changes.

The buttonOpen with... in the top ribbon of the Script allows to edit the script in an external editor.

View History

The History of Global Scripts can be accessed in two ways:

  • Either by selecting the Clock button available in the top of a selected Script (right side panel of the window), or
  • while editing the Script, in the Script window, go to the backstage of the Script (Script tab) and click History.

Read more about Version history here.

Restore version

It is possible to restore a former version of a Global Script in the History view. To do so, first open either of the views of the History.

By clicking the version number it is possible to open and review the former version of the Script in read-only mode. To restore, click Restore in the top ribbon of the Script.

Version Flag

The button Set Stable, available above a selected Global Script, allows to set the current version of the script as stable when pressed; when a Global Script is opened in Edit mode, it is also possible to click Set Stable in the top ribbon of the window.

To set a previous version of a Global Script as stable, either open the History and in the History view, select the version of the script which should be stable and click Set Stable in the right top area; or open the Script in Edit mode and go to the backstage by clicking Script in the top left corner, select History and in the list of versions, select the wanted version and click Set Stable in the top right area of the view.

To unset a stable version, select the Global Script (version) and click Unset Stable.

Learn more about Version Flags.

Scripts in Teneo
Global Variables
Engine Scripting API Javadoc