Primal Data Advent Calendar #3: How to discover the most used emojis in your Slack channel

Michal Koláček
Slido developers blog
4 min readDec 5, 2020

--

This piece is a part of the Primal Data Advent Calendar, a series of miscellaneous articles written by the Slido Data Team. We release one on each Advent day that happens to be a prime (like 5 for the 5th of December). Enjoy!

Emojis (not just) in Slack are great. They allow us to show emotions without needing to write even a single word. For curious folks like me, this way of reaction also makes it readily available for analysis and finding out some interesting bits and pieces from it.

Following the steps outlined in this article, you can also become a master of trivia when it comes to emojis. Wonder no more what the most used emoji in any of your Slack channel is!

To get to the bottom of this, we will firstly obtain an access token, then pick a channel, gather all its messages, and finally get corresponding emoji reactions. In technical terms, we'll utilise methods:

from Slack API and Python's libraries requests and pandas.

Note that by using this guide your stats will reflect emoji reactions to “main” messages in a channel, not emojis used in threads or message contents.

Get Access Token

Head to Your Apps of your Slack Workspace and create a new app or make sure to have an access to an already existing app that you can leverage.

In the app, navigate to OAuth & Permissions and ensure that user token scopes include all of those that are required by the methods, i.e. channels:read, channels:history, and reactions:read.

When everything matches up, (re)install the app to your Workspace and copy the OAuth Access Token. You will need it in a minute.

Getting the OAuth Access Token from Slack App’s OAuth & Permissions page

Find Channel ID

Once you decide for which channel you'd like to check emoji usage, you need to get its ID. And there are two ways of doing so.

If you are thinking of one particular channel, the easiest thing to do is to simply go to your Slack Workspace’s URL in a web browser, which follows the format of yourworkspacename.slack.com, and navigate to it. The URL will then follow a pattern of app.slack.com/client/TXXXXXXXX/CXXXXXXXX. The TXXXXXXXX is your Team ID, the CXXXXXXXX is the Channel ID – that's what you are after.

If you just cannot decide or you'd prefer to see more details first, the method to use is conversations.list. Running the sample piece of code below, Slack returns a payload with not only channel IDs but also some other handy information, e.g. when they were created or how many people joined them.

Store Message IDs

When you choose a channel to your liking and acquire its ID, you are ready to get all the message IDs from it. These are crucial as they create the missing link between the channel and emoji reactions.

The IDs are stored in a form of a unique UNIX timestamp and can be easily retrieved by the conversations.history method. Let's get them all and save them into a list called msg.

Notice that the Slack API's maximum limit for the response is 1000, hence you might need to run the code multiple times or create a for loop to go around it, esp. in case you have a rather active (or old) channel. As an alternative, you can take only certain timeframe by using arguments oldest and/or latest.

To do this for a private channel (whose channel ID is in the GXXXXXXXX format), include groups:history into the user token scopes. Apart from that, everything works exactly the same.

Get Emoji Stats

Using the message IDs (saved in the msg variable), you can obtain the number of emojis used per each of the message by calling reactions.get method.

To get a quick glance at the overall results, you may simply sum all the counts per emoji and show the top 30.

By tweaking the last few lines a bit, you can easily allow for deeper level of detail by also grouping by time.

Play around

Now you have the dataset and the real fun begins – getting your hands dirty with the numbers and finding something that catches your (and later maybe even someone else's) eye.

For instance, below you can see one of the things that caught mine when analysing emojis from our Slido Slack.

Emoji stats of the #data_team channel in our Slido Slack

What can you find out in yours? Let me know in the comments!

--

--