How to Make a Simple Chatbot

Original article was published on Artificial Intelligence on Medium


How to Make a Simple Chatbot

In under 10 minutes

Since tutorials are often easier to follow in real-time.

You may have heard about the hype surrounding AI. Maybe you’re a business leader or an aspiring student. Either way, you’ve probably seen the headlines claiming that ‘AI is on the rise,’ perched at a developmental crest and ready to subsume humans at work. Well, I’ll let you judge that decision for yourself. In this gentle introduction to building an applied chatbot, I show you the basic capabilities that any sensible individual can create, empowered only with tools provided by Dialogflow and Actions on Google.

So, what exactly *is* Dialogflow? The simple answer is this: to help people interact with technology in a more streamlined way. For example, let’s say that I asked my machine, “What coffee shops are open nearby me today?” For more traditional or hard coded systems, if the question wasn’t asked in exactly this manner, then the system would not be able to understand what you were saying. At least in English, there are several ways to convey the same “meaning” with different words…

  • “Is Starbucks open?”
  • “Which coffee shops can I go to, today?”
  • “What cafes take mobile orders?”

We like Dialogflow because it can handle these different end-user experiences. In order to break down this very fundamental understanding of variance in human speech utterances, I’ll (very) briefly review some basic principles behind Dialogflow that will make the rest of the tutorial more accessible, and should provide you with a useful framework for future chatbot interactions.

Now within Dialogflow, we also have entities known as agents. These virtual agents that handle conversations with end users. These get trained, like call center agents, to handle expected conversations.

Agents learn to recognize something known as an intent, which as humans, we naturally understand as something that refers to your motivation, or reason for asking something. Perhaps you’ve listened to somebody ramble and you’re sort of just wondering in the back of your mind “Get to the point!” Well, you’re ultimately able to follow a conversation because you’re constantly assessing a probability of what somebody’s intent is during a conversation. Likewise, an intent is used to help your virtual agent take a phrase and understand what the user, or speaker, wants to get out of the conversation and then inform the agent’s final response.

So with the cafe example, the intent could be described as a “Find Cafe Intent.” Before you can even order Starbucks, the agent needs to know where to find a cafe, so we ask for your zip code in the first pass. Equipped with this intent, our agent then knows what kind of parameters to listen for, what kind of data that it needs to extract, and what kind of answers or responses the agent should give your end user. Some example responses might be:

  • “Sure, Starbucks is open 0.1 miles from you.”
  • “The Philz Coffee within 2 km from you is closed.”

Finally, within each intent, we can define Entities, that identify key pieces of data from a user’s utterance that we should extract. Conceptually, these are like objects that the agent should look for in the conversation — such as “date” or “location.” Perhaps the entity types are even more customized, like a “coffee’ entity that matches different types of coffee (americano, mocha, iced latte) that may be available for purchase with our caffe agent.

Before we get into the process, the final component to consider is a Dialogflow Context. Just as how context matters in normal conversations, Dialogflow agents need to understand the context, in order to match the intent. For example, if you just randomly walked up to somebody on a sidewalk and said, “Ok let’s order a mocha!”, then you would be likely to receive a bewildered stare and this humble stranger would probably say something along the lines of “Um, who are you?”

However, if you set the context by first asking the same stranger, “Hey, what coffee shops are open nearby me?”, then you set a ‘Cafe-Shopping Context.’ Therefore, this previously bewildered stranger might respond more normally if you followed up with “Could I order a mocha?”

The last ‘foundation’ that you should understand for building Chatbots using Google Assistant is an Action. Just as the name implies, an action can be the first entry point to initiate an interaction with your assistant. This is like when we start a conversation with “Hi Dr. Starbucks!” in order to activate our Starbucks chatbot. However, even more broadly defined, an Action enables the fulfillment or execution of some user-defined intent, through some service, app, or logic.

If you’ve got any more questions, feel free to reach out to me directly or check out the YouTube video. In the meantime, let’s get our hands dirty!