Understand the Processing Order of Global Scripts

A Teneo solution usually contains several types of Global Scripts which can be used for different purposes. These scripts provide Teneo developers enough flexibility to manipulate input and output, read files, write global variables, call third party API, etc. It is very important to understand the execution order of them in order to know which operation should be done in which script. Here you have a brief introduction of these global scripts and the order they are executed .

1. Solution Loaded
This script is executed when the solution is loaded before the beginning of the dialogue. It is in engine scope, which means it is not connected nor has access to any particular dialog session . This script is usually used to define the shared classes and functions which can be used within the whole solution, for example:

After you define this class in the Solution Loaded script, you can use the TeneoTextUtils class and the method capitalizeFirstLetters in any of the global scripts, flow scripts and attached scripts.

2. Begin Dialogue
This script is executed when the dialogue session begins , before the first user input is processed by the engine. It is only executed once per dialogue session on the first request .This script is normally used to set up global variables which won’t be changed in the whole dialogue session, such as the date, the device type (desktop / mobile), the channel (Messenger / Whatsapp) etc. For example, the following code in the Begin Dialogue script will save the current date at the beginning of the dialogue in global variables which are ready to be used during the whole dialogue session:

3. New session and Time-out session
New session and Time-out session scripts are both executed following the Begin Dialogue script. The New session script is only executed when the current request is the first request of a new session while the Time-out session script is only executed when the current request is the first request after a session expired due to a 10-minute inactivity. The timeout is configurable via the following code:

engineEnvironment.setSessionTimeout(n) 

while n represents the timeout by second. This code should be added in the Begin Dialogue script. These two scripts are very rarely used. Usually, they are only used when you need to distinguish between a new session and a session recovered from timeout.

4.Pre-processing
This script is executed once a request comes in. Please be aware that this script is executed BEFORE the built-in input processor does its job (tokenization, auto-correction, annotation, etc.). This script is often used to manipulate the user input text and collect the value of input parameters. For example, the following code in the Pre-processing script collects the value of the input parameter discountParameter when it is included in the request:

5. Pre-matching
This script is executed AFTER the input processor and BEFORE any trigger is fired. It is less frequently used compared to Pre-processing. The user input text is READ ONLY from this step, but you can still manipulate input annotation in this script. If you use LUIS^Teneo, the LUIS intent classification results are imported in this step. This script is executed once per request .

6. On top
This script is executed whenever a flow becomes the first flow in the flow stack . This script is rather seldomly used in projects. You can use it, for example, to collect the information of the flow which has been just triggered.

7. On drop
This script is executed whenever a flow is dropped from the flow stack . This script is not frequently used in projects. You can use it to collect the information of the flow which has been just reached the end point, or to modify a global variable to make it meet the condition of a prompt trigger.

8. Post-processing
This script is executed after the engine has constructed a response but which has not yet been given to the user. It is executed once per request . This script is very frequently used to manipulate the output text and output parameters. For example, the following code in the Post-processing script splits the output into multiple text bubbles when using Teneo Web Chat:

9. End Dialogue
This script is executed when the dialogue session ends and only once per dialogue session . It is often used to log a global variable at session level which will allow you to query this variable using session properties in Teneo Inquire. This is very useful when you want to query the final values of some important global variables at the end of the dialogue session. For example, the following script in the End Dialogue script converts six global variables into session properties :

Then you can query these global variables with their final state as session property in Teneo Inquire in this way:

10. Solution Unloaded
This script is executed when the solution is unloaded . The same as the Solution Loaded script, this script is not connected nor has access to any particular dialog session as well.

In this article you have learned the processing order of the global scripts in Teneo Studio. Besides these global scripts, there are more scripts which can be executed during the input processing, for example global listeners, flow scripts, flow listeners and script nodes in flows. You can click here for the whole input processing path. If you want to know more about the processing path, feel free to ask us here in the Forum any questions you might have!

1 Like