Skip to content

A server that sends an admin message when a group channel is created on Sendbird.

License

Notifications You must be signed in to change notification settings

mw866/chat-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A server that sends an admin message when a group channel is created on Sendbird.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published