Bagel Bot: Reimaging Donut

sanzgiri
sanzgiri
Sep 11 · 7 min read
Image for post
Image for post
Photo by Ryan DaRin on Unsplash

Co-Authored with Sam Lee

Slack is an amazing tool for team collaboration. One of its major strengths is the number of integrations and apps it offers that allow you to connect the messaging service with other tools you use in your daily workflow. And the Slack API makes it very easy to create your own app too! Within Xandr, we have used the Slack API to build our custom version of the Slack app called Donut. If you are interested in learning how you can create your own Slack app, read on!

At Xandr, we have a strong Data Science team and we thoroughly embrace the company’s Teach and Learn policy. Last year, our team started an initiative called SHIELD (Strategic Home for Innovation, Excellence, and Learning in Data Science). The goal is to foster an industry-leading, world-class Data Science organization by promoting research, growth, cultural excellence, mentorship, and personal development. The Shield program is spearheaded by a rotating team of volunteers, these are called the Agents of Shield. 😀

Xandr was formed following AT&T’s acquisition of AppNexus. As a result, our team, like many others in the organization, has members from both legacy AppNexus and AdCo (AT&T). We also have a lot of new hires. Slack’s Donut app provides a way for team members to have one-on-one conversations outside of work and to get to know each other better. As part of the Shield charter to spur collaboration, we were eager to use it. However, our Donut subscription was very limited. We already had a number of teams using the app and our subscription didn’t allow additional teams to use it.

We had used the Slack API before on other projects so we knew we could build an app similar to Donut. While we were pondering this idea, we found ourselves in a global pandemic and suddenly everyone became a remote worker. The need for an app like Donut became even more important to help keep the team cohesive and energized and to foster new connections.
So, we started building our own Donut-like app.

So, we started building our own Donut-like app.

Considering that Xandr’s Headquarters are based in New York where Bagels rule over Donuts and that we have a long-standing office tradition of serving bagels every Wednesday morning, we named the app Bagel Bot. We were able to create the first version of Bagel Bot very quickly and run it manually from a Jupyter notebook. Having written it ourselves, we could tune the pairing algorithm as well as add custom features. It was well-received and, for many folks in the Data Science team, it was the first time they had used an app like this.

Our next step was to build a web interface for our app that would allow us to extend it for use by other teams. We did this using a Python package called Streamlit. Bagel Bot became the first Streamlit app running on our internal Kubernetes cluster.

So how did we go about creating Bagel Bot? These were the steps:

  • Create a Slack Bot User
  • Prototype the functionality using the Slack API in a Jupyter notebook
  • Build a Streamlit App for the UI

Create a Slack Bot User

This involved:

  1. Go to Slack’s app page (you may need to sign in to your intended workspace)
  2. Click Create New App, enter your app name, and select the workspace you’d like it to be available in. This will bring you to a page that looks like this:
Image for post
Image for post

3. Scroll down to the section titled Display Information. Edit your app name, description, icon, background color then click Save Changes.

Image for post
Image for post

4. On the left side of the page, click OAuth & Permissions to designate what kind of access your bot should have.

Image for post
Image for post

5. To enable permission for actions such as getting a list of users in a channel, posting to a channel, and creating DMs with users, you’ll need to add Bot Token Scopes. The ones we added for Bagel Bot as shown below. You can see the full list of scopes for more information.

Image for post
Image for post

6. Request bot access to these scopes from your workspace administrator by clicking Request to Install at the top of this page under the section titled OAuth Tokens & Redirect URLs. When the request is approved, you will get a Slack OAuth Token that has the permissions needed for your bot to function.

Image for post
Image for post

Prototype Bot using Slack API in a Jupyter Notebook

There are several API wrappers for Slack that are written in Python. The official one is SlackClient, and it works with Python 3.6 and above.

