visit
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 Ruuh by Microsoft have been able to deliver human-like conversations using artificial intelligence and deep learning.
Do you remember Natasha from Hike? 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.
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 data being stored and used for the company’s benefits. Recently Google India tweeted asking ‘why do Indian users keep asking Google Assistant to marry them?’
Can we do anything about this? Most Probably No.
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.
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 Architecture for our Slackbot.
Image Credit: Sweta Sharma
And this is our Entity Relationship Diagram which will help you create your own database.
Image Credit: Sweta Sharma Clone the repository from .
Create a .env
file in the /src
directory of your project.
This is your main file: slackbot.py.
slackbot.py first imports all the packages required to run the Slackbot. It then initiates the slack client using your stored in your .env
file like this:
It initializes the constants and tries to connect with the Slack’s RTM API and if it fails to establish a connection then it returns Connection failed with the error message printed above.
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 slackbot.py file.
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:Note: For more information, you may look at the Python Library.
After you get your Custom Search Engine ID, get a API key and you are good to go.
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.Note: We have assumed our first YouTube search result to be the most accurate one for our users requesting for songs.
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.
Note: You may find useful to install the Bitly Package from GitHub.
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.Note: 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.
You need to get the API key of . You can choose your favorite football leagues from the leagues offered in the .Here is your football.py file.
The live_football
function fetches and extracts the live scores for the live football matches of the selected leagues stored in comp_id
dictionary and returns a list of tuples for the live matches with the required information of both the teams.
When the user subscribes for live football scores from the Slackbot, our football_res
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.
This is your news.py file.
It requires a key to fetch the latest news and a to shorten long URLs.
Note: You may find useful to install the Bitly Package from GitHub.
It returns the News with the title, description, and the news link as a formatted message.
Note: 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.
This is our task.py file.
If the user message starts with ‘remind me on’ then our parse_tasks
function extracts the date, task description and time from the user message received and verifies whether the date and time provided are valid.
If everything is parsed correctly then the task gets stored in the tasks table in our database and our users get a confirmation message letting them know that the task is set with the formatted date and time for the event.
Note: 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.
Here is our reminder.py file.
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 parse_reminders
function extracts the date & reminders from the user message received and verifies whether the date provided is valid.
If everything is parsed correctly then the reminder gets stored in the reminders table in our database and our users get a confirmation message letting them know that the reminder is set with the formatted date for the occasion.
Note: 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.
There are many features like facts, quotes offered in the Slackbot which I haven’t discussed in this article as their implementations were pretty straight-forward. There is also a help
command provided to our users where they can know about all the available features and their assigned commands.