Heroku makes it easy to post a webhook when you deploy an app using the HTTP Deploy Hooks add-on but there’s no way to post the webhook to more than one URL. This is a problem if you want to notify a few different services of the deploy, like an exception tracker and NewRelic. Of course you could spin up a new app just to catch the webhook and resend it, but that’s a lot of nonsense for something that should be simple.
The other alternative is to use Torpio, which makes it dead-simple to catch the webhook and resend wherever you like. It’s a great service for building lightweight connectors between services with some nice features:
- scripts are written in CoffeeScript 🙂
- your scripts have access to simple HTTP and logging functions
- scripts can be triggered via a webhook or email
- it’s free for a reasonable number of scripts & executions
Let’s walk through how to use Torpio to setup a script that will catch the deploy webhook from Heroku and resend it to a few services.
Heroku Deploy Hooks Using Torpio
First, sign in and create a new script. Scroll down to the bottom and you’ll see the webhook URL. Copy this and then log into your Heroku account and go to the deploy hooks add-on. Enter the webhook URL and hit save.
Copy in this code for your script:
This script does a few things. First, you can enter multiple URLs that accept Heroku’s deploy hook without any changes. The format is a simple
application/x-www-form-urlencoded POST with few parameters. The most important are
head. You can see the rest in the HTTP deploy hook docs. Because Torpio passes in the webhook body without modification, we can simple repost this to the URLs that we need. Most developer-related services will accept Heroku’s webhook format without any changes.
For services that don’t accept Heroku’s webhook format (NewRelic, for example), we can craft our own body and POST it. Since we want to be able to use this same script for multiple apps, the script does a bit of translation from the Heroku app slug to the NewRelic app ID. We can then use the same webhook URL and script for every app.
That’s it! This is a very simple example of the sort of thing you can do with Torpio. They have some great examples in their getting started guide and excellent developer docs. If you need to integrate one of their supported services, you even get built-in authentication management which is a really awesome feature and a huge time-saver.
Go forth and integrate!