Constructor
new ComponentInvocation(requestBody)
Parameters:
Name | Type | Description |
---|---|---|
requestBody |
object | The request body |
Methods
(static) sdkVersion() → {string}
Retrieves the sdk version.
Returns:
The sdk version.
- Type
- string
action(a)
Sets the action to return from this component, which will determine the
next state in the dialog.
Parameters:
Name | Type | Description |
---|---|---|
a |
string | action name |
attachment() → {object}
Retrieves the attachment of the current input message.
If the input message is not an attachment, this will return null.
Returns:
The attachment.
- Type
- object
botId() → {string}
Retrieves the bot id.
Returns:
The bot id.
- Type
- string
channelType() → {string}
Retrieves the channel type of the current input message.
Returns:
The channel type - facebook, webhook, test, etc.
- Type
- string
done()
Set "done" to true when your component has completed its logic and
the dialog should transition to the next state.
This is only meaningful when you are sending replies (ie you have also
set "exit" to true). If you are not sending replies ("exit" is false,
the default) then "done" is ignored; the dialog always moves to the next
state.
If "exit" is true (replies are being sent), then leaving "done" as false
(the default) means the dialog will stay in this state after sending
the replies, 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.
Setting "done" to true will transition to the next state/component after
sending the replies.
error(e)
Sets the error flag on the response.
Parameters:
Name | Type | Description |
---|---|---|
e |
boolean | sets error if true |
exit()
Set "exit" to true when your component has replies it wants to send to
the client.
The SDK's "reply" function automatically sets "exit" to true, but
if you manually modify the response to send replies then you will need
to set this explicitly.
keepTurn(kopt)
"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.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
k |
boolean |
<optional> |
whether to keep the turn for sending more replies |
location() → {object}
Retrieves the location of the current input message.
If the input message does not contain a location, this will return null.
Returns:
The attachment.
- Type
- object
logger() → {object}
Retrieves the logger so the component can use the shared logger for logging. The shared logger should support the methods log, info, warn, error and trace.
Returns:
The logger.
- Type
- object
messagePayload() → {object}
Retrieves the payload of the current input message in the common message format.
Returns:
The common message payload.
- Type
- object
nlpResult(nlpVariableNameopt) → {NLPResult}
Returns an NLPResult helper object for working with nlpresult variables.
See the NLPResult documentation for more information.
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.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nlpVariableName |
string |
<optional> |
variable to be given the nlpResult |
Returns:
The nlp resolution result.
- Type
- NLPResult
payload() → {object}
Retrieves the payload of the current input message. For backward compatibility purposes. However, the payload returned may be in the new message format.
Returns:
The message payload.
- Type
- object
platformVersion() → {string}
Retrieves the platform version of the request.
Returns:
The platform version.
- Type
- string
postback() → {object}
Retrieves the postback of the current input message.
If the input message is not a postback, this will return null.
Returns:
The postback payload.
- Type
- object
properties() → {object}
Retrieves the properties defined for the current state.
Returns:
The properties
- Type
- object
rawPayload() → {object}
Retrieves the raw payload of the current input message.
Returns:
The raw payload.
- Type
- object
releaseTurn(kopt)
"releaseTurn" is the shorthand for keepTurn(false)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
k |
boolean |
<optional> |
whether to keep the turn for sending more replies |
reply(payload, channelConversationopt)
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.
reply 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.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
payload |
object | string | MessageModel | payload to be sent back. payload could also be a string for text response | |
channelConversation |
object |
<optional> |
to override the default channelConversation from request |
request() → {object}
Retrieves the request body.
Returns:
The request body.
- Type
- object
sessionId() → {string}
Retrieves the sessionId for the current input message.
Returns:
The sessionId.
- Type
- string
setCallbackToken(callbackToken)
When expecting an out of band conversation continuation, such as a
user following the OAuth flow, completing a form and hitting submit, or
a human support agent or other third party sending a message, issue a
limited use token to allow calling back into Bots via the generic callback
endpoint.
The provided token should be a UUID or other unique and random number. By setting it
here in the response the Bot will await a reply with that token and use it to
thread the message back into the current conversation with that user.
Parameters:
Name | Type | Description |
---|---|---|
callbackToken |
string | token generated by you to allow reauthentication back into this conversation. Should be unique, like userId + random. It is ok to reissue the same token for the same conversation. |
text() → {string}
Retrieves the text of the current input message.
Eventually not all messages will have a text value, in which case
this will return null.
Returns:
The text of the input message.
- Type
- string
transition(topt)
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.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
t |
string |
<optional> |
outcome of component 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. |
userId() → {string}
Retrieves the userId for the current input message.
Returns:
The userId.
- Type
- string
variable(name, valueopt)
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 second form:
variable(name, value);
writes the value "value" to the variable called "name".
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 (optional) |