Interview w/ Gaurav: coding a Slack integration that lets users schedule CodeBuddies hangouts directly from Slack

CodeBuddies.org
CodeBuddies
Published in
6 min readSep 24, 2018

--

Hi Gaurav! Can you introduce yourself quickly?

Hi! My name is Gaurav Chikhale, a software engineer with a passion for web technologies. I’ve been working as a full-stack developer since 2013 and am currently spending a good amount of time contributing to open source and side projects.

What did you build?

I created a Slack bot (pull request) that lets members of CodeBuddies schedule hangouts directly from the Slack app.

That’s awesome! How does the feature work?

This bot is still in its infancy; it’s not very smart at the moment. It’s basically a CLI that works inside Slack.

To schedule a hangout, a user can simply mention the bot (@cb_jarvis) and pass some commands like:

“Hey @cb_jarvis! create hangout, tomorrow at 5pm, learn haskell”

or to list upcoming hangouts:

“@cb_jarvis list hangouts please”

What prompted you to submit a pull request for this idea?

Just for fun! It was an experiment; I got the idea when I was trying to schedule a hangout from a mobile device. It was not a very good experience. You had to open the browser, go to CodeBuddies, and sign in using Slack even when you were already signed into the Slack mobile app. There were a number of additional steps which can be annoying to follow. So I thought it would be much easier to open up Slack and ping a bot.

Did you have any experience working with the Slack API before?

Nope, this was the first time.

Wow. What did you research?

That’s a very good question. I think research is the most important part of any development.

There were mainly three areas I did some research, specifically:

1. How to use the Slack API, and how to integrate it with Meteor app

2. How to handle the timezone problem

3. The message parsing/NLP part

For example, with the timezone problem — if a user creates a hangout from a web app, it is not difficult to get the user’s timezone, since the web app runs inside the user’s browser where we do have control of writing the code.

But if a hangout is getting created from Slack, how do we access the user’s current timezone? We don’t have access to the user’s browser or machine. Thankfully, after digging into Slack’s documentation I found they store the timezone inside the user’s profile, which can be accessed via their web API.

Cool! Let’s talk about how you built out the integration.

How did you start?

Well, first I jumped straight into researching the Slack API. I discovered that Slack was working on a new kind of API called Workspace Apps. They call it the next generation of Slack apps, with a simplified tokens/permissions model. So I spent some time reading the docs, and playing around with those new APIs. And I figured out how to use the Event Subscriptions API to listen for new messages on Slack channels.

How did you decide which features you were going to work on when you got started?

I decided to create the very simple and basic version of a bot that could create the hangout. No extra features or complexities. For example, in the initial version I kept the message formatting very simple: using comma-separated values. Whenever a user pinged a message to @cb_jarvis, we would parse the message by creating segments from commas. The first segment represented the command and the other segments represented the other parameters.

How did you decide on which packages to use?

Here are the questions I ask when I choose any package:

  1. Do I really need any package to solve the problem, or can I do it natively without any hassle?
  2. If it’s for the front end, what is the size of the package? I use Bundle Phobia to check the package size.
  3. What extra feature(s) does this package come with that I don’t need? Is it modular, or can I just pick what I need?
  4. How is the documentation?
  5. Finally, I look at the popularity/Github stars etc.

For date parsing, I found this cool natural language date parser in javascript called Chrono: https://github.com/wanasit/chrono. There were no other packages and it was exactly what I needed so I picked it without a second thought.

How did you figure out which Slack permissions were necessary?

Slack’s documentation was good enough that I don’t have any difficulties finding what permissions we needed.

Okay, let’s walk through the code! :D

COMING SOON: A Code Walkthrough Video

What was the most time-consuming part of building this feature?

I think research and planning part were the most time consuming. You have to think a lot about the approach and the architecture. I wasn’t sure what tech to choose or where to start. The best way to tackle is just to take one step at a time and then move forward patiently. Even though initially the Slack documentation was a bit difficult to understand, I found that when you spend enough time reading and working on it, it gets easier. And at the end when you know what to use and how to implement it, it’s a piece of cake to write that code. (But also be prepared for unexpected errors. :P)

How did you navigate around the CodeBuddies codebase?

I was quite familiar with Meteor, like meteor methods, the publication/subscription model, and the folder structures etc. So I had no difficulties navigating around codebase. And the bot logic itself was independent of the framework; it just needed an HTTP request handler to accept the incoming messages from Slack.

However, there was a situation where I had to decide whether I should refactor the existing code that created the hangout and make it reusable, or just write the newer one. Writing the new logic was an easy and faster solution and the chances of breaking the existing logic were low as well, BUT it was not the correct way to do it. It was redundant of course and maintaining the two different logics that perform almost the same operation is not trouble-free. Especially if you are working on an open source project. So I ended up adding some refactoring there.

In the course of testing out the feature, we found a confusing bug! :D The app would suddenly error and think that the user didn’t input a date, despite working perfectly before. How did you eventually figure out the bug fix?

Confusing bug

I think half of the bug is already fixed when you can understand the cause and reproduce it precisely. As it happen with most of developers where “Code works locally but not on production,” I was no exception. On production when I was trying to create a hangout with the bot, it kept saying “Date is un recognized”, even for the correct date format that was working perfectly earlier. After around 40+ attempts, I finally figured out how to precisely reproduce the bug on local machine. And adding more console.logs helped to figured the cause of the bug.

It was a ‘pure function’ issue that supposed to not affect anything outside the scope. But since this function was working with the object and mutating its state indirectly by reference instead a proper new copy, it was causing undesired side effects.

Thank you so much for sharing, Gaurav!

My pleasure!

--

--

CodeBuddies.org
CodeBuddies

A community of independent code learners who enjoy sharing knowledge and helping each other learn faster. Open-sourced and 100% volunteer-driven.