A Beginner’s Journey Building a Slackbot

Hi my name is Swetha — I’m a rising junior in college and up until a year ago, I didn’t understand what programming really meant.

I thought it was rocket science. I’ve been coding for a year now and I still have this constant voice in the back of my head telling me to give up. “You’re not fast enough. You’re not good enough. You can’t code”.

And yet, I persisted.

I had been raving about how cool I thought Slack’s platform was to a friend a couple of weeks ago when we were trying to brainstorm project ideas for me to take on. I knew that I wanted to get my fingers dirty and make something, but I just didn’t know what. This was when she suggested I build a SlackBot that took a sentence like “Remind me to eat with ______ tomorrow” and created a reminder on your Google calendar.

I know in today’s world, building a SlackBot isn’t rare but for whatever it’s worth, I’m writing about this because a) I think it’s important to track progress and b) maybe someone else who’s just starting out in this field like me can make use of my journey.

So to start, a lot of things went through my mind. The most prevalent being: how the hell do I do this? First of all, I was building this on Slack, so I would definitely need to utilize the Slack API (https://api.slack.com/web). Second, I wanted this hooked into the user’s Google calendar, so I would also need to use the Google Calendar API (https://developers.google.com/google-apps/calendar/). I’d messed around with Google Maps API before, so I had a little comfort in knowing that Google didn’t leave you drowning with their APIs.

Then I started thinking about the flow of what I’d be doing. The user would be typing something into the SlackBot which would then somehow know to put this reminder onto the calendar? No, this was too complicated…there had to be middle ground. I had to somehow parse through the sentence the user typed into the SlackBot and isolate the subject of the reminder and the date/time.

After some research, I discovered Google API.AI (https://api.ai/), Google’s platform to test conversations using natural language processing and other human-computer interaction tools.

Now this could be because I’m a linguistics and computer science major but Google API.AI is pretty much the coolest thing I’ve ever played around with. Even if you don’t end up building a bot, I suggest you mess around with API.AI (it’s a lot of fun).

Anyway, I’d now figured out my flow. The sentence typed into the SlackBot would be sent to the API.AI which would then send the parsed JSON object to the calendar. But wait — the calendar API kept saying something about authentication, which made me realize, I needed a server to do all my authentication in and definitely needed routes to go back and forth from my different API destinations. (Now this is probably obvious to experienced programmers, but figuring out OAuth and slash commands took me a while so if you’re not that experienced with backend, you might struggle a bit through it but it’ll eventually make sense). I needed to authenticate their Google tokens and only then let the user continue chatting with the bot to schedule tasks.

Next, I knew I needed a database to store my user id and such, so I decided to use Mongoose and store my models in mlab. To capture the subject and date from the API.AI JSON object, I created additional keys in my user model so that I could access them within different files (everything non server related was in my bot.js file while the authentication/express stuff happened in my oauth.js file).

Once I had figured out all of that, it was just a matter of figuring out the API specifications, making sure all the files were properly connected, and getting my post/get requests working.

Now this is a very high level explanation of what I had to go through to get the bot working but once this was clear to me, everything else became much easier. The hardest part for me was understanding the flow, and figuring out how to save the user information in the database. OAuth is always something that scares me but after this part was completed, the rest was very doable.

All in all, it took me four days to complete this. I had an enormous amount of help from friends and public forums (shoutout to StackOverflow as usual) but I ended up with a working SlackBot. My bot was able to have basic conversations (using the smalltalk agent within API.AI) and set the desired reminders on my calendar. One thing I wish I had done was deploy it onto Heroku or something public but that would have taken longer as I am yet to learn how to use it. However, that’s definitely my new task at hand (Slackbot, remind me to learn how to use Heroku tonight). For now, this runs on localhost and it’ll have to do.

Again, I’m not sure how easy this was supposed to be, but as I keep getting told, coding is a single player game and this was my first time actually playing. I had been sitting on the bench for far too long.

There were moments where I was emotionally destroyed during this (you have no idea how many times I doubted my skills). Just reading through all the APIs made me extremely overwhelmed and dubious. However, I’m so glad I had pushed myself to build this because now I’m more confident in what I can do and make. I’ve learned so much and now am motivated to try new things that may have scared me in the past.

If you’re like me and keep pushing things off because of how daunting they may seem, just do them. Even if you don’t get them to work or finish, you’ll still take something tremendous away from the experience that will help you in the future. The most important thing I’ve realized in this journey is that the secret to coding is just starting.

Like what you read? Give Swetha a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.