Chatbots are being used almost everywhere today from social messaging platforms to integration into websites for booking tickets, finding nearby restaurants, generating leads, buying and selling products. Some chatbots, like have been able to deliver human-like conversations using artificial intelligence and deep learning. Ruuh by Microsoft Do you remember ? I used it 4 years ago and was amazed to see how she handled our conversations which were so much better than a bot could possibly handle. I hadn’t heard the concept of machine learning back then. Natasha from Hike Now chatbots have made us so dependent on them that it has become a part of our lives today. “Ok Google, remind me on 20th to publish my chatbot article” “What time?” “Midnight” “Sure, I’ll remind you on Wednesday at midnight.” Chatbots are not only making our lives easier by managing our tasks but they are also becoming quite interesting to have conversations with. “Ok Google, tell me a joke.” “Here’s a joke just in time for Valentine’s Day, I forgot to tell you I have a date for a Valentine’s Day. It’s February 14th.” But all these come at a cost of our for the company’s benefits. Recently Google India tweeted asking ‘ ’ data being stored and used why do Indian users keep asking Google Assistant to marry them? Most Probably No. Can we do anything about this? What if we could build our own chatbot? We could add all the features we need and tweak them as per our likings. So let’s build a chatbot which will help you get more productive at work as it runs on . The chatbot we are about to build is in no way near to the Google Assistant. It is not even voice-enabled. Slack Slack is a messaging platform built for teams to collaborate and work with each other. It is the most common tool used in companies today for communicating with their employees. Getting Started Let’s build a chatbot together on Slack. DISCLAIMER: This project was created by a team of 2 for a competition but unfortunately we couldn’t make it to the finals. This is our for our Slackbot. Architecture Image Credit: Sweta Sharma And this is our which will help you create your own database. Entity Relationship Diagram Image Credit: Sweta Sharma Clone the repository from . GitHub Create a file in the directory of your project. .env /src Install the requirements: pip install -r requirements.txt This is your main file: slackbot.py. first imports all the packages required to run the Slackbot. It then initiates the slack client using your stored in your file like this: slackbot.py Slack API key .env API_KEY=”Your Slack API Key” It initializes the constants and tries to connect with the and if it fails to establish a connection then it returns Slack’s RTM API Connection failed with the error message printed above. If the connection is successful, our slack client runs in an infinite loop and tries to read every second if any user’s message is received and if it receives any message, it extracts the channel id and the message text received from the Slack’s RTM API and further checks if the message received has any assigned command which can be processed to generate a response. Features with code and Explanation Song Lyrics Our users can get lyrics for songs by passing in spelled or misspelled song names right from the Slackbot. This code snippet has already been defined in your file. slackbot.py elif message.startswith("lyrics for "): get_song_name = message[11:] lyrics_gen = Song_Lyrics(settings.GCS_API_KEY, settings.GCS_ENGINE_ID) song = lyrics_gen.get_lyrics(get_song_name) response = '*' + song[0] + '*' + '\n\n' + song[1].replace('<br>','\n') You need to create a by adding any or all of the following websites as per your choice: Custom Search Engine ID https://genius.com/ http://www.lyricsted.com/ http://www.lyricsbell.com/ https://www.glamsham.com/ http://www.lyricsoff.com/ http://www.lyricsmint.com/ For more information, you may look at the Python Library. Note: Lyrics Extractor After you get your Custom Search Engine ID, get a API key and you are good to go. Google Custom Search JSON Get Audio & Video for a song Our users can get audio and video version for songs by passing in spelled or misspelled song names right on their Slackbot. This is your . get_music.py After importing all the dependencies, It requires a to fetch songs and extracts the first link from the search results received for spelled or misspelled song names. YouTube Data API We have assumed our first YouTube search result to be the most accurate one for our users requesting for songs. Note: It then makes use of to extract the audio from the video link of the song. It requires a to shorten long URLs generated for streaming audio which expires within a few hours as well as shortens the YouTube video link for providing the video version of the song. Pafy Python Library Bitly username and Bitly API key You may find useful to install the Bitly Package from GitHub. Note: this article Live Scores for Football Our users get notified about the latest scores for live football matches after every set time intervals. I have only selected top football leagues which fetch live matches for . Premier League, Championship, Serie A, Primeira Liga, La Liga I selected only a few leagues as there are numerous matches live at the moment and sending scores for all the live matches would make no sense to the users. This is a subscription-based service so you need to set up a Database as per my shared schema at the beginning. You can then use a to schedule your live scores to be sent to the subscribed users after every set time interval. Note: Schedule Python Library You need to get the API key of . Football Data API You can choose your favorite football leagues from the leagues offered in the . Football Data API Here is your file. football.py The function fetches and extracts the live scores for the live football matches of the selected leagues stored in dictionary and returns a list of tuples for the live matches with the required information of both the teams. live_football comp_id When the user subscribes for live football scores from the Slackbot, our class object stores the user’s channel id and our slack client API key which further verifies the user’s response and stores the selected leagues by the user in our Database and sends the follow-up confirmation response to the subscribed user with the latest scores for the live matches. football_res News Our users will be updated about current affairs and breaking news daily so that they can be up-to-date about the current happenings. This is your file. news.py It requires a to fetch the latest news and a to shorten long URLs. News API key Bitly username and Bitly API key You may find useful to install the Bitly Package from GitHub. Note: this article It returns the News with the title, description, and the news link as a formatted message. This is a subscription-based service so you need to set up a Database as per my shared schema at the beginning. You can then use a to schedule your live scores to be sent to the subscribed users after every set time interval. Note: Schedule Python Library Tasks Our users can schedule tasks in the Slackbot and it will remind them for the set task at the set date and time. This will help our users manage and complete their tasks on time leading to an increase in their productivity at work. This is our file. task.py If the user message starts with ‘remind me on’ then our function extracts the from the user message received and verifies whether the date and time provided are valid. parse_tasks date, task description and time If everything is parsed correctly then the task gets stored in the and our users get a confirmation message letting them know that the task is set with the formatted date and time for the event. tasks table in our database You need to set up a tasks table in your database as per my shared schema at the beginning. When the current date and time are equal to the set date and time, then send the task to the assigned user. Note: Reminders Users will be able to set reminders for birthdays and anniversaries of their colleagues and friends. This will help them stay connected and keep the communication going. Here is our file. reminder.py Our reminders module works similar to tasks but the . only difference is reminders are sent every year whereas tasks are sent only once at the set date and time If the user message starts with ‘remind me on’ and does not contain time then our function extracts the from the user message received and verifies whether the date provided is valid. parse_reminders date & reminders If everything is parsed correctly then the reminder gets stored in the and our users get a confirmation message letting them know that the reminder is set with the formatted date for the occasion. reminders table in our database You need to set up a reminders table in your database as per my shared schema at the beginning. When the current date is equal to the set date, then send the reminder to the assigned user every year. Note: Conclusion Phew! We have finally come to an end. Congratulations on building your own Slackbot offered with some great features. Here is my Slackbot Github Repository. There are many features like offered in the Slackbot which I haven’t discussed in this article as their implementations were pretty straight-forward. There is also a where they can know about all the available features and their assigned commands. facts, quotes help command provided to our users I would be glad to review your pull requests if you contribute in this open-source community to make this a better one. Slackbot Also, do check out my Python Library to get song lyrics by just passing in spelled or misspelled song names. Lyrics Extractor Thank you so much for taking the time to read this! If you enjoyed it, please give it a bunch of claps as it’ll help more people see this story. And ★ this repository on GitHub if you liked this project. ❤