BaseContext

Lib~ BaseContext

Super class for concrete context classes used to invoke custom components and event handlers

Constructor

new BaseContext(request, response, validationSchemaopt)

Source:
Parameters:
Name Type Attributes Description
request object invocation request payload
response object initial response payload
validationSchema function <optional>
callback returns a schema for request body validation

Methods

constructMessagePayload(payload) → {object}

Description:
  • Creates a message payload object
Source:
Parameters:
Name Type Description
payload object can take a string message, a message created by the MessageFactory, or a message created by the deprecated MessageModel.
Returns:
message payload in JSON format
Type
object

getChannelType() → {string}

Description:
  • Return the channel conversation type
Source:
Returns:
the channel type
Type
string

getLogger() → {object}

Description:
  • Retrieves the logger object.
Source:
Deprecated:
  • use logger() function instead
Returns:
The logger object.
Type
object

getMessageFactory() → {MessageFactory}

Description:
  • Returns the MessageFactory class for creating bots messages
Source:
Returns:
The MessageFactory class
Type
MessageFactory

getMessageModel() → {MessageModel}

Description:
  • Returns the MessageModel class for creating or validating messages to or from bots.
Source:
Deprecated:
  • Use getMessageFactory() instead
See:
  • MessageModel.js
Returns:
The MessageModel class
Type
MessageModel

getRequest() → {object}

Description:
  • Retrieves the request object.
Source:
Returns:
The request object.
Type
object

getResponse() → {object}

Description:
  • Retrieves the response object.
Source:
Returns:
The response object.
Type
object

getUserMessage() → {NonRawMessage}

Description:
  • Returns the last user message.
Source:
Returns:
the last user message. You can cast this message to the appropriate message type.
Type
NonRawMessage

getVariable(name) → {object}

Description:
  • Returns the value of a context or user variable
Source:
Parameters:
Name Type Description
name string name of the variable
Returns:
variable value
Type
object

getVariableDefinition(name)

Description:
  • Get the definition of a variable
Source:
Parameters:
Name Type Description
name string The name of the variable

logger() → {object}

Description:
  • Retrieves the logger object.
Source:
Returns:
The logger object.
Type
object

nlpResult(nlpVariableNameopt) → {NLPResult}

Description:
  • Returns an NLPResult helper object for working with nlpresult variables. See the NLPResult documentation for more information.

    If your skill uses visual flows, you don't need to specify a variable name. If your skill uses a YAML flow, you may specify a particular nlpresult by name (if you have multiple nlpresult variables defined in the flow), or omit the name if you only have 1 nlpresult.

Source:
Parameters:
Name Type Attributes Description
nlpVariableName string <optional>
variable that holds the nlpResult
Returns:
The nlp resolution result.
Type
NLPResult

setVariable(name, value)

Description:
  • Sets the value of a context or user variable
Source:
Parameters:
Name Type Description
name string name of the variable
value object value of the variable

translate(rbKey, …rbArgs) → {string}

Description:
  • Get translated string using a resource bundle key defined in the skill.
Source:
Parameters:
Name Type Attributes Description
rbKey string key of the resource bundle entry defined with the skill that should be used to translate
rbArgs string <repeatable>
substitution variables
Returns:
resource bundle freemarker expression that will be resolved when event handler or custom component response is received by dialog engine
Type
string

variable(name, valueopt)

Description:
  • Read or write variables defined in the current flow. It is not possible to change the type of an existing variable through this method. It is the caller's responsibility to ensure that the value being set on a variable is of the correct type. (e.g. entity, string or other primitive, etc).

    A new variable can be created. However, since the variable is not defined in the flow, using it in the flow subsequently may be flagged for validation warnings.

    This function takes a variable number of arguments.

    The first form: variable(name); reads the variable called "name", returning its value. The name could be in the form of <scope>.<variableName>. For example, a variable firstName in the profile scope needs to be retrieved as variable("profile.firstName").

    The second form: variable(name, value); writes the value "value" to the variable called "name".
Source:
Example
let firstName = conversation.variable("profile.firstName");
let lastName = conversation.variable("profile.lastName");
conversation.variable("fullName", firstName + ' ' + lastName);
Parameters:
Name Type Attributes Description
name string The name of variable to be set or read
value string <optional>
value to be set for variable