$context
A structure which represents the current runtime context of the request.
tip
The
$context object contains references to all the other built-in variables with the same names, but without the $ prefix:$context.parseTree = $parseTree
$context.client = $client
Additional fields
currentStateis the path to the current state where the script is executed.contextPathis the current context path. It can be different fromcurrentStateif thenoContextflag is used.testContextis the test execution context. This object is defined only in test mode and cannot be modified.
When using NLU, these fields are also available:
intentis the intent activated in the state.entitiesare entities found in the phrase.nluResultsis an array of NLU results.
How to use
- Clearing the session and client data at the start of the conversation.
state: Welcome
q!: $regex</start>
a: Hello! I’m your online assistant.
script:
$context.session = {};
$context.client = {};
go!: /ChooseCity
- Saving the path to the last triggered state in the
postProcesshandler.
init:
bind("postProcess", function($context) {
$context.session.lastState = $context.currentState;
});