In this blog, we will understand on how to create a chatbot which makes you learn Data Science by sharing few documents from Beingdatum google drive repository.
First of all we need to setup Rasa, all details on wha is Rasa and setting up Rasa is shared in this blog-Rasa Setup
Once you are done with setting up Rasa let’s start doing custom changes in the project to make it as per our use case.
What is Intent?
It is the verb in your dialog which you write as your user input.
“I want to order a book” or “Placing order for a given book”. Here, the intent would be “ordering”.
Example-Good morning .Hi, Hello, hey there
Intent : greet
What is Entity?
It is the nouns in the dialog as it is an useful information from the user input that can be extracted.
Example: Reserve a table at a hotel tomorrow night
Intent : book a table
Entity: Place: hotel
time: tomorrow night
What are Stories?
These are sample interaction between the user and bot, defined in terms of intent captured and actions performed. So developer can mention what to do if you get a use input of some intent with/without some entities.
Now, let’s understand on how to make a rasa chatbot and integrate google drive in rasa?
1.You need to know how to make a chatbot using rasa.You will get the following files while you make the chatbot using rasa init command.
(first you need to install rasa before creating the chatbot)
Part of rasa folder
Intent and entity ———————> nlu.md
Also , you ngrok.exe you may need to download from internet if you are using slackbot integration. Steps to do Slack integration is mentioned in this blog – Rasa Slack integration
After you have got all the files then we need to write a python script from which we can integrate google drive with our rasa chatbot.
1.You need to create a google API account from where you will get the credentials.json folder which will be used to get access of your account ,from there you can also get access to your google drive where we can search retrieve a particular file, ppt and folder while we search for a given file from your rasa chatbot.
Site from where you can register google api
Steps to get credentials.json and token.pickle mentioned here – https://developers.google.com/drive/api/v3/quickstart/python
2.After getting all the files we can start by creating a python script in actions.py
First we will import all the packages that are needed. These will be available as default when you install rasa on your machine.
2.1 After this we will create a class Actionquestion() where will be write our whole code to integrate google drive with rasa.
The class is the action which will be responsible for answering the question which will be specified in nlu.md as intent: questions. So it will receive the question that will be asked by the user when using rasa chatbot.
It will fetch in the request to the given script and then it will initiate the actions which will help use to get the particular file from the given drive.
In this we have just laid the scope and the imported the packages that will be used in the given program.
This is written so as to access the google account and get the particular folder from the given drive to when you input the given particular file in the rasa chatbot.
This is the whole code for google drive integration using python on rasa
You can run this script by – rasa run actions
Now you will change and create intent in nlu.md, create path In stories.md and then in domain.yml you use these intent and stories to print the result.
It is the rasa nlu where you train your bot for all the actions that you want It to perform in your chatbot.
Nlu capture the intent and the training data for the intent.
As you feed in more intent then with each data that you put you need to retrain the rasa chatbot by using the command rasa train
Intent has all the feature inside it so when you ask a question it is actually the intent which has the given question inside it.
In this when you ask a question the intent will use the keyword greet and then as you would have asked “hi” so it will give you a reply respect to the given intent.
As we ask a particular question in the intent:question in rasa chatbot it will give the answer with respect to the file which is in  bracket and document which is in () brackets.
*Remember that the document was been specified in the python script.Document will be the entity as well as the slots as by referring to the given script you would be able to get the particular file and the python script will be active when your slot document is asked as a question in the chatbot.
After you write all the intents then we will go to the stories.md to see how to make stories of the intent that we have written previously. Sample below.
- good morning
- good evening
- i m good.
- good. thanks for asking
- i am great
- first time
Stories.md is a file which show the interaction between the user and the bot.
The path is a set of condition which is written in stories.md to show how a particular conversation between a user and a bot will take place. The interaction is all written in the path.
Take ##happy path
- There are two sub-points of greet and mood great. You can see that the intent which was given in nlu.md is been referred here.
So when you ask a question as hi it will great how are you that is because in domain the utter_great function is defined as “How are you “ so when ever you input a value which is present in intent as hi,hello,good morning etc you will get a fixed response of “Hi how are you”.
The stories help the user to create set stories which will follow the path which is been written in the given stories.md.
When you start your bot you will ask hello and with this intent it will go to the stories.md happy path section where it will greet and the required response *greet (utter_great) will give a response as “Hey! How are you doing ?”
As you ask more question you can create stories in succession as after *greet it will go to another part of stories of *mood_great and again will print the required responses to the given intent questions.
In this also a particular question from the intent is asked and then it is refered to stories.md for the different case that follow top to bottom stor approach.Then it will connect the slot with the python script by domain.yml.
And then the required answer for that intent is given in the form of dispatcher.utter_message(“”).
## happy path
To combine nlu and stories.md we use domain.yml.
1.First all the intents which you have written in nlu.md file should be written here.
2.entities and slots will be written for the document as it is used to connect the google account and get the required files from google drive.
3.Responses -are all the intent reponse for a particular question which is been written in nlu.md.
All these are text and should be written in double quotes so that you get the required response in the given chatbot.
We have successfully integrated google drive with rasa chatbot.Now you can start the bot by following commands-
rasa run -m models –enable-api –cors “*” –ssl-certificate <> –ssl-keyfile /<> –debug
In the above command –enable-api –cors “*” –ssl-certificate <> –ssl-keyfile /<> –debug is optional which is needed if you want to deploy the bot over a https ssl website.
You can access our Data Science training working chatbot here – Chatbot Demo OR on the bottom right corner of this page.
Git repo link – Git Repo Chatbot
Some screenshots of the chats below-