Your bot doesn’t have to be just a chatty assistant. It can also handle more advanced actions for you such as completing purchases, sending receipts and sending updated data from your databases. You can do that using webhooks.
Webhooks, also called a web callback or HTTP push API, are the API concepts that are getting more and more popular. Thanks to their lightweight and speed they provide data between applications immediately. With webhooks, you can pass and retrieve information from a matched interaction to your web service.
Main characteristics
-
you can set up separate webhooks for each interaction
-
pick the language you like to create webhooks:
PHP
,Node.js
,Java
,JavaScript
,C++
etc. -
webhooks returns data to your bot, that’s why responses from webhooks are added to bot responses
How to set up my first webhook
Go to our Setting up your webhook tutorial to check how you can create your first webhook connected with ChatBot.
Webhook request
When an interaction has a filled Webhook section, our backend service send the matched interaction to the webhook by POST
request.
Webhook schema
Example of the request content sent to the webhook address:
{
"conversationId": "5cc6d3c0b4001336f89de71a",
"result": {
"source": "app",
"resolvedQuery": "1",
"confidence": 0.5,
"score": 1,
"lifespan": 2,
"incomplete": false,
"storyId": "5cbf273ef96720b7e391b418",
"interaction": {
"id": "5cc6d3b845988e755a9f5e88",
"name": "Interaction A",
"action": ""
},
"parameters": {},
"sessionParameters": {},
"contexts": [
{
"id": "5cc6d3b845988e755a9f5e88",
"name": "Interaction A",
"action": "",
"parameters": {}
},
{
"type": "welcome",
"name": "Welcome Interaction",
"action": "default.welcome",
"parameters": {}
}
],
"fulfillment": [
{
"type": "webhook",
"debug": true,
"webhookId": "5cc6d3b245988e65419f5e86",
"used": true
},
{
"type": "text",
"delay": 2000,
"message": "Hi John Example"
}
]
},
"sessionId": "125338496333449767",
"timestamp": "2019-04-29T10:36:54.656Z",
"status": {
"code": 200,
"type": "success"
}
}
Limits
-
Timeout for service response is 10 seconds;
-
The maximum response size 100kb;
-
The response must be provided in JSON format;