Simple HipChat notifier

We needed a simple way of sending messages to HipChat (great online chat software, BTW), so I cooked up this:


#!/usr/bin/env perl

use strict;
use warnings;
use WWW::Mechanize;

# See https://www.hipchat.com/docs/api/method/rooms/message for info
my $url = 'https://api.hipchat.com/v1/rooms/message';
my $api_key = 'your-api-key';
my $from = 'User-to-post-as';
my $room = 'room-to-post-to';
my $message = $ARGV[0];
my $color = $ARGV[1];

my $mech = WWW::Mechanize->new;
$mech->post( $url, {
room_id => $room,
from => $from,
color => $color,
message => $message,
auth_token => $api_key,
});

Quick and dirty - no error checking. Works well for the situations we are using it in, but you may wish to make something more robust before doing anything serious with it.

Enjoy!

Leave a comment

About Jason A. Crome

user-pic Software developer for DEVNET, Inc. I write web applications for local government using Perl.