Botkit is better with Slack’s Events API

Eric Soelzer
Slack Platform Blog
5 min readJan 3, 2017

We are very excited to announce the release of Botkit 0.4.6 features support for Slack’s new and improved Events API. This new functionality allows developers to write bots that respond only to certain activities performed in Slack. Most importantly, it makes Slack apps easier than ever to install!

At Howdy, we’ve been hosting thousands of difficult to manage connections for our popular Slack app since our launch in 2015. Since the nature of an open websocket provides a torrential amount of data, running a large number of bots for Slack teams makes for a very memory-intensive and complicated connection to manage at scale — that’s where the nifty Events API comes in handy!

With this latest release, Botkit developers can limit the number and type of messages they receive — thus avoiding complexity and maximizing scalability! The Events API allows developers to create Slack apps more like traditional web apps are made, without the need to manage multiple real-time connections to users.

Botmakers using Botkit can continue using the Real Time Messaging API to create powerful bots for Slack, but anyone just starting down the path of bot development will find the Events API a great place to start.

How to create a Slack app using Botkit and Glitch

We’ve made it easy for you to start making a powerful Slack app using Botkit and Glitch, a web-based code editor that features instant deployments — so you can edit and host your bot’s code to test in one place!

1.) Create your new Slack app

To get started click Create New App at https://api.slack.com/apps. Don’t worry about your app submission to the Slack App Directory right now — you can always decide to submit it later.

After you’ve chosen a name and which team your app will live on, note the Client ID and Client Secret from the App Credentials view. You will need these to get your app up and running.

Once you’ve collected those keys, set up your default username in the Bot Users section and save your changes to continue:

Set your app’s default username in Bot Users

2.) Remix the Botkit Slack App Starter Kit

Glitch is a fantastic tool for experimenting with bots without worrying about complex local development configurations. We’ve made it simple by creating a Slack App Starter Kit you can remix here:

https://glitch.com/edit/#!/botkit-slack

Click “Remix This” to make it your own!

Click the name of the Glitch project and find Remix This. This will copy the Starter Kit into a new project that you can make your own.

Note: The Slack Starter Kit is also available on GitHub if you want to host it yourself: https://github.com/howdyai/botkit-starter-slack.

3.) Add your keys to Glitch and run

Glitch safely stores your keys in an .env folder. Paste your clientId and clientSecret values in here. Don’t worry — if anyone remixes your project, your keys won’t be shared.

Once you’ve included your app credentials, click Show Live to get your bot server running. This will open Glitch’s instant hosting and deployment magic. You’ll need to have this server running for Slack to confirm your app’s endpoints and finish your configuration.

4.) Get your app talking to Slack

You’re almost there! Now you just need to get your environment variables set so your app can communicate with Slack and vice versa.

Configure permissions

Return to your Slack app settings and navigate to OAuth & Permissions. There, paste in your Redirect URL, which is your own, remixed Glitch URL plus “/oauth”, like this example:

https://botkit-slack.glitch.me/oauth

Copy that URL from your browser window and paste into your settings.

Save your changes and confirm your Redirect URL to continue.

Add a Bot User

Create a username and enable the Online notifier in the Bot Users section.

Enable Interactive Messages

You’ll want to enable Interactive Messages for your app, so go ahead and do that too. That will be your Glitch URL, followed by “/slack/receive”:

https://botkit-slack.glitch.me/slack/receive

Type that URL into the Request URL field to enable Interactive Messages.

Enable and subscribe to Slack events

Now you can head over to Event Subscriptions and flip that toggle to enable Slack events! Here, you’ll paste in the same Request URL you used for Interactive Messages.

Then, subscribe to the events your apps requires below. For the purposes of this example, we’re going to subscribe to some Bot Events that allows this Botkit bot to hear messages wherever they’re posted.

Subscribe to events in Slack

Now comes the fun part…

Add your new app by clicking the “Add to Slack” button and select a team. If you’ve configured everything correctly, you’ll see a screen like this one:

Authorize your bot and it will magically begin talking to you in Slack!

Hello, world!

Congratulations! You just brought a brand new Slack app to life using the Events API, Botkit and Glitch. Now your adventure as a Slack developer officially begins with Botkit! 🎉

All of Botkit’s powerful functionality works with the Slack API automatically! Check out the Slack Events API documentation and the Botkit documentation to get started.

Edit scripts and more with Botkit Studio

You may have noticed a studio_token field in the environment variables. Based on our experience building Howdy and Botkit, we’ve built Botkit Studio, a powerful web-based tool for creating and managing bots. We can’t wait to release it to the public soon!

We’re utilizing Slack’s Events API to enable radical new script editing and bot management capabilities for Botkit developers. Please let us know if you’re interested in using it in your next bot project.

Join the Slack developer community

Now that you have your very own app up and running, we encourage you to join thousands of developers sharing their experiences at https://dev4slack.slack.com. It’s a tremendous, friendly resource.

In there, you’l find active #botkit and #slack-api channels where you can talk with Botkit developers and members of the Slack API team. You can even search the archives to see if discussions have been had around your questions!

Thanks to Jon Church and the entire Botkit community for contributing!

--

--

Eric Soelzer
Slack Platform Blog

Musician/technologist in Austin, TX. Co-founder, Gratify.