Say Hello to Hubot
For the past year or so we’ve been telling people about Hubot, our amazing Campfire bot. We have a lot of fun working on Hubot. He makes us laugh, he…
For the past year or so we’ve been telling people about Hubot, our amazing Campfire bot. We have a lot of fun working on Hubot. He makes us laugh, he ships our code, he is the interface to our CI server, and a whole lot more. Over the last year, he’s grown bigger and messier. So we decided to rewrite him from scratch, open source him, and share him with everyone.
Meet Hubot.
What we’ve come up with is a nicer implementation of the previous Hubot. One that we think a lot of our users will enjoy working with if they want to automate everyday tasks. Even better though, you can host your own Hubot on Heroku for free. Hubot scripts can be written in CoffeeScript or Javascript and he can persist data to Redis with Heroku’s free Nano addon.
github/hubot
Hubot is a library and an executable that wraps up all the logic of connecting to chat servers. Right now there are adapters for Campfire and IRC, but adding stuff like Hipchat or other services should be pretty trivial. The main hubot library is where the core of Hubot lives, but it just scratches the surface.
github/hubot-scripts
These are where Hubot’s scripts reside. This is where the magic happens. The fun stuff, the serious stuff, the weird stuff… hubot-scripts is designed as a place where we can share scripts with the entire community at large. You can browse it for interesting scripts, drop them into your own bot, and contribute your own work to the repository.
Hubot internals
At his core, Hubot simply idles in various rooms and waits for specific strings to go by in the chat.
robot.hear /problem??/i, (msg) ->
msg.send "http://cl.ly/BG7R/trollface.jpg"
With this snippet, Hubot will listen for the phrase problem?
, and then dutifully embed the classic trollface image into the chat.
Sometimes listening for strings isn’t what you want. Sometimes you want to command Hubot to do your bidding. For that, the robot has a different method.
robot.respond /(image|img)( me)? (.*)/i, (msg) ->
imagery = msg.match[3]
msg.http('http://ajax.googleapis.com/ajax/services/search/images')
.query(v: "1.0", rsz: '8', q: query)
.get() (err, res, body) ->
images = JSON.parse(body)
images = images.responseData.results
msg.send msg.random images
This snippet pulls down a random image from Google Image Search. Something like hubot image me pugs
would find a random pug image and paste it into the channel.
Every Hubot is powered by npm so you can easily bring in whatever Javascript libraries you want. Check out the scripts directory to see some more script examples.
YourBot
We really love Hubot. It’s a shared side project that everyone at GitHub can (and does!) contribute to on a regular basis. For us, Hubot’s much more than just a repository and a collection of scripts… he’s part of our culture.
We’re giving you the core of Hubot, and some of the scripts that make up Hubot. But it’d be a shame if you just stopped there. Build out some of your own scripts. Let your company take your bot however you’re destined to take it. We bet you’ll enjoy it as much as we do.
Written by
Related posts
The top 10 gifts for the developer in your life
Whether you’re hunting for the perfect gift for your significant other, the colleague you drew in the office gift exchange, or maybe (just maybe) even for yourself, we’ve got you covered with our top 10 gifts that any developer would love.
Congratulations to the winners of the 2024 Gaady Awards
The Gaady Awards are like the Emmy Awards for the field of digital accessibility. And, just like the Emmys, the Gaadys are a reason to celebrate! On November 21, GitHub was honored to roll out the red carpet for the accessibility community at our San Francisco headquarters.
Students: Start building your skills with the GitHub Foundations certification
The GitHub Foundations Certification exam fee is now waived for all students verified through GitHub Education.