Skip to main content

Sparkbox Gems

11-01-16 Patrick Simpson

We have a lot of fun at Sparkbox. And we say some pretty hilarious things too. Patrick walks through how he created a way for the public to partake in our entertainment.

Sparkbox is a fun, exciting, and sassy place. We often say things to one another that are pure gold, a conversational “gem” so to speak (not to be confused with a Ruby Gem). Gems are snippets of a conversation that can stand on their own, but they can also be ridiculously hilarious taken out of context. To highlight these gems, we’ve created something we think you’ll find entertaining, sometimes confusing, but definitely enlightening when it comes to our endless stream of inside jokes. Introducing Sparkbox Gems.

To clarify, Sparkbox Gems is more than just fun and games—creating it was also a great development exercise. The following details how I used the Slack API to build out a rich, Slack-data-driven website of pure entertainment!

#gems Slack Channel

Our #gems channel allows our team to share anything we believe is “gem worthy.” I wanted to share the fun with the rest of the world outside Slack, so I wrote gem-fetcher, which fetches our #gems channel messages using the Slack rubygem.

For fetching messages, we need to get the channel history for our #gems channel and iterate through the messages:

 def history
    slack.channels_history channel: GEMS_CHANNEL_ID, count: 1000, latest: timestamp, inclusive: true
  end

See the code on github.

A helper method, to fetch channel history:

  def messages
    history['messages']
  end

See the code on github.

To allow us to retrieve messages like this:

 messages = slack.messages
    puts "We have #{messages.count} messages starting at '#{ts}' time"
    messages.each do |message|

See the code on github.

What about Privacy?

Occasionally, something might show up in the #gems channel that is hilarious but maybe not a good fit for a global audience. All Sparkboxers have the same amount of authority to add a gem, make it public, or make it private.

An earth_* emoji reaction is how we determine if a “gem” is worthy to share it publicly with the world.

This is done by looking at the messages reactions (Slack API):

reactions.each do |r|
  if  /^earth_*/.match(r["name"])

See the code on github.

A red x :x: veto reaction ensures the gem does not make it to our public audience. This is done when we don’t really think what we’ve said makes sense for the whole world.  We do have a lot of inside jokes around here.

if  /^x/.match(r["name"])
  disapproved = true

See the code on github.

One vote makes it public. One veto makes it private. Once the message has been determined for  public use with the “earth” reaction (without a disapproval), it will get added to the JSON data file. This JSON data file is served up with a small website to showcase our gems. The JSON data file is created once and only updated occasionally.

Gem-me-bot: Gem Automation

In addition to our gem showcase, I created a gem bot, that would help us add gems to our #gems channel anywhere in a public Slack channel. The gem-me-bot is a bot that is looking for `:gem:` reactions.

As soon as one is found, it will parse the message and add it to the #gems channel in Slack

The gem still needs to be made “public” by our standard voting process, shown by the earth reaction in the image. The gem-me-bot is independent from our gems website and lives on github.

Conclusion

The creation of Sparkbox Gems was meant to be as silly as the #gems channel. And it really is just that. I discovered how easy it is to use the Slack API to create something in a freakishly fast timeframe (a couple nights). Truly, there are many great things that can be done with the Slack API. I hope our gems website gives others inspiration to create their own Slack-powered webs, even if just for the laughs.

Related Content

User-Centered Thinking: 7 Things to Consider and a Free Guide

Want the benefits of UX but not sure where to start? Grab our guide to evaluate your needs, earn buy-in, and get hiring tips.

More Details

See Everything In

Want to talk about how we can work together?

Katie can help

A portrait of Vice President of Business Development, Katie Jennings.

Katie Jennings

Vice President of Business Development