Skip to content

Latest commit

 

History

History
38 lines (27 loc) · 1.94 KB

README.md

File metadata and controls

38 lines (27 loc) · 1.94 KB

Chat Server

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

Demo

The demo server is available at https://chat-server.chriswang.tech/webhook

Getting Started

  1. Set your Sendbird API token.
export SENDBIRD_API_TOKEN=<YOUR_SENDBIRD_API_TOKEN>
  1. Start the local server
npm start

Design

A POST request at the /webhook route is handled by the following middleware functions in the following orders.

  1. verifySignature calculates the hmac from the raw body and compares it with x-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.
  1. 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.
  1. sendMessage makes a POST request to Sendbird's Platform API with the channel_url in the incoming webhook.
  • If the request is sent successful is successful, the function returns a 200 response with success: true in the body.
  • Otherwise, the function returns a 200 response with success: false in the body.