Tuesday, June 22, 2010

Fun with web hooks

As alluded to on Twitter by Kushal, Partychat-hooks is a nerdyfun companion to Partychat that lets you send and receive data from Partychat rooms via WebHooks.

To give a sample use case, here's how to add a "commitbot" that notifies a room whenever there's a commit made on a code.google.com project (Jehiah provides samples for other project hosting sites).

  1. Add a hook bot to the room that you wish to send messages to. It'll get assigned a hook ID of the form hookID@partychat-hooks.appspotchat.com
  2. If the room is invite-only, invite the hook bot to the room (by using /invite hookID@partychat-hooks.appspotchat.com
  3. (Optional) give the hook bot a nicer alias by using the appropriate form on its edit page
  4. Create a new post hook
  5. Copy its HTTP endpoint URL (of the form http://partychat-hooks.appspot.com/post/hookID) into the WebHook field of the "Source" page of the "Administer" tab on your code.google.com project
  6. Use this format to parse the commit data into a message that will be sent to the room (this page explains more about the JSON format):
    {% for r in json_decode(request.body).get("revisions") %}
      {{r.get('author')}} committed: {{r.get('message')}}
      http://code.google.com/p/{{
          json_decode(request.body).get("project_name")
          }}/source/detail?r={{r.get('revision')}}
    {% end %}
    

Then, a few seconds after the commit, you'll get a notification:

commitbot in action

3 comments:

  1. Hooks aren't working for invite-only rooms :( I couldn't get them to join a room once invited, now it wont recognize the hook ID as a valid email address.

    ReplyDelete
  2. Max,

    If you wouldn't mind emailing partyvhapp@googlegroups.com with some more details (room name, hook ID, etc.) we can see what's going on.

    ReplyDelete
  3. Err, partychapp@googlegroups.com

    ReplyDelete