Store input parameters

Besides the natural language inputs of the user, client applications can also include input parameters in their requests to Teneo. The values of these input parameters can then be stored in for example global variables, so that they can be used by flows, integrations, etc. 

More details on how client applications can interact with Teneo can be found on the Teneo Engine client API page in Deploy your bot.

In this example we will assume that requests from the client application can include an input parameter called discountParameter that we want to store in a global variable. To store it we need to do two things:

  1. Create a global variable to store the value of the input parameter.
  2. Populate the global variable.

Create a global variable

To create the global variable to store the discount code of the user, proceed as follows:

  1. Open the 'SOLUTION' tab in the solution's window.
  2. Select 'Globals' in the purple bar on the left hand side, and then select 'Variables'.
  3. Click 'Add'. A panel for specifying the new variable appears on the right hand side.
  4. Give the variable the name: discountCode, and set its initial value to the empty string: "".
  5. Click 'Save'.

Since this is a global variable, it can be used by any flow and it can also be used to assign variable based context restrictions.

Read the input parameter

Now that we have a global variable discountCode, we can populate it with the value of the input parameter discountParameter. For this, we need to use the Engine Scripting API, specifically the getParameter() method that is available in the EngineEnvironment class. The code to store the parameter looks as follows:

if (engineEnvironment.getParameter('discountParameter')) {
    discountCode = engineEnvironment.getParameter('discountParameter')

This code will make sure that the global variable discountCode will be populated only if the input parameter is found, and that the global variable will not be cleared if the input parameter is not included in requests anymore.

We will store this code in a global script. Which global script to use depends on when you expect to receive the input parameter. The most common places are:

  • Pre-processing
    In many cases you won't know exactly in which request the input parameter will be present (could be at the start, could be in the middle of the session). Or perhaps the value of the input parameter can change throughout the session. In that case, it is best to store the code above in the global Pre-processing script. Pre-processing scripts will be executed on every incoming request, before Teneo does any processing of the input.

  • Begin-dialog
    If you are certain that the input parameter will be included in the first request and will not change throughout the session, you can use the global Begin dialog script. This is slightly more efficient, because the script will only be executed once at the start of the session and not for every request.

In this example we will store the script in Pre-processing:

  1. Open the 'SOLUTION' tab in the solution's window (if you're not there already).
  2. Select 'Globals' in the purple bar on the left hand side, and then select 'Scripts'.
  3. Select the 'Pre-processing' where you want to store your code ('Pre-processing' or 'Begin dialog') and choose 'Edit'.
  4. Paste the script:
    if (engineEnvironment.getParameter('discountParameter')) {
        discountCode = engineEnvironment.getParameter('discountParameter')
  5. Click 'Save'.

The end result should look like this:

Testing input parameters

We can simulate input parameters by adding them to the Inputs panel in the main window of Teneo: input panels

  1. Click on the ‘Inputs panel’ to the right
  2. Add a parameter and name it: discountParameter
  3. Add the parameter's value which is the discount code: CyberMon

To see if the global variable ’discountCode’ got populated as intended, open the try out panel and give any input. Then open the Response info panel and inspect the global variables. You should see the global variable ‘discountCode’ populated with ‘CyberMon’.

Inspecting global variable 'discountCode'

Was this page helpful?