Webhooks for Bots
When creating a custom bot on the Sendbird Dashboard, the webhook URL of your server should be registered in Sendbird Desk to integrate your chatbot or a third-party bot. Once registered, your server will receive HTTP POST
requests from the Desk server in the form of the response containing information on all events related to a bot that occur within the application.
Note: You can set a different webhook URL for each bot using the Bot API or in Settings > Desk > Bots of your dashboard.
Configuration
You can configure a webhook endpoint URL and other relevant settings for each bot in Settings > Desk > Bots of your dashboard.
Webhook endpoint requirements
HTTP POST
requests with JSON
payloads are sent to your webhook endpoint upon specific events in your Sendbird application.
- The endpoint must support
HTTP/1.1
andkeep-alive
. - The endpoint needs to respond to
POST
requests. - The endpoint needs to parse
JSON
payloads.
By default, Sendbird server sends an HTTP POST
request and waits for a response from your webhook endpoint for 1 second. The server sends the same POST
request up to three times until it receives a response. To avoid too many requests, you should implement the endpoint to respond immediately to the server with a 200 OK
response.
Note: When you need a process or function which handles webhook payloads, it should be implemented to be executed asynchronously from that of which responds to the server. If they are executed synchronously, it can cause the endpoint to stop working properly when many events happen on your application.
Headers
HTTP POST
requests from Sendbird server will include the following headers.
x-hub-signature
Used as a request header to ensure that the source of the request comes from Sendbird server and the request is not altered by external influences. Based on both the POST
request body and your API token, the value of the x-hub-signature
starting with sha1=
is generated by SHA-1
encryption on the Sendbird server side. To verify the request on your server side, create a comparison value exactly the same way as Sendbird server does, and then check if the result is equal to the value of the x-hub-signature
.
Note: Upon creation, each bot is given a secret key which can be found on your dashboard. The secret key is encrypted and used to generate a value of
x-hub-signature
header for HTTP requests.
Data structure
All webhook events depend on the following data structure.
List of properties
Property name | Type | Description |
---|---|---|
eventType | string | The type of the event. |
botWebhookEvent | nested object | An object that contains information about the bot and the chat message from a customer. |
ticket | nested object | An object that contains information about the ticket. |
Webhook events
Ticket
Event | Triggered when |
---|---|
A bot receives the message sent by a customer. |
MESSAGE.RECEIVED
The following shows a webhook payload of a MESSAGE.RECEIVED
event.