Web hook fundamental

  • Learn Mocking Web hook
  • Creating local web hook using express
  • Integrate local web hook with GitHub
  • Integrate Twilio serverless function

Visit this read me here as well

Introduction to Web hook

Create mocked web hook handler at here https://beeceptor.com/

Create web hook in Discord

Copy the URL and append /github and add this URL in the GitHub web hook.

Writing our own local server

Now we write our own server to post to discord web hook. Check this project

Run npm start to start your local web server.

Let’s expose local server to internet

ngrock is a npm package that converts your local server to public URL.

Setting up ngrok in local window machine?

ngrok opens up tunnel to local machine. So that your application can be publicly accessible through the tunnel.

Now our local server is running at http://localhost:3000

Lets install ngrok and open this port for internet.

Download ngrok and run the exe.

Add ngrok.exe path in the system environment so that you can access from anywhere.

Creating public URL using ngrok

We will expose local server over internet by getting brand new internet URL. Open powershell run below script to expose localhost:3000 to public internet.

ngrok http 3000

My local server is accessible over internet and I get http and https both URLs available to browse over internet

Next I can visit my URL over internet

Hooking up local server with GitHub

Now in your github you can go and add the web hook URL that you generated just now. Make sure to append /github on your URL.

Now if you start github repo you will receive the message to your discord channel.

You can visit the web hook payloads at this address http://localhost:4040/inspect/http from ngrok.

Here is the code so far

Next lets read the Avtar URL from Github payload

When we star/un-star we can read the avtar_url of the user and show that in discord.

How to start your local server in watch mode?

  • Install npm i nodemon -g
  • Then run nodemon start to start your server in watch mode.

Now you can notice that we are able to post the avatar of the user from github to our discord channel.

const avatarUrl = req.body.sender.avatar_url;

Here is the source code so far

Twilio

Twilio is a serverless solution that can respond to SMS coming to a virtual phone number.

Create a flow in Twilio to speak up when someone calls you.

Record voicemail and send to web hook

You can record voicemail, convert voice to text

And use web hook URL to send the transcript.

You can install Twilio-CLI globally to send messages from your local development machine.

npm i -g twilio-cli

Next login to twilio by running twilio login

Run below script

twilio plugins:install @twilio-labs/plugin-serverless

Creating Twilio project

Create project

twilio serverless:init ideacatcher --empty

Run project

twilio serverless:start

Navigate to http://localhost:3000/send-test

Your server is up and running.

Reference

Web hooks for Beginners - Full Course