Create a slack bot!

Slack is one of the most used communication tool across teams in companies around the world.

You can use bots in Slack to automate your routine tasks, play games, challenge a friend, get live match scores and weather or even book a table for your next team lunch! Sounds interesting, huh?

To create a bot, all you need to know is to write API’s, and… in any language/framework of your choice.

In this post, I’m going to walk you over creating a simple hello bot. When you say hello, our bot will politely greet you back!

That's our hello bot
That’s our hello bot

Head to your slack domain, and click on your team name.  Pick the ‘Apps and Custom Integrations’ option.

Do you see a ‘Configure’ button on the top left? Click that.

Now, let’s create a ‘Custom Integration’.

Click on ‘Outgoing WebHooks’, and ‘Add Configuration’.

Jump to the Configuration Settings.

Here, you can set the channel to which you want your bot to listen and respond to. Trigger words are the words that will trigger your bot, literally! You can choose multiple trigger words, separating each with comma. We are going to use the trigger word ‘hello’.

Leave the URL blank for now, we shall get back to it soon.

Set a name for your bot in the ‘Customize Name’ field. Let’s call it ‘hello bot’

Give your bot an icon in the field below.

Now, let’s start coding.

I am using Sinatra, you could use anything you are comfortable with. Really!

Assuming you have ruby installed, go ahead and install the ‘sinatra’ gem.

gem install sinatra

Now make a folder for your project, and add a main.rb (can be any name) file in the folder.

Create a POST request that just returns a greet statement.

require 'sinatra'
post '/hello' do
    "Hello, " + params["user_name"] + " ! You look good today!"
end
 

Now, deploy the app. This is outside the scope of this post. If you have not done this before, get a Heroku account, and this link will get you deploy your app on Heroku.

Back on Slack, enter the URL of your deployed app in the URL field, which we left blank earlier.

You are almost done! Go ahead and type ‘hello’ in the slack channel you mentioned while configuring.

The Hello Bot greeted me: Hello, aishwarya ! You look good today!”

Have fun exploring !

Cheers,

Aishwarya

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s