Bots for Business
Guide to Messaging Apps Chatbot: Slack bots
Get a head start on building your chatbot app for Slack. This guide explores the unique features of Slack bots, reviews use cases, and covers framework integrations.
June 4, 2019
The Slack community is all in with chatbots. Since the app entered the world in 2013, developers have taken advantage of the Slack API to build chatbots of various kinds. Most Slack bots perform a function relating to the primary reasons people use the app—team collaboration and productivity. Still, you might be surprised at the variety of ways your bot can interact with Slack users.
Let’s dive deep into the world of Slack bots. We’ll look at what it takes to create a Slack bot and how to integrate a bot with Slack. In addition, we’ll consider some representative use cases that demonstrate what your bot can achieve on the platform.
Why build a Slack bot?
There are lots of reasons to build a bot for Slack. Here are a few of the most compelling ones:
- Your team is trying to achieve something specific using Slack, and you want to make it easy for them to do so.
- You’ve identified a particular service that could benefit the Slack community, but it isn’t available yet.
- You have already built a productivity or collaboration tool for another platform, and you think the Slack community would find it valuable.
The main point is that Slack isn’t just another messaging application or social network—it’s a tool that businesses, organizations, and teams use to get work done. As we’ll soon see, most bots that gain traction on the platform address an internal business problem or take advantage of an external business opportunity.
Simply put, most Slack bots help people do the things they were already going to do, only faster.
How to make a Slack bot
To build a Slack bot, start by reviewing documentation for the Slack API. The first thing to understand is that the Slack API allows you to build apps for Slack, not just bots. Slack apps come in various forms, and chatbots are among them.
In other words, you’re really building a Slack app that happens to be a chatbot.
Create a Slack App
The documentation explains how to do this. After following the instructions, you have a Slack app that resides in a single workspace. Over the long run, you can keep your app-turned-bot on a single Slack workspace, allow users to communicate with it on other workspaces, or even submit it to the Slack app directory. It’s your call.
Review how bots work in Slack
In the Slack API documentation, follow the section on building bots. It shows you how to:
- Create a bot user. In Slack, bots are actually considered users. They’re not just peripheral entities that human users seek out; rather, they exist as regular participants in a given channel. After creating your Slack app, you set up your bot as a user and configure its settings, including user name and display name.
- Set up the Events API. Every Slack bot lives in a workspace. The Events API allows your bot to respond to messages and other activities that happen in a workspace.
- Install your bot. You have to install the app (that is, your bot) to the workspace where it will interact with users.
- Handle events. This includes receiving and responding to messages in the manner you intend and that users expect.
As you follow these steps, be sure to review some of the unique features of Slack apps. All of these are described in the documentation.
Slash commands, for example, are Slack-specific user requests that tell your app to do something. In response to a given slash command, your app will reach for some data on the backend, package it into a message, and reply to the user accordingly. Slash commands are a big part of the overall Slack experience, so your bot will likely need to know how to handle them.
Choose a bot framework
Although the Slack API documentation will give you a good idea of how Slack bots operate, it includes this important note: “The real magic of a bot comes when it’s connected with external services, providing a seamless conversational interface for them within Slack.”
In other words, you can—and perhaps should—build your bot with a dedicated bot-building framework. Slack specifically calls out Botkit here, but there are numerous bot frameworks that come with powerful natural language understanding (NLU) capabilities, machine learning features, and integration with select enterprise services. If you need help getting started, check out our guide to bot-building frameworks.
Using a framework, you’ll also have a bot that you can deploy anywhere—not just on Slack. Many bot creators build bots for multiple platforms, such as Slack and Facebook Messenger, and then deploy those same bots on dedicated domains (like .BOT). That way, users can find (and keep using) your bot, even after their team outgrows Slack or moves communication to another platform.
Not sure what kind of domain is best for your bot or is your preferred domain name already taken? Consider a .BOT domain name, a bot-centric option that’s perfectly suited for this purpose.
How to integrate your bot with Slack
Assume you’re planning to build your bot on a dedicated framework, let’s consider the process of integrating your bot with Slack. Since the Slack API documentation references the Botkit, here’s a high-level overview of how the integration process works with this framework. Keep in mind that many of the major frameworks, such as Amazon Lex, Dialogflow, and the Microsoft Bot Framework, offer similar integration options for your Slack bot.
- Configure a bot in Botkit and Slack at the same time. Botkit documentation covers how this works, but you’re essentially making your Botkit bot interface with the Slack Events API.
- Configure Open Authorization (OAuth). This authentication system gives your bot permission to interact with users.
- Add a bot user, buttons, dialogs, and other components. Slack calls these interactive components, and you can send the interactions to a specified URL.
- Enable event subscriptions. Doing so allows your bot to receive messages.
- Add your bot. Log in to Slack, choose a team, and follow the rest of the prompts.
- Review Botkit technical procedures. These include creating a Botkit controller, reviewing the different types of events, interactions, and webhooks, managing Slash commands, and more. The technical procedures can be found in the Botkit documentation.
Slack chatbot examples
Most bots in the Slack app directory perform work-related functions. You can find bot-driven developer tools, office administration bots, chatbots that help with security and compliance, and others. Let’s look at a few things that Slackbots can help you achieve.
Human resources chatbots
Among messaging platforms, Slack is unique in providing HR with tools for managing otherwise tedious tasks—using bots, no less! Just consider the process of requesting time off. Normally, an employee might have to send an email or log in to a separate backend system. Then they’d have to wait for an HR manager to approve the request.
With a tool like AttendanceBot, that employee (who’s already logged in to Slack) sends the bot a message, like, Next week, I need to take Wed through Fri off. The bot then notifies an HR manager, who can approve or deny the request with a single click.
Getting things done is arguably the primary purpose of Slack. So it makes sense that there are lots of productivity bots in the app directory.
Take Geekbot, which broadcasts status updates among team members after tracking asynchronous meetings. This could be useful if, for example, you’re waiting on a colleague to finalize a task. Geekbot notifies you where they are in their review process so that you don’t have to waste your time checking in.
Astrobot is another productivity tool that’s so popular, Slack acquired the company that built it. Astrobot lets you write and respond to emails in Slack using Slack user names. You can also use it to identify important messages and reduce inbox clutter.
Bots like Teampay help you manage purchases made by people on your team. You’re able to see costs, vendors, and purchasers. If you need to get permission for certain types of expenses, Teampay lets you do that, too.
Rydoo is another Slack bot that streamlines the management of travel expenses. It allows employees and HR professionals to upload receipt images, send mileage information, and (on the HR side) approve and reject expenses.
Getting started with Slack bots
Start by reviewing Slack’s documentation for building Slack apps. Then read about Incoming Webhooks and Slash Commands. Understanding these concepts can help you envision how your bot might behave on the platform.
After that, consult your chosen framework’s documentation about Slack integration and review Slack’s bot-building tutorial. There are few limitations with bot apps in Slack. If you’re planning to build a bot that helps teams do better work (and get it done faster), you’ll almost certainly have success.