Topic: Work Tools Revamp - Hubot for IRC logging

Topic type:

How to set up Hubot for IRC channels with a web accessible log viewer

This took a bit to find all the parts for, but in the end it was pretty simple.

For a remote worker on an open soruce project like myself, IRC is really handy for keeping in touch with other team members.

However as someone on the other side world and in a very different time zone as the other team members, having an IRC without a log to refer back to was a real pain. Obviously I needed a bot to log the channel.

On a previous project that used Campfire, I got to know Hubot. I knew that Hubot was very extendable and had an IRC adapter so I figured I would jump on the Hubot bandwagon.

Here's what I did:

  1. installed Node.js and Redis that Hubot depends on
  2. cloned hubot irc runnable to a directory named after my new bot

    git clone https://github.com/jgable/hubot-irc-runnable.git mynewbot
    cd mynewbot
  3. edited mynewbot's package.json do add hubot-logger as a dependency

    ...
    "dependencies": {
    ...
    "hubot-logger": "~0.0.11"
    }...
  4. installed mynewbot's dependencies with npm install
  5. edited the necessary environmental variables in runbot.sh:

    # Set Environment Variables
    export HUBOT_IRC_NICK=mynewbot
    export HUBOT_IRC_SERVER=irc.freenode.net
    export HUBOT_IRC_ROOMS="#channel1,#channel2"
    export IRCLOGS_PORT=3000 #or whatever port you want your node express app to listen on for serving archives of logs
    export IRCLOGS_FOLDER="/path/to/where/i/want/logs"
  6. added a new external-scripts.json that looks like this:

    ["hubot-logger"]
  7. edited hubot-scripts.json to drop "tweet.coffee" (was causing errors on start for me) and add other scripts from hubot-scripts that I wanted
  8. ran ./runbot.sh

Now your bot should log into your channels and start logging. Without further set up, your IRC logs would be available on localhost:3000 from your browser.

Optional steps that you will probably need

I want to have my logs be publicly available, so I went ahead and set up a new Digital Ocean host with all of the above set up plus the following:

  1. set up DNS to point at my new host as a subdomain of an existing registered domain, in my case this was an A record that pointed at the IP address Digital Ocean gave me
  2. set up my new host to forward requests for port 80 to port 3000 since I didn't want to run node as a priviledged user (you have to be root to listen on port 80 otherwise) as per this stackoverflow answer
  3. ran the ./runbot.sh command from with a screen session so I log out and leave it running
  4. add something that will restart ./runbot.sh if it dies, I did the following:

This uses an UpStart init script to respawn the process if it dies (and start it at boot, etc.). Place the file under /etc/init/mybot.conf (rename mybot.conf to whatever you named your bot's directory) and edit to suit. I based it off the steps found in http://kvz.io/blog/2012/11/20/installing-hubot-on-ubuntu/.

The Result

You can check out my working example here:

http://irc.waltermcginnis.com/irclogs/

Enjoy your new Hubotness!

Discuss This Topic

There are 0 comments in this discussion.

join this discussion