What is a Slack Chatbot and how to create it?

By Joren Wouters Updated on

Want to save time by automatically replying to messages in Slack?

Then, you should create a Slack chatbot, which will take care of that!

In this tutorial, I will explain:

  • What Slack bots are
  • How Slack chatbots work
  • And how you can create a Slack chatbot yourself, without writing a single line of code

Let’s dive in!

 

What are Slack bots?

Slack chatbot is an automated conversation system embedded into Slack. It can send welcome messages to Slack users who visit the bot and automatically reply to specific words in a Slack conversation or channels.

Slack chatbots work 24/7 and can have multiple conversations at once.

Besides, you can add Slack bots to channels in Slack where they can talk in group conversations.

Here is an example of a Slack chatbot that automatically tells jokes:

slack-chatbot-example
Source: Slack

 

How do Slack bots work?

Slack chatbots are often created based on a conversational flow.

And most flows are built using three simple elements:

  1. Trigger: tells the chatbot when to start a conversation
  2. Action: Tells the chatbot what to do
  3. Condition: Performs checks on the user based on if this, then that

how-slack-chatbots-work

For example, when a visitor sends a message to your Slack chatbot, the chatbot will first check if the user is a first-time visitor of the chatbot or a returning visitor.

If the visitor is a first-time visitor, it will send the “first-time visitor” message and ask a question. If the visitor is a returning visitor, it will send the “Returning visitor” message and notify an agent.

 

How to make a chatbot on Slack?

Slack doesn’t have a platform that allows you to create bots directly on their platform. Therefore, we need to use a third-party chatbot platform to create our Slack bot.

You can use different chatbot platforms for creating a Slack bot such as Flow XO, Engati and Xenioo.

Now, let’s create a Slack chatbot in a few simple steps, without using a single line of code:

 

1. Sign up for a free Flow XO account for your Slack bot

The first step is to create a free Flow XO account by clicking the button below:

Create free Flow XO account

 

2. Create a flow and reply to specific words

Once you have signed up for your account, you need to go Flows and click on + New in the top-right corner:

flowxo-new-flow

Here, we can determine if we want to go with a pre-built template or with a Blank Flow. We will select the Blank flow:

flowxo-blank-flow

Then, we need to determine what triggers this flow, which will be a New message:

flowxo-new-message-trigger

We will set it up for all the bots connected to our Flow XO account (we will set this up later):

flowxo-connect-to-all-bots

And then we can determine the word we want to reply to. As an example, we want to reply when somebody asks for the wifi password.

So, we will fill in the following words and phrases:

flowxo-new-message-phrases

And we will set up so that the chatbot will reply in a private conversation and in public Slack channels:

flowxo-message-types

Now your flow will be saved and will look something like this:

flowxo-new-flow-example

If you click on the name of the flow (“Untitled flow”), you can also edit give it a better name so you know what the flow is about:

flowxo-edit-flow-name

 

3. Determine the auto-reply for Slack messages

Now that we created our flow, we need to determine the automatic reply we want to send if someone asks for the wifi password.

You can create this reply by clicking on the + icon in the flow builder:

flowxo-add-action

Choose for Send message:

flowxo-send-message-action

And we can set a simple auto-reply for this message and click on Save:

flowxo-send-message-contents

Lastly, you need to activate the flow in the upper-right corner by clicking on the Off toggle:

flowxo-enable-flow

That’s it! Now, every time a user asks for the wifi password, your chatbot will automatically reply to it.

You can even test this out by clicking on the message bubble in the bottom right and talk to your chatbot:

flowxo-test-console

 

Connect your bot to Slack

The last thing we need to do is connect our bot to our Slack workspace.

And this is also the most trickiest part of the tutorial. But if you just follow every step that I take, you can connect your Flow XO Bot to Slack.

We can do this in a few simple steps:

  1. Create a bot in Flow XO and connect it to a Slack app
  2. Add a Redirect URL and add the right scopes
  3. Add Event Subscriptions to your Slack bot
  4. Add Interactivity to your Slack app
  5. Enable Slash Commands and your Slack chatbot to your workspace

 

1. Create a Bot in Flow XO and connect it to a Slack App

The first step is to go to Bots in Flow XO and click on New in the top-right corner:

flowxo-new-bot

Then, select Slack as your channel:

flowxo-choose-slack-platform

And you can give your Bot a name, such as “Chatimize’s Slack Chatbot”:

flowxo-create-slack-chatbot

Before we can actually create the bot, we first need to add some information to Slack and from Slack to Flow XO.

So in order to do this, we need to create an app inside Slack.

Therefore, you need to go to https://api.slack.com/apps?new_app=1 and click on Create an App:

slack-create-app

Choose to create an app from scratch:

slack-app-from-scratch

And fill in the name of your app (can be the same name as in Flow XO) and pick the right Slack workspace:

