Engine scripting API

Many of your scripts will depend on internal Teneo data. You may for example want to use the user's input in a script, or find out what the name is of the flow that is currently processed or you need to manipulate and answer text using a script. For that you can use the Engine scripting API. This API gives you access to detail provided in the requests as well as the current state of the dialog.

The two classes that you will use mostly in your scripts are:

  • engineAccess (alias _) - For accessing details about the conversation and bot's internal state.
  • engineEnvironment - For access to request/input parameters

The Engine scripting API Reference provides details on all classes and methods as well as the scopes in which they can be used. Below you will find some examples of Engine scripting API calls that are commonly used in Teneo solutions.

Common scripts

Retrieve an input parameter


Usually called in the either global Begin dialog or the global Pre-pocessing script. A more detailed guide can be found here: How to store input parameters.

Set the lifespan of a global variable


Get the user's input


or, slightly shorter:


Get the output text


Get the output url for an output


Manipulate an output text

if (channel == 'slack' && _.getOutputURL()) {
    _.setOutputText(_.getOutputText() + '\nMore details: ' + _.getOutputURL())

Note: outputs can only be manipulated in the global Post-processing script.

Clear all output parameters

if (something == true) {

Note: outputs can only be manipulated in the global Post-processing script.

Add an output parameter

_.putOutputParameter('openMic', 'true')

Note: the value of outputs parameters should always be Strings. Outputs can only be manipulated in the global Post-processing script.

Get the length of the dialog


Clear the flow stack

You would typically add this script to the On-drop script of the flow that should clear the stack.

if( _.activeFlows.size()>1) {
    for ( item in _.activeFlows[0..-2]){
        for (flow in item) {

Get the contents of a file stored in your solution

You can get the contents of a file stored in the /script_lib folder in the Resource file manager like this:

def fileContents = groovy.io.FileType.class.getClassLoader().getResource(resourceFilename).text

End session

You can programmatically end or kill an engine session like this:


Change session timeout

The bot session timeout period can be set in a script.

  1. From the main solution window, click on the 'Solution' tab in the top left corner.
  2. In the purple section on the left, choose 'Globals' and select the 'Scripts' tab at the top.
  3. Open the section, Begin Dialog and add a line as below where 'n' is the amount of seconds you wish for the timeout:
  4. DonĀ“t forget to hit save!

Was this page helpful?