Built-in variables
The following variables can be referenced in script extensions specified after the if
, else
, elseif
, script
tags and string substitutions {{}}
in reactions:
Variable | Description |
---|---|
$client | A storage for persistent data related to the current bot user. |
$context | A structure which represents the current runtime context of the request and contains references to all the other built-in variables, as well as a few special fields. |
$entities | The list of all NLU entities recognized in the user request. |
$injector | The set of properties specified during bot deployment or script connection. |
$parseTree | An object representing the result of matching the input phrase against named patterns and entities, as well as the results of value conversions. |
$request | An object containing the user request data. |
$response | An object for forming the bot response. |
$session | A storage for data related to the current session. |
$temp | A storage for temporary data which only exists while processing a single user request. |
Access built-in variables
ECMAScript 5
-
In the
script
tag, access the variables directly:$session.example = "Example";
-
In JS files and JS actions, use the
$jsapi.context
method:$jsapi.context().session.example = "Example";
ECMAScript 6
In the ECMAScript 6 runtime, you can access the variables in the scriptEs6
tags and JS files.
ECMAScript 6 is not supported in JS actions.
Variables are available in synchronous and asynchronous functions.
Synchronous functions
All the variables are supported. Access them directly:
$session.example = "Example";
Asynchronous functions
Only the $session
and $client
variables are supported.
-
Write a value into a variable:
$session.example = "Example";
-
Get a value from a variable:
var example = await $session.example;
In the ECMAScript 6 support in JAICP article, you can learn more about using these variables in asynchronous functions.