A server that sends an admin message when a group channel is created on Sendbird.
The server handles the incoming webhooks from Sendbird using Express and sends chat messages by making an outbound request at Sendbird's Platform API.
And the admin message says:
“Don’t call us, we’ll call you” - Hollywood Principle
The demo server is available at https://chat-server.chriswang.tech/webhook
- Set your Sendbird API token.
export SENDBIRD_API_TOKEN=<YOUR_SENDBIRD_API_TOKEN>
- Start the local server
npm start
A POST
request at the /webhook
route is handled by the following middleware functions in the following orders.
verifySignature
calculates the hmac from the raw body and compares it withx-sendbird-signature
.
- If the result is an exact match, the function calls the next function in the chain.
- Otherwise, the function returns a
401
error response.
checkCategory
checks if the category of the webhook event is 'group_channel:create'.
- If the result is true, the function calls the next function in the chain.
- Otherwise, the function ends the chain.
sendMessage
makes aPOST
request to Sendbird's Platform API with thechannel_url
in the incoming webhook.
- If the request is sent successful is successful, the function returns a
200
response withsuccess: true
in the body. - Otherwise, the function returns a
200
response withsuccess: false
in the body.