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 currentlyu 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 the 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

engineEnvironment.getParameter('userTimeZone')

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

_.setSessVarLifespan('coffeeTypeInFocus',2)

Get the user's input

_.userInputText()

Get the output text

_.getOutputText()

Get the output url for an output

_.getOutputURL()

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) {
    _.outputParameters.clear();
}

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

_.getDialogHistoryLength()

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) {
            flow.abort()
        }
    }
}

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

engineEnvironment.setSessionTimeout(0);

Was this page helpful?