This API is incredibly easy to use. In our bot, we used the following:

  • The conversations API - which has methods to list channels (conversations_list) and members within a channel (conversations_members). We use these methods to build a list of users that will participate in the Bagel pairings.
  • The users API - which has a method (users_info) that gives the real name and time zone location for a user. We leverage this, along with information from local directory services, to identify a user’s role and their team. We then use this data to power the pair matching algorithm.
  • The matching algorithm - which uses a distance metric that preferentially pairs users from different time zones, teams, or roles. We also keep a history of all past matches to avoid matching the same users in subsequent pairings.
  • The conversations_open method - to create a new direct messaging channel that a pair can use for their private bagel chats. We have a customized list of ice-breakers that we pick from and we use the chat_postMessage method from the chat API to initiate a conversation with a fresh pair of users.

When a team is ready to use Bagel Bot, we create a new slack channel in which we invite all users from that team who are interested in getting paired by Bagel Bot. Within Data Science, we create fresh pairings every three weeks, which we feel is a good balance. Each pair gets its own private channel for direct messaging. We encourage each pair to post a selfie and a brief description following their Bagel meeting.

The first version of Bagel Bot was manually invoked from a Jupyter notebook. This notebook illustrates the code we used.

Creating a User Interface for the Bot using Streamlit

In order to extend Bagel Bot to other teams and allow them to conduct their own pairings, we decided to add a Web UI to our Jupyter notebook.

Streamlit is an open-source Python library that makes it easy to build custom web applications for machine learning and data science. We are huge fans of Streamlit and have used it on a number of Data Science projects. One of us (Ashutosh) has written a Medium blog post on how you can create Streamlit apps for machine learning and host them from a free AWS instance.

The Streamlit workflow is very simple. You pick a channel from a dropdown and select the Post Matches checkbox if you intend to actually post the matches (i.e., you are not doing a dry run). That’s it! The app shows you the matches it generated and posts the pairings on the team’s slack channel. It also creates the direct messaging channels for the pairs.

Streamlit does not currently have an authentication scheme for their apps. So we created basic password level access to the app to prevent any inadvertent pairings. We deployed our streamlit app to a Kubernetes cluster running on the Xandr NYC datacenter. Internally it is accessible via https://bagel.adnxs.net.

Here is a screenshot of Bagel Bot in action. If you are interested, you can view the source code.

Image for post
Image for post

Our bot has been used to create Bagel pairs in our Data Science team since March ’20. We also used it with the Summer Intern class of 2020, to pair interns with other interns or employees. Seeing the success of Bagel Bot, a few other teams have approached us to use it within their group.

Next steps for us on the Bagel Bot are to automate the pairings based on a configurable cadence for each team, extract and monitor the success rate of pairings (how soon after the pairing did a pair meet, how much & how often did they correspond in their private channel, did they post an update/selfie? etc.) Based on the data gathered, we can implement ways in which Bagel Bot can help increase the success rate of pairings.

Summary

Here are some takeaways from our work:

  • Slack has an easy-to-use API that you can leverage to build powerful applications.
  • Streamlit allows you to quickly create very nice user interfaces.
  • Data Science skills (using APIs, developing algorithms, building dashboards) are a superpower that can be applied to non-traditional areas.

We hope this blog post inspires you to create a Slack app on your own!

Xandr-Tech

Our latest thoughts, challenges, triumphs, try-again’s…

sanzgiri

Written by

sanzgiri

Xandr-Tech

Our latest thoughts, challenges, triumphs, try-again’s, most snarky and profound commit messages. Our proudest achievements, deepest darkest technical debt regrets (just kidding, maybe). All the humbling yet informative things you learn when you try to do things with computers.

sanzgiri

Written by

sanzgiri

Xandr-Tech

Our latest thoughts, challenges, triumphs, try-again’s, most snarky and profound commit messages. Our proudest achievements, deepest darkest technical debt regrets (just kidding, maybe). All the humbling yet informative things you learn when you try to do things with computers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store