Building Slack bots: February 2019 Edition of the Columbus JavaScript Usergroup
By: Alex Finnarn
Tags: Slack, Nodejs, JavaScript

On a kind of dreary and rainy day last week, I noticed the Columbus JavaScript Usergroup was presenting a talk on “Writing simple Slack bots with Node.js”. Meetups, pizza, and beer usually lift my spirits on such days as these so I figured I might as well build a Slack bot to notify everyone of this great remedy to the rainy day blues.

The Columbus JavaScript Usergroup

The Columbus Javascript Usergroup has been around since…well, their Twitter says they joined in May 2011, so that’s pretty old in terms of internet years. I’ve personally only attended two meetups since being back in the Columbus area for about a month, but both meetups have been packed and the group felt pretty vibrant to me.

The topics for meetups are akin to what you’d expect from a JS meetup. Last month, the presenter gave a high-level talk of the ins and outs of using “serverless” services to replace custom backend functionality. Before that talk, I saw mentions of NoSQL, WebAssembly, and “Robots Powered By React Native”. All are topics that spark my interest, and I expect high-quality, interesting topics to be presented on in the future.

Guy Royse is the self-proclaimed “czar of the group” who helps to line up speakers for the meetup. Guy jestfully called himself the czar and graciously thanked the speaker and the host, Pillar, for providing the pizza, beer, and fancy-schmancy draft cold brew for attendees to gobble down. Each meetup starts with designated time for grabbing some pizza and drinks while networking so you’ll never have to build your Slack bots on an empty stomach.

If you read this before attending one of their meetups, then I’ll let you know one important detail that always has a few people jetting out of the venue to correct. You’ll need to park in the back of the complex and not out front unless you want your car to get towed. In general, it’s always best to verify the parking details of any meetup you go to that involves private parking, and in this case, there is always more than enough room out back to park for free without fear of towing…just make sure you move your car to the back. You’ve been warned 🕵

Just like any meetup, they are on the lookout for speakers at future events and you should contact the czar to find out more.

The Presenter: Curtis Autery

The session was kicked off by Curtis Autery who works at Beam Dental. He is a self-avowed mumbler, just like me, but you’ll be happy to know that the JS group has a pretty good AV system complete with a mumbler-approved microphone.

Curtis has many years of experience developing and one area where this became apparent was his great use of presentational resources to allow attendees to follow along and peruse later. You can view the sample scripts and slides that Curtis used that night below.

Another area where Curtis’ experience showed was in his use of telnet to navigate the Slack API responses in the terminal. I didn’t have the telnet utility installed on my machine so it was a joy for me to look at how telnet is able to “provide a bidirectional interactive text-oriented communication facility” and read more about it via the Wikipedia article.

Setting up A Workspace

We started out the interactive presentation by setting up a Slack Workspace. I’ve only interacted with Slack bots at my work via integrations with services like Travis CI or as a way to impart timely GIFs into conversations, but I’ve always wondered how I could utilize a Slack bot in other meaningful ways.

You’ll want to set up a separate workspace to experiment in so that you don’t have to request access in any of your current, professional Slack workspaces. Even if you think you already have access or your work is cool with it, there’s no telling that things will remain cool once you want elevated permissions or to integrate with a third-party service that doesn’t look too trustworthy…or you give out an API key or something publically accessible code…

Slack makes it so easy to create a workspace, that you don’t need to worry about sneaking around an existing Slack workspace. You’ll find yourself starting workspaces full of typos with questionable channels in no time.

My #gut-loss channel in my Slack workspace full of typos.

Types Of Bots

Now that you have a workspace to play around with, you might wonder what types of bots you can create to take full advantage of Slack. I personally have several Slacks open at all times during the day so I have plenty of opportunities to think of ways I can use Slack to avoid incessantly checking other apps during the day. I’m in Slack all day anyway so I might as well keep my distractions in there as well.

Curtis presented on ways you can use Slack bots including showing “basic queries for server info (users, channels), using the real-time messaging API with websockets, and receiving interactive events over Slack-to-server callbacks.” He tied that all together at the end with a live demo of a “choose your own adventure” app utilizing all the examples he described to us.

My Bot

I was so caught up following along with the presentation and trying things out that I don’t have any good photos, videos, or logs of the examples Curtis showed, so all I can do is post a link to the example code he mentioned for that stuff.

After the meetup, I was inspired enough to create a simple Slack bot of my own. I decided that my bot would nag me every hour to move around and tell me specifically how to move around based on the current weather. I tend to check the weather as the day goes along and before I head outside to take a walk so it made sense to create a bot that periodically did that for me.

I’m still going to use the Slack workspace I created above, but I wasn’t sure what method I should use to interact with posting to the Slack channel.

Types of Slack Features