Dialogflow Tutorial: Create AI Chatbots with Google’s NLP Engine

Parth Shrivastava
Chatbots Life
Published in
6 min readJun 15, 2020

--

Photo by NeONBRAND on Unsplash

What is Dialogflow?

Dialogflow (previously API.ai) is one of the leading chatbot builder platforms. It uses NLP, which enables us to build and implement the interactive interface for mobile and web apps.

In this article, I will show you how to create a simple chatbot using Dialogflow. You will find details about the tools and the technology used while building a chatbot.

The article also has a walkthrough of the Dialogflow tutorial. It outlines the chronological flow so that by the time you finish reading, you will have a basic idea of how to create a chatbot like RepoFinder.

Let us now dwell on the question of why do you need chatbots.

Why do you need a chatbot?

Gartner predicted that by the end of 2020, 85% of customer interactions would be managed without a human. Who would do that? — bet your money on chatbots.

Google also declared an imminent shift from a mobile-first world to an AI-first world. Companies across various industries are riding the wave and have deployed AI-powered chatbots for their businesses.

Chatbots, if they can fulfill their potential, will be much more sophisticated than traditional apps. They can understand natural human language, by virtue of which, chatbots will be much more interactive and engaging.

Trending Chatbot Articles:

1. Publishing your Chatbot on Microsoft Teams

2. 🤖 How to talk to Computers: A Framework for building Conversational Agents — Part 1

3. Designing a chatbot for an improved customer experience

4. Top 5 NLP Chatbot Platforms

As AI improves in the future, talking to a chatbot will be like talking to someone who empathizes with a real human and a brain reminiscent of Google.

Now let’s get back to building a bot.

How to create chatbots using google Dialogflow?

Required tools and technology

  • Dialogflow: Bot framework to create intelligent chatbots, which you can then integrate with your apps.
  • Node.js: To define the fulfillment logic, which eventually processes the data.
  • Kommunicate: Chat interface to query the chatbot and display the resulting output.

Now let me help you get familiar with DialogFlow, but first, a little about the project as I will be drawing inferences from it in the course of this article:

Creating your first chatbot — RepoFinder (Project Name) — RepoFinder helps you find open source development libraries from Github, based on your input.

Creating Agent

Sign up for Dialogflow and open your dashboard. The first step is creating an agent, which essentially is the bot you are building. You can create one through the console by following these instructions. In our case, we’ve named it RepoFinder.

Creating Intents

Next, you will have to create Intents. Intents help the bot perceive the user’s input and decide the subsequent action. Intents can be created both from the console or by calling APIs.

Dialogflow, by default, gives two intents: Default Fallback Intent, Default Welcome Intent.

More Information on creating Intents can be found here.

Intent In Dialogflow

Creating Entities

After Intents, you need to define entities. Entities are powerful tools used to extract parameter values from the user’s query. Any actionable data that you want to get from a user’s request should have a corresponding entity.

Consider our agent RepoFinder. The user says, “Tell me the best Chat SDK on GitHub” — this should tell the agent that the user needs some info on Chat SDK.

So how do you configure the agent to do it? Well, for each user expression mapped to an intent, the agent needs to figure out the respective input that the user wants info about. This, the agent does with the help of Entities.

So for each intent you create, every user expression should contain a corresponding entity that your bot agent needs to figure out. Now by default, the agent can’t do that — you need to train it to do so.

Entities in Dialogflow

Training the Agent

Dialogflow provides a training tool that allows you to add annotated examples to relevant Intents in bulk (see screenshot below). It helps to improve the classification accuracy of the agent. Here you will also receive a log of all the queries sent to your agent and what the agent responded in return.

This is very useful if you tell your agent something and it responds with an output you don’t like. It can also be helpful if you realize later that you forgot a synonym of an entity, and users are using that a lot, then you can tell your agent what to do in that case.

Actions

Now your chatbot is all set to function. Every time it receives a query, it will first capture the intent and then extract the entity. The next step is to generate a response, which the user is ideally seeking. You can do this by leveraging webhooks to fetch data from external sources (GitHub API server in our case). You can do this in the Fulfillment Section by specifying the webhook URL.

The penultimate step is to tell the intent to use this webhook to respond with the data that was returned from it.

Integrating RepoFinder in Application/Website

For detailed instructions on how you can use your newly created bot on a website are given here. You need not write any code for integrating a bot on your website; just use the Kommunicate chat interface.

If you want to do it on the code level, follow the below instructions.

The image below demonstrates the integration architecture and the sequence of information flow:

Integration Architecture
  1. The user comes to the website and asks for the required library.
  2. The website uses Kommunicate APIs to send messages to the application server.
  3. The application server sends the query to the Dialogflow agent.
  4. The agent uses machine learning algorithms to match the user’s requests to specific intents and uses entities to extract relevant data from them → thereby processes natural language to convert it to actionable data.
  5. RepoFinder returns the actionable result to the application server
  6. A part of Response of RepoFinder look like this:
    { “parameters”: { “keyword.original”: “chat”, “keyword”: [“chat”] } }
  7. Dialogflow agent’s response with all the details available here.
  8. Application server calls Github search APIs/internal database to get the list of libraries related to the keyword.
  9. The application server then sends the list of libraries back to User again by calling Applozic APIs.

That is pretty much all you need to do to build a simple bot in Dialogflow.

You can checkout RepoFinder here. You can get the full project with the source code on Github.

Just play around with Intent, Entities, and Action to build your own flow and chatbot. We can’t deny that chatbots are going to handle most of our customer interactions; starting now would definitely set you on pace with your competitors.

Related Reads:

  1. Dialogflow vs. Rasa: Which one to choose for building chatbots

This post was originally published here.

Don’t forget to give us your 👏 !

--

--