API Methods
sendResponse
Sending Response on behalf of your chatbot to a specific user.
Request URI
Single response
POST /sendResponse
Multiple responses
POST /sendResponses
Sample Request
Single response
curl -X POST \ 'https://bot.stella.sanuker.com/v2.1/sendResponse?accessToken={ACCESS_TOKEN}' \
-H 'Content-Type: application/json' \
-d '{
"channelId": "aChannelId",
"recipientId": "85293333333",
"memberId": "someMemberId",
"response": {
type: "TEXT",
text: "Hello World"
}
}'
Multiple responses
curl -X POST \ 'https://bot.stella.sanuker.com/v2.1/sendResponses?accessToken={ACCESS_TOKEN}' \
-H 'Content-Type: application/json' \
-d '{
"channelId": "aChannelId",
"fbUserRef": "some-user-ref",
"memberId": "someMemberId",
"responses": [
{
type: "TEXT",
text: "Hello"
},
{
type: "TEXT",
text: "World"
}
...
]
}'
Properties
Property | Type | Description |
---|---|---|
channelId | String | Channel ID in stella |
fbUserRef | String | Optional User-ref used in Facebook checkbox plugin |
memberId | String | Either memberId or recipientId Member ID in stella. |
recipientId | String | Either memberId or recipientId External ID. E.g. PSID on Facebook, phone number / groupId on WhatsApp, open_id on Wechat, etc. |
response | Object | Either response or responses The data you wish to send as a response. For the example above, we are sending a text response on Facebook, which you can take reference in Facebook Message Types. You can also check the message types of the corresponding platforms to construct the response object. |
responses | Array[Object] | Either response or responses The data you wish to send as responses. For the example above, we are sending an array of text responses on Facebook, which you can take reference in Facebook Message Types. You can also check the message types of the corresponding platforms to construct the response object. |
Response
The request returns a JSON string containing a “ok” flag indicating if the response/responses are successfully sent or not. In a successful case, an field “success” with truthy value will be returned. Otherwise, an optional “err” object if an error is encountered.
{
"ok": 1,
"member": "member-id",
"sendResult": {
"ok": 1,
"member": "member-id",
"result": [
{
"result": {
"message_id": "m_U0EmmN476hlyPr-0iH2cXMcrTLJ5HeVUQjzqok8vkkF8wnJpPkagYbXU5hr0bXWHM5PPYjgd9RWG10K0oujeHQ"
},
"messageEvent": {
"from": "some-page-id",
"to": "fb-user-ref",
"data": {
"text": "Hello World"
},
"type": "TEXT",
"timestamp": 1583292367324,
"messageId": "m_U0EmmN476hlyPr-0iH2cXMcrTLJ5HeVUQjzqok8vkkF8wnJpPkagYbXU5hr0bXWHM5PPYjgd9RWG10K0oujeHQ"
}
}
]
}
}
Response properties
Property | Type | Description |
---|---|---|
err | String | Error message |
err_code | Integer | Error Code |
member | String | Member ID in stella |
ok | Integer | 1 or 0, representing success and error accordingly |
sendResult | Object | Please see the description below (sendResult properties) |
sendResult properties
Property | Type | Description |
---|---|---|
ok | Integer | 1 or 0, representing success and error accordingly |
member | String | Member ID in stella |
result | Array[Object] | Please see the description below (sendResult properties) |
result properties
Property | Type | Description |
---|---|---|
messageEvent | Object | Normalised message event object |
result | Array[Object] | Raw result object |
Error Response
You would encounter an error “Phone Number Invalid” if the phone number you submitted is invalid. (i.e. not a valid phone number or the phone number is not a whatsApp number)
{
"ok": 0,
"err_code": 108,
"err": "Either memberId or recipientId or fbUserRef is required."
}
redirectMemberToNode
Redirecting a member to a specific node in tree and executing all or partial components of the node. This is useful for performing complex operations on a member and keeping all the bot logic in the tree instead of hard-coding in an api.
If memberId is not provided, the system would search for a member with the provided recipientId or fbUserRef, if none is found and the provided channel is a Whatsapp channel, the system would try to create a member with the recipientId and perform the redirection.
Request URI
POST /redirectMemberToNode
Sample Request
curl - X POST \ 'https://bot.stella.sanuker.com/v2.1/redirectMemberToNode?accessToken=some-access-token' \
-H 'Content-Type: application/json' \
-d '{
"channelId": "aChannelId",
"recipientId": "85293333333",
"fbUserRef": "some-user-ref",
"memberId": "someMemberId",
"meta": {
"orderId": "someOrderId",
"name": "hello"
},
"redirect": {
"nodeCompositeId": "someNodeCompositeId",
"tree": "someTreeId",
"runPreAction": true,
"runPostAction": true,
"sendResponse": true
}
}'
Properties
Property | Type | Description |
---|---|---|
channelId | String | Channel ID in stella |
fbUserRef | String | Optional User-ref used in Facebook checkbox plugin |
memberId | String | Either memberId or recipientId Member ID in stella. |
recipientId | String | Either memberId or recipientId External ID. E.g. PSID on Facebook, phone number / groupId on WhatsApp, open_id on Wechat, etc. |
meta | Object | Optional Meta object provided to the node. |
redirect | Object | Please see the description below (redirect properties) |
redirect Properties
Property | Type | Description |
---|---|---|
nodeCompositeId | String | Composite ID of the node redirecting to |
tree | String | Tree ID of the node redirecting to |
runPreAction | boolean | For fine tuning whether preActions should be run after redirect |
runPostAction | boolean | For fine tuning whether postActions should be run after redirect |
sendResponse | boolean | For fine tuning whether responses should be sent after redirect |
Response
The request returns a JSON string containing a “ok” flag indicating if the member is successfully redirected to node, a “member” field with the stella memberId, and an optional “error” object if an error is encountered.
{
"ok": 1,
"member": "member-id",
"sendResults": [
{
"ok": 1,
"member": "member-id",
"result": [
{
"result": {
"message_id": "m_4a7-MjU8W-k7K1Ws5_hOP8crTLJ5HeVUQjzqok8vkkELEM4sWFpVAAhK4Yz_ELl-eSjueSVEFSr137J1XMpBOQ"
},
"messageEvent": {
"from": "some-page-id",
"to": "fb-user-ref",
"data": {
"text": "Redirecting a member to the test node",
"transform": ""
},
"type": "TEXT",
"timestamp": 1583291866627,
"messageId": "m_4a7-MjU8W-k7K1Ws5_hOP8crTLJ5HeVUQjzqok8vkkELEM4sWFpVAAhK4Yz_ELl-eSjueSVEFSr137J1XMpBOQ"
}
}
]
}
]
}
Response properties
Property | Type | Description |
---|---|---|
err | String | Error message |
err_code | Integer | Error Code |
member | String | Member ID in stella |
ok | Integer | 1 or 0, representing success and error accordingly |
sendResult | Object | Array of sendResults from each node that has been redirected. Please see the description below (sendResult properties) |
sendResult properties
Property | Type | Description |
---|---|---|
ok | Integer | 1 or 0, representing success and error accordingly |
member | String | Member ID in stella |
result | Array[Object] | Please see the description below (sendResult properties) |
result properties
Property | Type | Description |
---|---|---|
messageEvent | Object | Normalised message event object |
result | Array[Object] | Raw result object |
Error Response
You would encounter an error “Phone Number Invalid” if the phone number you submitted is invalid. (i.e. not a valid phone number or the phone number is not a whatsApp number)
{
"ok": 0,
"err_code": 108,
"err": "Either memberId or recipientId or fbUserRef is required."
}