---
title: "Wooster Scripting for Fun & Profit"
summary: "How the HubSpot Dev Team harnesses Wooster to accomplish some very serious, mission-critical stuff. Very. Serious."
date: 2012-04-17
authors: [thomas-petr]
topics: [DevEx]
canonical: https://product.hubspot.com/blog/bid/84948/wooster-scripting-for-fun-profit
cover:
  scene: wooster-scripting-for-fun-profit
  alt: "A little robot butler lifts the cloche off a silver tray to serve a laughing developer an orange hashtag."
---

One of my favorite things about working at HubSpot is everyone's great sense of humor. The developer chatroom chronicles most of our zany antics, and it's facilitated by our very own robotic butler, **Wooster Bot** (named after [Bertie Wooster](http://en.wikipedia.org/wiki/Bertie_Wooster), and based off of GitHub's [Hubot](https://github.com/blog/968-say-hello-to-hubot)).

## These bros want a chat bot...

Wooster is pretty smart; we've taught him how to evaulate mathematical expressions, translate text between languages, kick off new builds, generate a whole slew of different meme photos, and even tell us what today's specials are at the [deli across the street](http://www.2ndstcafe.com/). Any employee can add more functionality to Wooster by writing a node.js script. What else can we do with Wooster?

## #JFDI

[David Cancel](https://twitter.com/dcancel), our fearless leader Chief Product Officer, is known for his poignant, humorous, and often quotable hashtags:

> .@[antrod](https://twitter.com/antrod) lots of books and events cause a new sucker is born every day. [#FAKERZ](https://twitter.com/search/%2523FAKERZ)
>
> — David Cancel (@dcancel) [April 9, 2012](https://twitter.com/dcancel/status/189342801601904641)

> Boston Startupers beware. [#GeekswithGuns](https://twitter.com/search/%2523GeekswithGuns) is back. [#actlikeyouknow](https://twitter.com/search/%2523actlikeyouknow)
>
> — David Cancel (@dcancel) [April 5, 2012](https://twitter.com/dcancel/status/187912923757293568)

> The @[HubSpot](https://twitter.com/HubSpot) sales team is making it rain like a Lil Wayne video today! [#majorleagues](https://twitter.com/search/%2523majorleagues)
>
> — David Cancel (@dcancel) [March 30, 2012](https://twitter.com/dcancel/status/185781126663643136)

So we figured, let's harness this corpus for some laughs.

## A man's gotta have a code.

We can implement this easily in [CoffeeScript](http://coffeescript.org/):

```coffee
module.exports = (robot) ->

  # twitter API url
  url = 'https://api.twitter.com/1/statuses/' +
    'user_timeline.json?include_entities=true' +
    '&screen_name=dcancel&count=199'

  # respond when someone says "@wooster dc"
  robot.response /dc$/i, (msg) ->

    # hit twitter API
    msg.http(url).get() (err, res, body) ->

      # catch HTTP errors
      if err
        return
 
      # parse response JSON
      data = JSON.parse body

      # catch API errors
      if data.error
        msg.send "Error: " + data.error        
        return

      # get list of hashtags
      hashtags = tweet.entities.hashtags for tweet in data

      # flatten hashtag list
      hashtags = [].concat.apply [], hashtags

      # respond with a random hashtag
      if hashtags.length > 0
        index = Math.floor(Math.random() * hashtags.length)
        msg.send '#' + hashtags[index].text
```

Our final implementation makes use of Redis as a backing store to minimize how often we hit the Twitter API, but this was left out to improve clarity.

## Hello World

After deploying to our new Wooster script, we're in serendipitous hashtag heaven!
