If you are reading this, chances are high you have spoken to a bot.
Yup, you who is reading this. You. Have. Spoken. To. A. Bot.
Before you go all Terminator on us and close this window and scroll away to another chatbot story that you found interesting out there on Google, bear with us.
Chatbots are those interesting little guys who occupy a corner of your screen, usually the bottom right (don’t look, we don’t have a chatbot, yet) and help you with a question that you need an answer to.
Questions like:
- What are your pricing options?
- Where can I find more details about your product?
- Do you have any client testimonials to back up your claims?
- Where can I stash a body if I don’t own a ranch and live ina two-room apartment with three other guys?
The chatbot may have some trouble with the last question. Moving on.
Chatbots represent a form of marketing called Conversational marketing, which has been around for as long as we can all remember.
When you used to walk into a store maybe a decade ago and ask a salesperson about the right kind of vacuum cleaner for your house, that was Conversational marketing.
Ever picked up a phone and spoken to a company rep who explained to you why the “Toastmaster 5000” will solve all your breakfast problems? Yup, that’s conversational marketing too.
Chatbots are just taking those conversations to a whole another level. And they seem to be working too. This Gartner report says that 85% of all customer interactions will be managed without humans as soon as 2021.
Add to this other interesting Chatbot statistics such as:
- 40% of all online shoppers, irrespective of age, prefer to use a chatbot, according to this Tidio report.
- According to this Forbes report, three out of five millennials have used Chatbots at least once in their lives,
- 63% of customers feel that businesses of the future should be conducted on Messenger.
- By 2021, 50% of all companies will spend more on chatbots than on traditional mobile apps.
We now know chatbots are cool, and that they can lead us to some serious moolah, but we need to brush up on a few basics before we get down and dirty building one.
Getting the basics right
Chatbots are cool. You get it. But should you actually invest your time and money in building a chatbot, and, if yes, what framework should you choose?
To answer these questions, we turn to Master Shifu from Kung Fu Panda, who said something along the lines of
Figure out what problem you and your website are trying to solve, and if a chatbot will help the customer in his user journey.
Start by asking yourself these simple questions:
- Should my business by available 24*7?
- Does a chatbot make sense when most of my business is B2B, and customers prefer to speak to a sales rep?
- Do my customers want faster customer service?
- Do I need to lower my labour costs?
- Can customers find everything easily on my website, or do they need more personalized service?
If your answer is YES to most of the questions above, a chatbot is a must for your business.
We will now look at the structure of a chatbot, telling you important definitions that you need to learn if you wish to move past the “Chatbot- Noob” stage.
A chatbot usually consists of 3 components: A messaging platform, a Natural Language Processing Engine, and a Database.
We won’t get into the nitty-gritty details here, since we can’t wait to show you how we built a Chatbot using Rasa, but here is a graphic we found online that will give you a better idea.
Now you need to remember three key chatbot terms before we move further
- Intent: The intent of a visiting user answers the simple question — What does a user want? Let us say the user says something like:
The intent of the user would be book_flight.
- Entity: Entities are the buckets of data that is used in the conversation between you and the chatbot. These are the blocks that you would like to send to the server to process later on, and consists of information you want to capture from the user.
Hre the entities would be: from_city: Los Angeles
to_city: New York
- Stories:
Think of stories as to how you would like the conversation to flow. Different responses you give to the chatbot will have different replies. You are telling the chatbot the various combinations that are possible in the conversation.
Think of it as teaching sentence formation to a seven-year-old You need to train the chatbot on all the possible responses a user can give.
Once you have mastered these basics, you are now ready to build a chatbot on your own. Let us see how that pans out:
How we built a simple conversational chatbot
Step 1: First, we’ll install python 3.
Step 2: Create and activate the virtual environment using the below commands.
- python3 -m venv ./venv
- source ./venv/bin/activate
Step 3: Install Rasa open-source with the below command. If you are facing any issues, you can explore the documentation.
- pip install rasa
Once the packages installation is done, let’s create the project directory.
mkdir v-assistant
cd v-assistant
Simple so far? Now things get a bit more interesting.
Create the new project with rasa init-no-prompt command.
Once the project is created, you will see below logs in the terminal.
The rasa initcommand creates all the files that a Rasa project needs and trains a simple bot on some sample data.
You can play around with this data to get the hang of things. Remember training a seven-year-old that we mentioned earlier? Follow the same principle.
This creates the following files:
Let’s interact with the sample bot to see if the execute rasa shell command from the terminal is working.
As you can see, we can interact with the sample data.
Now let’s see how we can make the bot more interactive, for which we need… drumroll…stories!
We have told you what stories are before, but we are going a bit technical here for people with some coding background who like big technical words.
A story is a representation of a conversation between a user and an AI assistant, converted into a specific format where user inputs are expressed as corresponding intents and entities ( where necessary ), while the responses of an assistant are expressed as corresponding action names.
We’ll first add intent, then it’s the corresponding action, and finally, we’ll train our bot to do what we asked it to do. Hell Yeah!
Let’s say we want a chatbot to speak a name when the user asks the name of our chatbot. So we’ll add intent for that in the intent.md file.
Here ‘##intent’ defines the intent e.g.- ##intent:welcome, ##intent:name. Also, we have to register the intent in our domain.yml file in the intents section, as shown below.
After the intent, we’ll define the action for that intent in the same file under the responses section.
Now that you have defined the action, we have to register that action in the same domain file under the actions section.
After adding the appropriate action and intent, we’ll define the story in stories.md file.
Now, as our NLU data and stories are ready, it is time to train the bot.
We can do this with rasa traincommand in the terminal.
After execution run the command rasa shellfor interaction.
As you can see, the bot will utter its name when the user asks for it. The action which we have added is utterance action, which starts with utter_ and sends a specific message to the user.
Rasa has provided more information about the action here-
This way, you can add N number of intents, actions and make more user stories.
We still need to build the dialogues and stories with some custom actions, entities, and slots so that bot can respond to the messages.
As a bonus point, we can integrate it with different channels and web applications.
I would recommend going through each section step by step and reading the Rasa Documentation to understand it better.
Parting words
This is just grazing the surface of building Chatbots, and if you want to go deep, we would recommend you to compare frameworks like Rasa in this post and choose one that you like.
Once you pick a framework, the world is your chatbot’s oyster, and you can program it to help out any customer that comes to your site, except maybe the shoddy character with a dead body that we mentioned in the beginning.
You can also take your chatbots to the next level by asking your chatbot to send meaningful data to a third party API and then perform an action in that system.
For instance, you can connect your chatbot to Salesforce and ask your visitor for his basic information like name and email. If the person has interacted with your business before, you can provide him a personalized user journey by doing away with the initial questions. The possibilities are limitless!!
Now that you know why chatbots are important and how to build a chatbot using Rasa, we feel it is time to pick up that lightsaber, young Skywalker. If, at any point, you feel stuck or want to build a bot for your business, send us a shoutout here at SoluteLabs.