Analyzing Slack Traffic with PowerBI

The other day in the SQL Community Slack channels, we started chatting about general usage of Slack – which channels saw the most activity, what topics were discussed, and so on. One thing led to another and I wondered if I could put that into a report for analysis. While I realized that you can’t get any sort of “top user” based on the extract I used, it was still an interesting exercise.

I went through a couple of steps to get to a usable set of data:

  1. Import the Slack JSON data
  2. Massage it
  3. Replace the user ids with usernames – mostly for better word clouds
  4. Import the data into PowerBI and play with some visualizations

Here are the final results for those who might be curious:

Importing the Data

This was one of the trickier parts, but I got some help from Constantine Kokkinos ( b | t )with a PS script to get me started. I tweaked that a bit to use OPENBULK and OPENJSON commands to parse out the fields I wanted from the JSON files. That went well until I realized I also needed the Date of the file in order to have any useful analysis because Slack Timestamps don’t contain the date, just the time. I also realized that OPENJSON and the “WITH” command require you to use the field’s case as defined in JSON. After a bunch of playing with the PS and SQL code, I tweaked Constantine’s code to something that worked and let me pull in the message text for word analysis.

 

Massaging the Data

It’s all well to get this into a table, but at that point, I realized all of the times were still in the Slack TimeStamp format and the Message Text used Slack’s UserID anytime someone was mentioned instead of their username. That makes sense as usernames can change or even be duplicated within a group, but made for word clouds that looked a little strange.

The following script creates the objects I used to store the Slack data, creates a full text index on the MessageText column to make finding user ids faster, imports some basic User info, and has the script to update the userids after the messages are imported.

Slack Usage Analysis

Now that this was all imported and somewhat cleansed, I was ready to do some basic analysis. I started a new PowerBI Desktop file, imported the data in the Messages table, and threw up some visualizations. I had to install the Word Cloud extension from the Marketplace, then exclude several noise words beyond the defaults. This included words such as “joined” and “channel”, “`” (three backticks – used to denote a text block in Slack), and a handful of integers that occur regularly.  I left the usernames intact as they only show when someone is mentioned directly in the channel.

Visualization isn’t my strong suit, but I’ve obtained permission from the admins to share the files used for this in case someone wants to play around with the data directly. You can download the files here. Have fun playing around and let me know what you think.

Comments
  1. Giorgio

    Where’s OpenBulk in the ps script?

    • paschott

      The openrowset command in the first block of SQL in that PS script pulls the contents of the json file into the variable to be consumed by the openjson command.

  2. Joshua Brock

    Great stuff…and at this point, way over my head 😉 At least all things outside of Power BI.

    So I’ve been asked to do something similar…using an existing Power BI report I’ve built that monitors/reports on our Office365 licenses, I’ve been asked to also include Slack.

    Rather than a CSV export, I was trying to find a way to use the Slack API to pull the user information needed. Essentially my managers want to see all our users and which apps they’ve been assigned and are actually using, costs associated, etc. I’ve set up additional filters for their use as well (Departments, software app, etc).

    This is a bit over my head as my experience with SQL is minimal and even more so with JSON. I simply needed all of our users (with their emails) to determine who’s using it. The extra work you did with word clouds I think they’d like to see also, but down the road.

    Any additional direction to help get me get up to speed is appreciated…thanks!

    • paschott

      I had to do a bit of digging and asking for help with my particular case. There should be ways to pull in the data directly from Slack with their JSON files, but I’d recommend looking at the Slack forums for more help there. The first part of this post dealt with importing the raw data into SQL tables. That might give you enough to analyze the users. Do a check for where a user id is in the comments and you should know if someone is using the system to post or not.

Leave a Reply

Your email address will not be published. Required fields are marked *