Jun 27, 2016
We had a hack day at Songkick a few weeks back, and I decided I wanted to build something with Slack. Like any sensible company, we use Slack to help us colaborate and improve communication, but we also use it to share catgifs (we have an entire channel) and a whole host of default, aliased and custom emojis. Based on this, I wondered if I could use our emoji use to gague the average mood of the whole company. And so SlackMood was born.
My first step was figuring out how to get a feed of messages across our whole Slack. I’d already decided to build it in Golang, fortunatey some clever person had already built a Golang library for Slack, saving me a huge amount of work. I registered a new bot on the Slack developer site and started hacking.
Unfortunately I quickly ran into an issue. I wanted to get the RTM (real-time message) feed of every channel, but it turns out bot accounts can’t join channels unless their invited. I could see 3 solutions to this;
I decided to go with 3, as it seemed the simplest to implement.
The actual code for this was relatively simple
It then passes the message object into a function that extracts the emoji counts
It uses both a regular expression on the message, and interating over the reactions.
I’d decided to use BoltDB for the backend storage, maybe not the best idea as I think a relational datastore like Sqlite would have been much better suited, but Bolt was a technology I’d never used before so it seemed interesting. We generate a message ID from the base message, then the reactions all have their own IDs based on the user who posted them. These are all stored in BoltDB as message ID -> details, where details is a struct describing the emoji;
Now we’ve got a list of emojis and their timestamps, we can go through and assign each one a rating, of ether positive, negative or neutral. Fortunately, some of our team had already built a spreadsheet of emoji sentiment analysis for a previous hack project (turns out, we love emojis).
With our emoji ranks loaded into a struct array, we can go through and analyse the score of our current listed emoji
(N.B. looking back at this now, I realize a map of emojiname -> mood would have been much better rather than a double-loop, but this was like 6 hours in and I’d been drinking a little).
Now we know the mood of all the emojis, calculating the graph just involves iterating through all the seen emojis and storing them in a map of date->mood. The
GetMood function above works on a list of emojis, so we just bucket the emojis by the selected time period.
Due to storing all the emoji in Bolt and not being able to do proper filtering, we first filter by the time period we care about, then divide this up.
GraphMood returns a struct array which we can just JSON encode and feed into Chart.JS to get the nice visualization above.
All in all, it was pretty fun but the whole project contains a lot of terrible code. If you want, check it out on Github here.
Other stuff I would have liked to add:
Maybe next hack day.
P.S. if you fancy working somewhere with regular hack days, in a team which has a pre-prepared spreadsheet with emoji sentiment analysis, Songkick are hiring a variety of technology roles at the moment. So come work with us, we have a 60% SlackMood happyness rating(tm)