Making a slackbot using Python


For those of you who don’t know what slack is- Slack brings all your communication together in one place. It’s real-time messaging, archiving and search for modern teams.

Things to know


API’s – Application programming interface is kind of like a pact between the provider and the reciever, wherein you can request data from the host server using the API and the API key.
For example you can request google maps to send you the map location of Chennai in your application only and only if you have an API key and use the Google Maps API.


Webhooks are like reverse API's, wherein you provide the information provider with a URL/Address where all new data goes if any.

The difference between the two is that in the first one you have to keep checking for new data/changes where as in webhooks any and every change/data is sent to the address provided while creating the webhook.

Getting Ready

For our first slack bot we will not be using a webhook, in other words we will be pinging slack servers again and again till we see a change and then process the change.

pip install slackclient

Go to Slack API Page

After all this get your API key Next you willl need to get your bot’s ID for that RUN this simple code just once and copy your bot ID

import os
from slackclient import SlackClient


slack_client ="YOUR API KEY"
if __name__ == "__main__":
    api_call = slack_client.api_call("users.list")
    if api_call.get('ok'):
        users = api_call.get('members')
        for user in users:
            if 'name' in user and user.get('name') == BOT_NAME:
                print("Bot ID for '" + user['name'] + "' is " + user.get('id'))
        print("could not find bot user with the name " + BOT_NAME)

After running this you should get your bots ID.

What I tried to do was, build a sentiment analysis bot.
To do the sentiment analysis I used Indico
Further code and explaination can be found in my github account.

Mini Project

Create a slack bot that sends a general report to the admin of the group/ group leader at the end of the day.
The report should consist of the following.
Avg mood of the group: Positive

Most Positive/Negative Person: Name

Leave a reply:

Your email address will not be published.

Site Footer

Sliding Sidebar

About Me

About Me

Hey, I am Thomas Ashish Cherian. What I cannot create, I do not understand.

Social Profiles