Analyzing Interactions in a Slack Communication Network

Analyzing Interactions in a Slack Communication Network

Memgraph
Topics:

We recently held a company-wide hackathon where we challenged each other to build compelling, useful applications using a streaming data source, Kafka, Memgraph, and a Web Application backend. This week we’re looking at a Slack bot that can help you understand how your teammates interact.

Our team spent Hackathon week building a graph application on top of streaming Slack data. If you want to jump right to the code, check out the GitHub repo, and if you want to learn more about it, join our Discord Community Chat!

The Data Source

We knew that we wanted to do something with Slack data because the API was friendly, bots are fun to play with, and modeling with it would be relatively straightforward.

The Data Model

The bot can only gather information from channels it is a part of. Whenever you add a bot to the channel, the bot will collect the last X messages (this is configurable when starting the bot) and use those messages as cold start.

The graph model is straightforward, and it’s illustrated below:

data-model

Each user represents a unique node in the graph. Users post messages in the channels. They also react with emojis to messages posted by other users.

Each message contains a certain amount of words. For styling purposes, each user, besides their unique id and name, has their avatar. There are four kinds of nodes in the graph: User, Message, Word and Channel, and we draw edges for reactions, posts, word count, and messages. This simple graph will provide the data model for our analytics.

The Full App Architecture

Slack offers an API that allows an application to consume messages through events. A local Kafka cluster is set up, and the producer (Slack-Kafka connector) sends the data to the Kafka broker and is then consumed in real-time by Memgraph through a stream. Memgraph then updates its knowledge graph in real-time, and the bot handler consumes the analytics upon the user’s request.

This architecture can be depicted in the following picture:

architecture

Communicating with the Bot

The user communicates with the bot in Slack chat with the help of the commands:

/influence me

Get information about you in all the channels visible to the Bot. The Bot’s answer will contain the words you like to use in your messages and emotes you use the most to react to your fellow colleagues’ posts across all channels.

bot

/influence me in <#channel>

Get information about you in <#channel>. The Bot’s answer will contain the words you like to use in your messages and emotes you use the most to react to your fellow colleagues’ posts in the selected channel.

bot

/influence myself and @user

Get information on the interaction between you and @user. The Bot’s answer will contain the reactions your fellow colleagues add to your messages.

bot

/influence channels and reactions <reactions>

Get information about reactions in all channels visible to the bot. The Bot’s answer will contain the metrics about specified reactions you and your fellow colleagues use. It will give info about who uses the reaction the most and who receives it the most across all of the channels the bot is a part of.

bot

/influence channel <#channel> and reactions <reactions>

Get information about reactions in <#channel>. The Bot’s answer will contain the metrics about specified reactions you and your fellow colleagues use. It will give info about who uses the reaction the most and who receives it the most.

bot

/influence messages <text>

Get information on how to improve your message. The Bot’s answer will contain suggestions on words that should be added to your message to improve it and potentially receive more reactions in the end.

bot

In The Lab

We used the Memgraph Lab to visualize the data and understand our schema better. What we found interesting is how the graph was connected, strongly connected components, and the people who connected these strongly connected components.

memgraph-lab

Exploring how the graph is connected can be done using Memgraph’s integrated NetworkX algorithms and query modules. To find strongly connected components, we used the NetworkX algorithm strongly_connected_components. This algorithm is implemented within the nxalg query module in Memgraph MAGE. The picture below shows one strongly connected component from our humongous graph.

scc

It’s also possible to run the opposite components algorithm - weakly connected components. Weakly connected components are part of custom implemented query modules within Memgraph Mage.

wcc

Conclusion

Slack Influencer was developed for an internal Hackathon at Memgraph to demonstrate the simplicity and the power of knowledge graphs combined with streams. It was a very fun experiment, especially when we ran it internally at Memgraph.

If this sounds cool to you, check out the GitHub repo, and let us know what you think in our Discord Community Chat!

In this article
Sign up for our Newsletter

Get a personalized Memgraph demo
and get your questions answered.

Read next

identify-patterns-and-anomalies-with-community-detection-graph-algorithm
Graph Algorithms
Community Detection
Identify Patterns and Anomalies With Community Detection Graph Algorithm

Get valuable insights into the world of community detection algorithms and their various applications in solving real-world problems in a wide range of use cases. By exploring the underlying structure of networks, patterns and anomalies, community detection algorithms can help you improve the efficiency and effectiveness of your systems and processes

by
Vlasta Pavicic
March 1, 2023
why-are-nodes-with-a-high-betweenness-centrality-score-high-maintenance
Graph Algorithms
Why Are Nodes With a High Betweenness Centrality Score High Maintenance

Betweenness centrality is one of many measures you can get from performing a centrality analysis of your data. It identifies important entities in your network that are actually a vulnerability and can bring your processes to a standstill. Dive deeper into this important metric and how it can be used in various use cases.

by
Vlasta Pavicic
February 15, 2023
how-i-found-the-most-influential-users-on-hacker-news
Graph Algorithms
Real-Time Analytics
How I Found The Most Influential Users on Hacker News

Hacker News is a website that contains content from the tech industry and to find yourself among its most popular posters sometimes seems a miracle! To break the mystery around it, I tried to knowledge-hack it with Kafka and PageRank algorithm - read on to find out what I discovered!

by
Lucija Perkovic
February 10, 2023

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

by
This is some text inside of a div block.
This is some text inside of a div block.