EntityResolutionContext

Lib~ EntityResolutionContext

The Bots EntityResolutionContext is a class for querying, validating and changing a composite bag entity and its entity resolution status.

An EntityResolutionContext class instance is passed as an argument to every event handler function.

Constructor

new EntityResolutionContext(request)

Source:
Constructor of entity resolution context. DO NOT USE - INSTANCE IS ALREADY PASSED TO EVENT HANDLERS
Parameters:
Name Type Description
request object

Extends

Methods

addCandidateMessages()

Source:
Add the bot messages created by ResolveEntities or CommomResponse component to the response that will be sent to the user. Note that these messages are in the format of the conversation message model (CMM), and can be either a text, attachment or card message payload

addMessage(payload, keepProcessingopt)

Source:
Adds a message to the bot response sent to the user.
Parameters:
Name Type Attributes 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.
keepProcessing boolean <optional>
If set to false (the default), the message will be sent to the user and the ResolveEntities or CommonResponse component will stop any further processing, and wait for user input. If set to true, the component will continue processing, possibly sending more messages to the user before releasing the turn

addValidationError(itemName, error)

Source:
Add a validation error for a composite bag item. This marks the item invalid and the the item will not be set/updated with the new invalid value. The error mesage will be published as bot message to the user.
Parameters:
Name Type Description
itemName string name of composite bag iten that validation error applies to
error string the error message

clearDisambiguationValues(itemName)

Source:
Removes the disambiguation values that are found based on the last user input for a specific bag item
Parameters:
Name Type Description
itemName string name of the composite bag item, if not specified, all disambiguation values of all items will be cleared

clearItemValue(name)

Source:
Remove the value of a composite bag item from the composite bag entity JSON object
Parameters:
Name Type Description
name string name of the composite bag item

constructMessagePayload(payload)

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

getCandidateMessages() → {Array.<object>}

Source:
Returns a list of the candidate bot messages created by the the ResolveEntities or CommonResponse component that will be sent to the user when you use addCandidateMessages() function.
Returns:
list of candidate messages. Note that these messages are in the format of the conversation message model (CMM), and can be either a text, attachment or card message payload
Type
Array.<object>

getCurrentItem() → {string}

Source:
Returns the name of the bag item that is currently being resolved
Returns:
the bag item name
Type
string

getCustomProperty(name) → {object}

Source:
Returns the value of a custom property that is stored in the entity resolution context. A custom property can be used to maintain custom state accross event handler calls while resolving the composite bag entity.
Parameters:
Name Type Description
name string name of the custom property
Returns:
value of the custom property
Type
object

getDisambiguationValues(itemName) → {Array.<object>}

Source:
Returns the disambiguation values that are found based on the last user input for a specific bag item
Parameters:
Name Type Description
itemName string name of the composite bag item
Returns:
the disambiguations values. This is a string array for bag items that have a custom entity type, and a JSONObject array for bag items with a system entity type
Type
Array.<object>

getDisplayValue(itemName) → {string}

Source:
See:
  • setSystemEntityDisplayProperties
  • setSystemEntityDisplayFunction
Returns the display value for a composite bag item. For bag items with a custom entity type or STRING items, the display value is the same as the actual value. For system entities, LOCATION and ATTACHMENT the configured display properties and display function determine the display value
Parameters:
Name Type Description
itemName string name of the composite bag item
Returns:
display value of composite bag item
Type
string

getDisplayValues(itemNames) → {Array.<string>}

Source:
See:
  • setSystemEntityDisplayProperties
  • setSystemEntityDisplayFunction
Returns the display value for a composite bag item. For bag items with a custom entity type or STRING items, the display value is the same as the actual value. For system entities, LOCATION and ATTACHMENT the configured display properties and display function determine the display value
Parameters:
Name Type Description
itemNames string you can specify one or more item names as argument. If you do this, only the display values of these items will be returned. If you do not specify an item name, the display values of all items in the bag will be returned.
Returns:
list of display values of composite bag item
Type
Array.<string>

getEntity() → {object}

Source:
Returns the value of the composite bag entity currently being resolved
Returns:
The JSON object holding the composite bag item values
Type
object

