Webhooks Made Easy

Webhooks, we use them all the time, whether it’s to trigger and CI build, notify someone about an action or to trigger a deployment.

Making a program to listen for and validate a webhook isn’t terribly difficult, but it is tedious and who likes to write the same code over and over? anyone? … that’s what I thought 🙂. So I’m going to go through creating a simple program to listen for a GitHub Release event and Tweet about it on Twitter.

#1 Creating a GitHub Webhook

Navigate to to the repository you wish to create the webhook for and go to Settings -> Webhooks.

https://github.com/<username or organization>/<repository>/settings/hooks

Now select “Add webhook” and input your information and hit “Add webhook” at the bottom to create it; I recommend when creating your own to not select “Send me everything” and only select the individual events, in this case only the ‘Release” event.

Keep track of the Payload URL, Port and Secret in this case “/webhook”, “4434” and “mySuperWebHookSecret”, we’ll need it in our program later.

And if all information was correct you will end up with a WebHook

#2 Creating Twitter Application

Logged in under the Twitter account you wish to Tweet the release information, navigate to https://apps.twitter.com/app/new and enter your desired Application Name, Description and your website address; you can leave the Callback URL empty.

After creating the Twitter Application, select the “Keys and Access Tokens” tab and select “Create my access token”

After that take note of the Consumer Key, Consumer Secret, Access Token and Access Token Secret as we will need them in our program.

#3 Creating our application

Now that we have all the necessary information we can create our application. We will be using the following two library’s to accept the Webhook and post a Tweet:

As a final note, I think that it bears mentioning that go-playground/webhooks not only supports GitHub but also Bitbucket and GitLab as well.

Like what you read? Give Dean Karn a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.