A Simple Sloppy Slack Slash-command Show-how (with Meetup API)

Jeff Madsen
Aug 29, 2017 · 5 min read
Image for post
Image for post
(We know “Show-how” isn’t a real word. Alliterate all the things!)

Checking out BotList lately got me curious about that world, so yesterday I decided to sit down and create what is probably the simplest form of bot — a Slack slash-command of my own. For those of you unfamiliar, in Slack you have the ability to create a full-fledged Bot that you can interact with (or that can serve up push notifications), or just a simple command like /whenisthenextmeetup that we’re going to build.

This whole “show-me” should take you about 10 minutes if you want to follow along. There’s a bit of very sloppy php code at the end you can use (although you’ll probably want to clean it up quite a bit if you leave it in production). You’re going to want the following:

  • A Slack account with at least one organization that won’t mind you doing this (ask, or better — ask if you can make them something)
  • A Meetup account
  • A web host account where you can drop a single .php file

I built this for HNKansai , a Hacker News group based in the Kobe/Osaka/Kyoto triangle (join us!). We recently started using Meetup for our monthly get-together and co-host Sacha Greif suggested this idea might be helpful.

Your first step is to actually find the link on the Slack website to get started. Don’t laugh — I’m not the brightest bulb in the chandelier, but it took me round and round clicking of the sort typically associated with Google APIs to figure out a generic starting point I could share. The key is to know which of your organizations you want to make this on before you get started:

https://[yourTeam].slack.com/apps/build/custom-integration

So for me, for example, it was https://hnkansai.slack.com/apps/build/custom-integration (which won’t work for you unless you are a member of HNKansai - put your own team in). After that it is all downhill.

Image for post
Image for post
We’ll use Slash Commands, obviously

We’ll use Slash Commands, which takes us to a starting point asking for the command we want to use. Type ‘/whenisthenextmeetup’ and click the Add Slash Command Integration (don’t worry about how long it is — we’ll be adding autocomplete in the next step).

You’ll be taken to new page with a lot of useful information at the top that you really don’t need to know about right now. About half-way down the page you will see Integration Settings:

Image for post
Image for post
URL will not yet be filled in — that’s a coming step

The Command is self-explanatory; the URL is where we are going to put the link on our hosted account where our actual script is that does something. In our case, that “something” is going to be to call the Meetup API with a usergroup slug and have it return to us the next event information, which we will parse and pass back to Slack.

First, while we’re here, let’s give it the rest of the information we want to show in slack. Customize Name is your bot name, and the icon will be its avatar. The autocomplete part is important — it will not only save typing but let users see usage instructions. Mine looks like this in production:

Image for post
Image for post
Autocomplete for our command

Save that when you’re done and let’s go grab our API key from Meetup.

When you log into Meetup you’ll find the usual dashboard at https://www.meetup.com/meetup_api/; you can find your API key at the top. That’s all we really need from here, but the endpoint we’ll be working with is https://www.meetup.com/meetup_api/docs/:urlname/events/#list which you’ll find handy if you want to modify our results later.

Now we need some code for our api calls. If you’re an experienced programmer, this is the point where you ask yourself, “PHP…Meetup…gotta be something out there, right?” and run to Mr. Google, who tells you about this nice little single file library: https://github.com/FokkeZB/Meetup Not only did I not bother to use composer to pull it in (just grabbed the “raw” version), I even stole part of his example code and created my own endpoint here:

I told you it was simple & sloppy. (It’s also in production — how’s your weekend project?) About half of the code is just letting people use shortcuts for some of the other local groups many of us belong to. The Meetup actually requires the group’s slug (ex: ‘Osaka-Web-Designers-and-Developers-Meetup’) which would be a bit tiresome to type out, so I made a shortlist to allow 3-letter codes instead, with a default.

The meeting start time is stored in milliseconds, so be sure to convert. It is also GMT, but since we are all in Japan I did it (say it together!) the Simple, Sloppy way. It looks like this in Slack:

Image for post
Image for post
This is three separate requests, using “ccc”, default and “owd” as arguments

That’s really all there is. Very simple code which can be written in any web language you want and a few dashboard settings. Feel free to use this “as is” or anyway you care to. Next time I’ll get into some bots that are a little more interactive than this. Enjoy!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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