How to start developing a slack bot with interactive buttons

In summer 2016 slack introduced API feature for making bots with interactive messages. I think it is not necessary to explain why it will help to create a more user-friendly bots.

Just look at examples:

text commands flow
buttons flow

Your bots won’t have to parse human language as much if you let users make direct choices. The result is a new way of building apps for Slack, one that relies less on complex multi-step interactions, while letting you increase user engagement — Slack Developer Blog post.

Now we’re gonna see how to develop a bot with this cool new feature.

API for message buttons well documented and looks easy to use. But the problem is that it is required to use http connection in order to send responds to our bot.

https://api.slack.com/docs/message-buttons

Though it is really hard to set up this in local environment. Fortunately, there are a few solutions, for example the localtunnel. During development this tool is useful for temporarily exposing a compatible webhook url.

Localtunnel allows you to easily share a web service on your local development machine without messing with DNS and firewall settings.

Run your bot for example on 9292 port and then type:

lt --port 9292

And get a link like this https://botdomain.localtunnel.me/

Which you can put into section “Interactive Messages” on your slack app settings. And start developing in local environment.

Now everything seems to be fine, but turns out the localtunnel doesn’t really work well and sometimes crashes. To resolve it I made a gem localtunnel-restarter which keeps localtunnel working.

Usage:

localtunnel-restarter --port 9292 —-subdomain bot9292

If something happens with proxy server it will be automatically restarted with subdomain and port from options.

--

--

Software Engineer. Interested in Microservices, Distributed Systems and Cloud Services.

Love podcasts or audiobooks? Learn on the go with our new app.

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
Kirill Shevchenko

Kirill Shevchenko

244 Followers

Software Engineer. Interested in Microservices, Distributed Systems and Cloud Services.