Twitter Slackbot: Combining the potential of Twitter and Slack

The article below describes the work of Team DataMasters during a recent month-long Professional Development competition at Cybera. 

With the COVID-19 situation rapidly evolving, it’s important to adhere to the public health guidelines and stay up-to-date with the latest information from the government and public health officers. At times, it can be overwhelming to keep track of all the news and updates from different sources, and there is the risk of possibly missing out on important information that concerns you.

Over the years, government organizations have been increasingly using Twitter as a popular medium to disseminate information to the mass public. During a recent internal hackathon competition at Cybera, our team, the DataMasters, wanted to tap into Twitter’s potential and develop a solution to stream important tweets related to COVID-19 in real-time, and deliver it as a Slack message. 

Why did we choose Slack for our prototype?

Slack is a common communication platform used across organizations (including Cybera). It offers the ability to integrate with various software and services. Our team envisioned a scenario where a person busy at work gets a notification in Slack whenever there is a COVID-19 update related to them. Our product is an attempt at creating this scenario.

The message’s content is a real-time tweet from the Twitter accounts that the user has set the Slackbot to follow. We set our product to centre on tweets concerning COVID-19 in Alberta. However, it can be customized to any application that the user wishes. 

Getting started

The bot was developed in Python leveraging our cloud computing resource — the Rapid Access Cloud. To successfully run our script, you need to have access to Twitter and Slack API tokens. After successfully deploying it in a cloud server with relevant credentials, a user can add the bot to any Slack channel of choice. Once added, the user will start receiving tweets from the Twitter account listed in the default query. 

In our case, we specified @YourAlberta, with COVID-19 as the default query. When a tweet from @YourAlberta matches the keyword COVID-19, that tweet is streamed real-time as a Slack message. A detailed description of how to send queries, as well as access Twitter and Slack API tokens, are provided in the ReadMe section of our Github repo.  

A unique feature of our product was its ability to interact with the Slackbot using a Slack interface, similar to the concept of a chatbot (but not as interactive). As of the date this blog is published, a user who has this product set up can add a Twitter username with/without keywords through Slack. At any point, the user can also find the list of queries currently being tracked through the interface. We’re still working on extending the tool to wider use cases.

One of the powerful features of this bot is that a user can specify as many Twitter accounts, along with keywords, as they want to start tracking (subject to Twitter API’s rate limits). 

The COVID-tweets slackbot in action.

Be specific

We found that the bot works best when it is fed very specific keyword/s. Just specifying a Twitter account results in all the tweets from that user being sent real-time to Slack, and many of those messages can be unrelated to the topic of interest. However, when keywords are specified, the bot fires up only when the tweet matches the specific area of interest. 

This is an initial iteration and there are more than one venues to explore from here. For example, we could look to incorporate posts from other social media, or perhaps do sentiment analysis on the posts. Our team is excited to continue this work while extending to other use cases. 

If you are interested in learning more about this project, feel free to reach out to us at datascience@cybera.ca.

Take note

The bot doesn’t have any control over a tweet’s content. Please exercise caution and add only trusted and verified Twitter accounts. If you would like to replicate the COVID-19 Twitter-Slack integration, we recommend the following Twitter accounts, which provide critical  information regarding COVID-19: 

  1. Alberta Government
  2. Alberta Health Services
  3. Chief Medical Officer of Health

You may also want to consider adding the official Twitter accounts of the city/county you live in. Also, here are some keywords you could consider adding in to the mix:

COVID19, COVID19AB, COVID-19, COVID-19AB, vaccine, vaccination, appointment, 24 hours, cases