Apply Stella API to Chatbot
Stella API allows an external application to trigger the following types of bot actions in Stella:
- Send Responses: Send a message in a specific response type to a chatbot user.
- Redirect Member To Node: Redirect to a specific node and execute the node for a chatbot user.
The common use case is when you want to activate Stella to send a message to a user based on the action of your external application. For example, you want to send a purchase confirmation message to a WhatsApp user after that person has completed a purchase on your online store and provided the WhatsApp number.
Getting Hands-on
This procedure will teach you how to test the Stella API (i.e. POST
) on Postman.
Send Response
- Create a new request on Postman and add
https://bot.stella.sanuker.com/v2.1/sendResponses
to the request URL.
Change the request type to
POST
.Generate an access token with
bot:sendResponses
permission and put it to "VALUE" under "Params". MarkaccessToken
under "KEY".
- Head to "Body" and choose "raw" and "JSON".
- Paste the body code of "Send Responses". The code below is just a sample, you should edit the response according to your needs. You can find out the JSON for the response object in advanced tab of the response builder.
{
"channelId": "5ece50e72efaabd58ef55027",
"fbUserRef": null,
"memberId": "5ece50f3bf385b25c4e08db5",
"recipientId": null,
"messagingType": "MESSAGE_TAG",
"messagingTag": "CONFIRMED_EVENT_UPDATE",
"response": [
{
"type": "TEXT",
"text": "Hello World"
},
{
"type": "IMAGE",
"url": "https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg"
}
]
}
- You should be able to find the channelID from your channel and recipientID/memberID/fbUserRef from the member page.
- Click "Send". It should return the following 200 response:
- Successful:
{
"ok": 1,
"member": "5ece50f3bf385b25c4e08db5",
"sendResults": [
{
"result": [
{
"result": {
"recipient_id": "10152368852405295",
"message_id": "m_U0EmmN476hlyPr-0iH2cXMcrTLJ5HeVUQjzqok8vkkF8wnJpPkagYbXU5hr0bXWHM5PPYjgd9RWG10K0oujeHQ"
},
"messageEvent": {
"from": "124830722411862",
"to": "10152368852405295",
"data": {
"text": "Hello World"
},
"type": "TEXT",
"timestamp": 1583292367324,
"messageId": " -0iH2cXMcrTLJ5HeVUQjzqok8vkkF8wnJpPkagYbXU5hr0bXWHM5PPYjgd9RWG10K0oujeHQ"
}
},
{
"result": {
"recipient_id": "10152368852405295",
"message_id": "m_U0EmmN476hlyPr-0iH2cXMcrTLJ5HeVUQjzqok8vkkF8wnJpPkagYbXU5hr0bXWHM5PPYjgd9RWG10K0oujeHQ"
},
"messageEvent": {
"from": "124830722411862",
"to": "10152368852405295",
"data": {
"url": "https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg"
},
"type": "IMAGE",
"timestamp": 1583292367324,
"messageId": " -0iH2cXMcrTLJ5HeVUQjzqok8vkkF8wnJpPkagYbXU5hr0bXWHM5PPYjgd9RWG10K0oujeHQ"
}
}
]
}
]
}
- Failure:
{
"ok": 0,
"err_code": 108,
"err": "Either memberId or recipientId or fbUserRef is required.\""
}
Redirect Member To Node
Create a tree node in a tree and add this tree to the channel you will use for this POST request.
Create a new request on Postman and add
https://bot.stella.sanuker.com/v2.1/redirectMemberToNode
to the request URL.
Change the request type to
POST
.Generate an access token with
bot:redirectMemberToNode
permission and put it to "VALUE" under "Params". MarkaccessToken
under "KEY".
- Head to "Body" and choose "raw" and "JSON".
- Paste the body code of "Redirect Member To Node". The code below is just a sample, you should change the
tree
&nodeCompositeId
to the ones in the tree node you created in step 1.
{
"channelId": "5ece50e72efaabd58ef55027",
"fbUserRef": null,
"memberId": "5ece50f3bf385b25c4e08db5",
"recipientId": null,
"redirect": {
"tree": "5ecf6cfba3b6643c33a64079",
"nodeCompositeId": "j4Bivxm0GWhnNV1m",
"runPreAction": true,
"sendResponse": null,
"runPostAction": false
},
"meta": {
"name": "Sanuker",
"orderId": "5ecf6be76fcfda6b139d802c"
}
}
- You should be able to find the channelID from your channel and recipientID/memberID/fbUserRef from the member page.
- Click "Send". It should return the following 200 response:
- Successful:
{
"ok": 1,
"member": "5ece50f3bf385b25c4e08db5",
"sendResults": [
{
"result": [
{
"result": {
"recipient_id": "10152368852405295",
"message_id": "m_U0EmmN476hlyPr-0iH2cXMcrTLJ5HeVUQjzqok8vkkF8wnJpPkagYbXU5hr0bXWHM5PPYjgd9RWG10K0oujeHQ"
},
"messageEvent": {
"from": "124830722411862",
"to": "10152368852405295",
"data": {
"text": "Hello World"
},
"type": "TEXT",
"timestamp": 1583292367324,
"messageId": " -0iH2cXMcrTLJ5HeVUQjzqok8vkkF8wnJpPkagYbXU5hr0bXWHM5PPYjgd9RWG10K0oujeHQ"
}
},
{
"result": {
"recipient_id": "10152368852405295",
"message_id": "m_U0EmmN476hlyPr-0iH2cXMcrTLJ5HeVUQjzqok8vkkF8wnJpPkagYbXU5hr0bXWHM5PPYjgd9RWG10K0oujeHQ"
},
"messageEvent": {
"from": "124830722411862",
"to": "10152368852405295",
"data": {
"url": "https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg"
},
"type": "IMAGE",
"timestamp": 1583292367324,
"messageId": " -0iH2cXMcrTLJ5HeVUQjzqok8vkkF8wnJpPkagYbXU5hr0bXWHM5PPYjgd9RWG10K0oujeHQ"
}
}
]
}
]
}
- Failure:
{
"ok": 0,
"err_code": 108,
"err": "Either memberId or recipientId or fbUserRef is required.\""
}