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.
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:
- Create a global variable to store the value of the input parameter.
- Populate the global variable.
Create a global variable
To create the global variable to store the discount code of the user, proceed as follows:
- Open the 'SOLUTION' tab in the solution's window.
- Select 'Globals', and then select 'Variables'.
- Click 'Add'. Give the variable the name:
discountCode
, and set its initial value to the empty string:""
. - Click 'Save'.
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:
groovy
1if (engineEnvironment.getParameter('discountParameter')) {
2 discountCode = engineEnvironment.getParameter('discountParameter')
3}
4
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:
- Open the 'SOLUTION' tab in the solution's window (if you're not there already).
- Select 'Globals' and then select 'Scripts'.
- Select the 'Pre-processing' where you want to store your code ('Pre-processing' or 'Begin dialog') and choose 'Edit'.
- Paste the script:
groovy
1if (engineEnvironment.getParameter('discountParameter')) { 2 discountCode = engineEnvironment.getParameter('discountParameter') 3} 4
- 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:
- Select the 'Tryout' button located in the top left corner. This will open a new detailed Tryout window.
- Select 'Add Parameter' located above the box where you write.
- Add a parameter and name it:
discountParameter
(above). - 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’.