In a project we have this private Facebook group for random links and notifications. Instead of sending annoying e-mails to every group member whenever somebody makes a
git push to our GitHub repo, I created a simple service that posts post receive hook information to that Facebook group's wall instead.
The service is a simple Sinatra server which uses the Koala gem for Facebook's Graph API.
Download this web service and install dependencies (uses Bundler).
git clone git://github.com/johanbrook/github-facebook-hook.git cd github-facebook-hook bundle install
A neat way of generating an Access Token is to visit Facebook's Graph API Explorer and generate from there. Note that the access token seem to have very short expiration time – I currently have to regenerate it every 2 hours or so. I'll investigate.
When you have your token, add it to
keys-sample.rb and rename that file to
module Keys ACCESS_TOKEN = "<your token here>" end
Be sure to change the require in
require "./keys" instead of
Check that everything works.
ruby app.rb open http://localhost:4567
You should see a "Nothing here" text.
Now create a free Heroku app to host the web service (if you have another server, skip this step).
heroku create <appname> --stack cedar git remote add heroku email@example.com:<appname>.git
Add the access token as a Heroku environment variable.
heroku config:add FB_ACCESS_TOKEN=<your token>
When that's done, grab the URL to your Heroku app (something like
Next, go the the GitHub repo you want to watch, and choose "Admin" > "Webhooks & Services" > "Add webhooks". Add the URL to your Heroku app and append
Press "Update Settings".
Whenever somebody pushes to the GitHub repo, your web service on Heroku will receive a POST request, and pass that along to a Facebook group's wall with the Graph API. Neat, eh?
Stuff I should do
- Make the tool more general and ready almost out-of-the-box. Don't make it involve that many steps.
- Support not only group walls, but user and friends' walls as well, perhaps with different routes.
- Better handling of access token.