Constructor
new CustomComponentContext(request)
- Source:
Example
const MyCustomComponent = {
metadata: () => ({name: 'hello'}),
invoke: async (context) => {
// use conversation instance methods to respond, set variables, etc.
context.reply('Hello!');
context.transition();
}
}
Parameters:
Name | Type | Description |
---|---|---|
request |
object | The request body |
Extends
Methods
MessageModel() → {MessageModel}
- Description:
- Returns the MessageModel class for creating or validating messages to or from bots.
- Source:
- Deprecated:
- Use getMessageFactory() instead
Returns:
- Type
- MessageModel
attachment() → {object}
- Description:
- Retrieves the attachment of the current input message. If the input message is not an attachment, this will return null.
- Source:
Returns:
- Type
- object
botId() → {string}
- Description:
- Retrieves the bot id.
- Source:
Returns:
- Type
- string
channelId() → {string}
- Description:
- Retrieves the channel Id of the current input message.
- Source:
Returns:
- Type
- string
channelType() → {string}
- Description:
- Retrieves the channel type of the current input message.
- Source:
Returns:
- Type
- string
constructMessagePayload(payload) → {object}
- Description:
- Creates a message payload object
- Source:
- Overrides:
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:
- Type
- object
error(e)
- Description:
- Sets the error flag on the response.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
e |
boolean | sets error if true |
getChannelType() → {string}
- Description:
- Return the channel conversation type
- Source:
- Overrides:
Returns:
- Type
- string
getLogger() → {object}
- Description:
- Retrieves the logger object.
- Source:
- Overrides:
- Deprecated:
- use logger() function instead
Returns:
- Type
- object
getMessageFactory() → {MessageFactory}
- Description:
- Returns the MessageFactory class for creating bots messages
- Source:
- Overrides:
Returns:
- Type
- MessageFactory
getMessageModel() → {MessageModel}
- Description:
- Returns the MessageModel class for creating or validating messages to or from bots.
- Source:
- Overrides:
- Deprecated:
- Use getMessageFactory() instead
- See:
-
- MessageModel.js
Returns:
- Type
- MessageModel
getRequest() → {object}
- Description:
- Retrieves the request object.
- Source:
- Overrides:
Returns:
- Type
- object
getResponse() → {object}
- Description:
- Retrieves the response object.
- Source:
- Overrides:
Returns:
- Type
- object
getUserMessage() → {NonRawMessage}
- Description:
- Returns the last user message.
- Source:
- Overrides:
Returns:
- Type
- NonRawMessage
getVariable(name) → {object}
- Description:
- Returns the value of a context or user variable
- Source:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
name |
string | name of the variable |
Returns:
- Type
- object
getVariableDefinition(name)
- Description:
- Get the definition of a variable
- Source:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the variable |
invalidUserInput(ropt)
- Description:
- Call this method if the input is not understood, and this would allow the bots runtime to handle the issue. The bots runtime may just display the message to the user and execute the same component again, or it may try to interpret the input and process differently.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
r |
object | string | MessageModel |
<optional> |
optional payload to be sent to user. payload could also be a string for text response |
keepTurn(kopt)
- Description:
- "keepTurn" is used to indicate if the Bot/component should send the next replies, or
or if the Bot/component should wait for user input (keepTurn = false).
The SDK's "reply" function automatically sets "keepTurn" to false.
- "keepTurn" is used to indicate if the Bot/component should send the next replies, or
or if the Bot/component should wait for user input (keepTurn = false).
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
k |
boolean |
<optional> |
whether to keep the turn for sending more replies |
location() → {object}
- Description:
- Retrieves the location of the current input message. If the input message does not contain a location, this will return null.
- Source:
Returns:
- Type
- object
logger() → {object}
- Description:
- Retrieves the logger object.
- Source:
- Overrides:
Returns:
- Type
- object
messagePayload() → {object}
- Description:
- Retrieves the payload of the current input message in the common message format.
- Source:
Returns:
- 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.
- Returns an NLPResult helper object for working with nlpresult variables.
See the NLPResult documentation for more information.
- Source:
- Overrides:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nlpVariableName |
string |
<optional> |
variable that holds the nlpResult |
Returns:
- Type
- NLPResult
platformVersion() → {string}
- Description:
- Retrieves the platform version of the request.
- Source:
Returns:
- Type
- string
postback() → {object}
- Description:
- Retrieves the postback of the current input message. If the input message is not a postback, this will return null.
- Source:
Returns:
- Type
- object
properties() → {object}
- Description:
- Retrieves the properties defined for the current state.
- Source:
Returns:
- Type
- object
rawPayload() → {object}
- Description:
- Retrieves the raw payload of the current input message.
- Source:
Returns:
- Type
- object
releaseTurn(kopt)
- Description:
- "releaseTurn" is the shorthand for keepTurn(false)
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
k |
boolean |
<optional> |
whether to keep the turn for sending more replies |
reply(payload, channelConversationopt)
- Description:
- Adds a reply to be sent back to the user. May be called multiple times to send multiple replies in a given response.
Automatically sets the
keepTurn
as false.
- Adds a reply to be sent back to the user. May be called multiple times to send multiple replies in a given response.
Automatically sets the
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
payload |
object | can take a string message, a message created by the MessageFactory, or a message created by the deprecated MessageModel. | |
channelConversation |
object |
<optional> |
to override the default channelConversation from request |
Returns:
request() → {object}
- Description:
- Retrieves the request body.
- Source:
Returns:
- Type
- object
sessionId() → {string}
- Description:
- Retrieves the sessionId for the current input message.
- Source:
Returns:
- Type
- string
setVariable(name, value)
- Description:
- Sets the value of a context or user variable
- Source:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
name |
string | name of the variable |
value |
object | value of the variable |
text() → {string}
- Description:
- Retrieves the text of the current input message. Eventually not all messages will have a text value, in which case this will return null.
- Source:
Returns:
- Type
- string
transition(topt)
- Description:
- Call
transition()
when your component has completed its logic and the dialog should transition to the next state, after replies (if any) are sent.If
transition()
is not called, the dialog will stay in this state after sending the replies (if any), and subsequent user input will come back to this component. This allows a component to handle a series of interactions within itself, however the component is responsible for keeping track of its own state in such situations.transition()
will cause the dialog to transition to the next state. transition(outcome) will set te outcome of the component that would be used to determine the next state to transition to.
- Call
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
t |
string |
<optional> |
outcome of component |
translate(rbKey, …rbArgs) → {string}
- Description:
- Get translated string using a resource bundle key defined in the skill.
- Source:
- Overrides:
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:
- Type
- string
userId() → {string}
- Description:
- Retrieves the userId for the current input message.
- Source:
Returns:
- 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".
- 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).
- Source:
- Overrides:
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 |
(static) sdkVersion() → {string}
- Description:
- Retrieves the sdk version.
- Source:
Returns:
- Type
- string