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)

Source:
Creates a message payload object
Parameters:
Name Type Description
payload object can take a string payload, an object payload or a MessageModel payload. A string or object payload will be parsed into a MessageModel payload. If the MessageModel payload has a valid common message format, then reply will use it as messagePayload, else it will use the payload to create a rawConversationMessage (see MessageModel) as messagePayload.

getLogger() → {object}

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

getMessageModel() → {MessageModel}

Source:
See:
  • MessageModel.js
Returns the MessageModel class for creating or validating messages to or from bots.
Returns:
The MessageModel class
Type
MessageModel

getRequest() → {object}

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

getResponse() → {object}

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

getVariable(name) → {object}

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

setVariable(name, value)

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

variable(name, valueopt)

Source:
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".
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