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.
verifySignaturecalculates 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
401error response.
checkCategorychecks 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.
sendMessagemakes aPOSTrequest to Sendbird's Platform API with thechannel_urlin the incoming webhook.
- If the request is sent successful is successful, the function returns a
200response withsuccess: truein the body. - Otherwise, the function returns a
200response withsuccess: falsein the body.