getEntityItems() → {Array.<object>}

Source:
Returns list of composite bag item definitions
Returns:
list of composite bag item definitions
Type
Array.<object>

getEntityName() → {string}

Source:
Returns the name of the composite bag entity type currently being resolved
Returns:
name of the composite bag entity type
Type
string

getItemsMatched() → {Array.<string>}

Source:
Returns the composite bag item definitions that have gotten a new value extracted from the last user input
Returns:
list of composite bag item names
Type
Array.<string>

getItemsMatchedOutOfOrder() → {Array.<string>}

Source:
Returns the composite bag item definitions that have gotten a new value extracted from the last user input while the user was prompted for another bag item.
Returns:
list of composite bag item names
Type
Array.<string>

getItemsUpdated() → {Array.<string>}

Source:
Returns the composite bag item definitions that already had a value and have gotten a new value extracted from the last user input.
Returns:
list of composite bag item names
Type
Array.<string>

getItemValue(name) → {object}

Source:
Return value of a composite bag item in the composite bag entity currentyly being resolved
Parameters:
Name Type Description
name string the name of the composite bag item for which the value is returned
Returns:
value of the composite bag item
Type
object

getLogger() → {object}

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

getMessageModel() → {MessageModel}

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

getMessages()

Source:
Returns the list of messages that will be sent to the user
Returns:
list of messages

getRequest() → {object}

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

getResponse() → {object}

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

getUserInput() → {string}

Source:
Returns the last user input message. If the last message was not a text message, this function returns undefined
Returns:
the user text message
Type
string

getValidationErrors() → {object}

Source:
Returns validation errors
Returns:
validation errors keyed by item name
Type
object

getVariable(name) → {object}

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

isSkippedItem(name) → {boolean}

Source:
Returns true when item is marked as skipped, returns false otherwise
Parameters:
Name Type Description
name string name of the composite bag item
Returns:
skip item flag
Type
boolean

setCustomProperty(name, value)

Source:
Sets the value of a custom property that is stored in the entity resolution context. A custom property can be used to maintain custom state accross event handler calls while resolving the composite bag entity. If you set the value to null, the custom property will be removed.
Parameters:
Name Type Description
name string name of the custom property
value object value of the custom property

setEntity(newEntity)

Source:
Sets the value of the composite bag entity currently being resolved
Parameters:
Name Type Description
newEntity object The JSON object holding the composite bag item values

setItemValue(name, value)

Source:
Set value of a composite bag item in the composite bag entity currentyly being resolved
Parameters:
Name Type Description
name string the name of the composite bag item for which the value is set
value object value of the composite bag item

setSystemEntityDisplayFunction(entityName, displayFunction)

Source:
A bag item of type system entity, LOCATION and ATTACHMENT has a JSON Object as value. With this function you can override the default display function that is applied to the display property values. The function is called with each display property as an argument For example, this is the default display function for DURATION: ((startDate,endDate) => new Date(startDate)+" - "+new Date(endDate)) If you want to format the dates differently, you can use a library like moments.js and call this function to override the display function Object that should be used to print out a string representation of the value.
Parameters:
Name Type Description
entityName string name of the system entity, or 'ATTACHMENT' or 'LOCATION'
displayFunction object the display function applied to the display properties

setSystemEntityDisplayProperties(entityName, properties)

Source:
A bag item of type system entity, LOCATION and ATTACHMENT has a JSON Object as value. With this function you can override the default display properties of the JSON Object that should be used to print out a string representation of the value.
Parameters:
Name Type Description
entityName string name of the system entity, or 'ATTACHMENT' or 'LOCATION'
properties Array.<string> array of property names

setVariable(name, value)

Source:
Overrides:
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

skipItem(name)

Source:
Mark a composite bag item as skipped, which means the ResolveEntities or CommonResponse component will no longer prompt for a value for the bag item
Parameters:
Name Type Description
name string name of the composite bag item

unskipItem(name)

Source:
Unmark a composite bag item as skipped, which means the ResolveEntities or CommonResponse component will prompt again for a value for the bag item
Parameters:
Name Type Description
name string name of the composite bag item

variable(name, valueopt)

Source:
Overrides:
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