slack-create-app-for-workspace

Now your Slack app is created, which we are going to use for our Slack chatbot.

Once you have created your Slack app, you automatically go to the Basic information tab of your app.

If you scroll down, you will find the section App credentials and you need to copy your Client ID and Client Secret to Flow XO:

slack-bot-app-credentials

 

2. Add a Redirect URL and add the right scopes

Next, we need to go to OAuth & Permissions and add a Redirect URL to our Slack App.

You can get this URL from Flow XO. So if we go back to Flow XO, you will see that we have a Slack App Redirect URI, which we need to copy and paste into Slack:

slack-chatbot-redirect-url

Once you have added the Redirect URL, we need to add Bot Token and User Token scopes to our Slack app. We need this to be able to actually receive and send messages from Flow XO to Slack.

So in Slack, you can just scroll down on the same page and add the following Bot Token Scopes:

  • app_mentions:read
  • channels:history
  • channels:join
  • chat:write
  • chat:write.public
  • commands
  • groups:history
  • im:history
  • incoming-webhook
  • mpim:history
  • users:read
  • users:write

And add the following User Token Scope:

  • channels:history

So it eventually looks like this:

slack-app-bot-user-token-scopes

 

3. Add Event Subscriptions to your Slack bot

Following, we need to add Event Subscriptions to our Slack bot.

In Slack, go to Event Subscriptions, set it to On in the top-right corner and add the following Bot User Events (under “Subscribe to bot events”):

  • message.channels
  • message.groups
  • message.im
  • message.mpim

Then, you also need to add the “Slack App Interactive Messages Action URL” from Flow XO to your Slack app:

slack-chatbot-add-event-subscription

 

4. Add Interactivity to your Slack app

Next, we need to add Interactivity to our Slack app.

In Slack, go to Interactivity & Shortcuts, enable the Interactivity and paste the “Slack App Interactive Messages Action URL” from Flow XO inside the Request URL and click on Save changes:

slack-bot-add-interactivity

 

5. Enable Slash Commands and your Slack chatbot to your workspace

Lastly, we need to enable slash commands and our slack chatbot to our Slack workspace.

First, go to your Slack app, click on App home and enable Allow users to send Slash commands and messages from the messages tab:

slack-app-allow-slash-commands

With this feature enabled, people in your Slack workspace can write slash commands and your bot can understand them and possibly process them.

Next, we need to go back to Flow XO and click on Next at the right-bottom of the page:

flowxo-slack-bot-next

Then, you need to click on Add to slack to add your chatbot to your Slack workspace:

add-flowxo-bot-to-slack

Slack will open up and you need to give permission to add the chatbot to your workspace:

allow-slack-chatbot-to-workspace

And now your chatbot is successfully connected to your Slack workspace. You can find the chatbot under “Apps” in the left sidebar and talk to it:

slack-chatbot-in-workspace

 

 

Add your Slack Bot to a channel

When you’ve added your chatbot to your Slack workspace, it isn’t automatically added to every channel.

If you want to add your chatbot to a channel, you can just mention them inside the channel and Slack will automatically ask if you want to add them:

invite-chatbot-to-slack-channel

Now, you only have to click on Invite them and when you say “wifi password” the chatbot will reply inside the channel:

slack-bot-in-channel

 

Now It’s Your Turn

And that’s how you create a Slack chatbot, without writing a single line of code.

Now I have a question for you: How are you planning to use Slack chatbots for your business?

Please let me know by leaving a comment below👇

Comments (4)

  1. Ricky

    I can get this to work in a channel, but not in a private DM chat. Is this just a matter of setting the BOT token scope? Or will I need to do something else to make this work in a DM chat? I’ve tried to @ my bot (invite) to a DM chat, but it doesn’t actually invite them.

    1. Joren Wouters

      Hey Ricky! What do you mean by a private DM Chat? Is this a group chat or a 1:1 chat with the Slack chatbot?

  2. Ricky

    OK, so looks like you can’t integrate the bot to an existing DM chat or an existing DM group chat. If you create a new DM and @ the bot into the conversation, then it’ll respond to messages. However, if you @ the bot in an existing chat, even though it says it’ll be invited, it won’t actually be included in the chat.

    From the api.slack.com page where you manage your BOT, you can add it to a workspace and choose a specific channel or even a DM chat to add it to. If you add it to a DM chat from there, the chat will say something like “added an integration to this channel: (name of your bot)” and it will still NOT respond to messages. Only way is to create a new DM chat and @ the bot while you add the users to include in the chat.

    Alternatively, convert the chat to a private channel and that’ll work. It kinda sucks but is there a way to make this work with existing DM chat, without going through what I did?

    1. Joren Wouters

      Hey Ricky! What do you mean by a private DM Chat? Is this a group chat or a 1:1 chat with the Slack chatbot?

Leave a Reply