Teneo Developers

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 e.g. 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', and then select 'Variables'.
  3. Click 'Add'. Give the variable the name: discountCode, and set its initial value to the empty string: "".
  4. 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:


1if (engineEnvironment.getParameter('discountParameter')) {
2	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:

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' 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:


    1if (engineEnvironment.getParameter('discountParameter')) {
    2    discountCode = engineEnvironment.getParameter('discountParameter')
  5. Give your script a name like, Grab discount code and 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 Parameters, in Tryout, are reviewed to ensure correct handling of these based on casing (upper/lower case) and to not allow duplicated parameter names; for example, Tryout will accept PARAM1, param1 and PAraM1 as different parameter names since the casing is different while PARAM2 and PARAM2 will raise a warning as the name is duplicated (i.e. identical in wording and case). Also note that parameter names are always required and the field cannot be left empty.

Discount parameter

  1. Select the 'Tryout' button located in the top left corner. This will open a new detailed Tryout window.
  2. Select 'Add Parameter' located above the box where you write.
  3. Add a parameter and name it: discountParameter (above).
  4. Add the parameter's value which is the discount code: CyberMon (under).

To see if the global variable ’discountCode’ got populated as intended, open the Tryout 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'