Hubot

We used to run Hubot on Heroko until it crashed, not sure what happened exactly but we didn't bother bring it back due more pressing issues within our company.

Then I saw one of the most georgeous presentations ever, Intergalactic Javascript Robots from Outer Space, and it got me excited to run a Hubot again.

This time I wanted to Deploy Hubot onto UNIX. I followed the excellent article, and made some adjustments below in this blogpost to accomodate better system integration and copypastability :)

First Off

I'm assuming you use Campfire. Let's create a bot user by the name hubot there. Make sure has a working email address because Campfire will want to validate it.

Hint: It's fun to give your hubot@yourcompany.com a nice avatar at gravatar.com.

All done? Let's install!

Install

# Prerequisites
aptitude install build-essential libssl-dev git-core redis-server libexpat1-dev logtail

# If you don't have node 0.6+
NODE_VERSION="v0.8.0"
NODE_BASE="node-${NODE_VERSION}"
pushd /usr/local
  wget https://nodejs.org/dist/${NODE_VERSION}/${NODE_BASE}.tar.gz
  tar xf ${NODE_BASE}.tar.gz -C src && cd src/${NODE_BASE}
  ./configure && make && make install
popd

# Coffeescript
npm install -g coffee-script

# Hubot
pushd /usr/local
  git clone git://github.com/github/hubot.git && cd hubot
  npm install
popd

Note that npm is bundled with node since v0.6.3.

Hubot System User

$ adduser --disabled-password --gecos "" hubot

Upstart Script

$ cat <<EOF > /etc/init/hubot.conf
description "Hubot Campfire bot"

# Campfire-specific environment variables. Change these:
env HUBOT_CAMPFIRE_ACCOUNT='companyname' # the one in: <companyname>.campfirenow.com
env HUBOT_CAMPFIRE_ROOMS='123456'
env HUBOT_CAMPFIRE_TOKEN='afafafafafafafafafafcdcdcdcdcdcdcdcdcdc'

# Subscribe to these upstart events
# This will make Hubot start on system boot
start on filesystem or runlevel [2345]
stop on runlevel [!2345]

# Path to Hubot installation
env HUBOT_DIR='/usr/local/hubot/'
env HUBOT='bin/hubot'
env ADAPTER='campfire'
env HUBOT_USER='hubot' # system account
env HUBOT_NAME='bot' # what hubot listens to
env PORT='5555'

# Keep the process alive, limit to 5 restarts in 60s
respawn
respawn limit 5 60

exec start-stop-daemon --start --chuid \${HUBOT_USER} --chdir \${HUBOT_DIR} \
  --exec \${HUBOT_DIR}\${HUBOT} -- --name \${HUBOT_NAME} --adapter \${ADAPTER}  >> /var/log/hubot.log 2>&1
EOF

Now don't forget to $EDITOR /etc/init/hubot.conf and change the 3 HUBOT_CAMPFIRE_ environment variables.

To start, type:

$ start hubot

To check the log, type:

$ logtail /var/log/hubot.log

Use

Now check Campfire to see if Hubot entered the room, and tell him to send you an image; type:

bot: image me donuts

Some other commands to get you started may be retrieved by issuing:

bot help

This will show you:

bot <user> is a badass guitarist - assign a role to a user
bot <user> is not a badass guitarist - remove a role from a user
bot animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
bot convert me <expression> to <units> - Convert expression to given units.
bot die - End hubot process
bot echo <text> - Reply back with <text>
bot help - Displays all of the help commands that Hubot knows about.
bot help <query> - Displays all help commands that match <query>.
bot image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
bot map me <query> - Returns a map view of the area returned by `query`.
bot math me <expression> - Calculate the given expression.
bot mustache me <query> - Searches Google Images for the specified query and mustaches it.
bot mustache me <url> - Adds a mustache to the specified URL.
bot ping - Reply with pong
bot pug bomb N - get N pugs
bot pug me - Receive a pug
bot show storage - Display the contents that are persisted in the brain
bot show users - Display all users that hubot knows about
bot the rules - Make sure hubot still knows the rules.
bot time - Reply with current time
bot translate me <phrase> - Searches for a translation for the <phrase> and then prints that bad boy out.
bot translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional
bot who is <user> - see what roles a user has
bot youtube me <query> - Searches YouTube for the query and returns the video embed link.

Going Forward

You can write your own Hubot Scripts, or use those by others.

Happy hubbing :)