Create A Google Assistant Chatbot Using Dialogflow

Create A Google Assistant Chatbot Using Dialogflow

A short tutorial exploring how to design a chatbot for Google Assistant using Dialogflow

Introduction

In this article, we are going to create a dummy chatbot to order pizza using Google Assistant. We need to have an understanding of Chatbots and Dialogflow before getting started.

What are chatbots?

The chatbot is simply a chatting application in which the user/customer chats with an application/bot to get a solution for any specific task that the bot is designed for.

Chatbots are designed for specific tasks i.e if the application is designed to order food, it can help with ordering food-related tasks. The more we train the application bot, the more it will understand the phrase given by the user and give the response more accurately. We will learn this as we go forward and create our first bot.

There are several interfaces where we can connect our application bot like Messenger, Google Assistant, Slack and much more. We can create our own custom interface as well. In this tutorial, we will cover the integration with Google Assistant.

Google Assistant

This is developed and maintained by Google and is primarily available on mobile and smart home devices. Users can interact with it via text/voice and schedule/execute tasks.

Dialogflow

Dialogflow is a natural language processing platform. For a chatbot, it is important to understand what the user is trying to say as much variety as possible. For example, if the bot asks ‘what is your name?’, the user can answer it in several ways like "my name is John"/"John is my name"/" myself John"/"Name- John" etc. To fulfill the given request, we only have to say the word "John" instead of factoring in the entire sentence. This is where Dialogflow comes into play. It is made and maintained by Google. We can pass an entire string to Dialogflow using REST APIs which in turn will return meaningful text to which we can use to interact on the application at a later time.

Few terms to understand in Dialogflow:

Intents: In Dialogflow, intents are created to understand what the user is trying to say by providing multiple training phrases which may be written by the user. When an end-user writes a phrase, Dialogflow uses its NLP algorithm to find the best possible intent from a list of intents and returns meaningful data derived from it.

Entities: Entities are used to extract names, places, or things from a user's sentence. For example, we shall create an entity named states inside which we will store the list of states needed in the application. Now, when a user types something like, "I live in state XYZ", it is passed over to Dialogflow. In case the XYZ state is found in the state entity, Dialogflow will understand and return XYZ to the application, which the developer can use later on as needed.

Steps to create a flow in Dialogflow:

  • First, open dialogflow.cloud.google.com and sign in using your desired ID.

  • Next, create an agent using the button displayed over the dashboard with the name pizza-order-bot.

  • You will notice that there are already two intents created by Dialogflow. These are the Default Welcome Intents which contains training phrases related to greeting messages and the Default Fallback Intent which is the default intent for Dialogflow in case the message doesn't match any other intents.

  • Now, create an Intent with the name Pizza Order Intent using the button provided.

  • After this, click on add training phrases and enter some phrases which the user may say for ordering pizza, i.e. "I want to order pizza", "Get me pizza", "I am looking for pizza", "I am hungry", and finally save it.

  • Now, create two entities namedSize and Toppings. In the size entity add small, medium, large as the required options and add cheese, tomato, mushrooms etc. in the toppings entity and save it.

  • Next, go to the Pizza Order intent and click on Add Actions and Parameters and proceed to fill the table as shown in the image given below. These are the questions that the bot is going to ask the user for the desired size and toppings as well as the location.

Screenshot 2021-07-01 at 11.51.40 AM.png

  • Now when the user says something which matches the required intent, the agent will ask the questions mentioned in order unless the user enters a value. These user values will be saved in the parameter name mentioned which will be used further during order confirmation.

Note: The location parameter uses a system entity defined by Dialogflow which contains its own list of addresses. Since this is a very basic flow which you are creating, please give any standard address like Amsterdam, Bangalore which can be recognized by the Dialogflow.

  • Now, we need to give a response to the user with the order details and status in the responses section. The parameter values can be used in the sentence using the $ sign. Add the below phrase in the response or you can use your own suitable one and save it.
    “Thanks for the information. The $size pizza with topping $toppings is on your way at $address.”
    
  • After completion, you can test your flow in the right console by saying something similar to what you have used for the training phrases.

Integration with Google Assistant

  • To start off, choose Integration and click the Google Assistant visible at the top on the left sidebar.

  • On clicking, you will see two fields i.e explicit and implicit invocation. Keep these fields as they are and click on the test given below. It may take some time to open the simulator to test the app. If the enable web and app activity screens to come on, you can skip this process. Additionally, you can test the flow in the next screen(simulator) that comes up or you can use your phone as well.

  • To test on a mobile device, first sign in with the same Google ID with which you had logged in with into Dialogflow. To proceed, enable Google Assistant by long-pressing the home screen and say/type “Ok Google! Talk to my test app.”

  • The first response will be a greeting message. Then you can start to test the flow by saying something like “I want to order pizza.”

Conclusion

Congratulations, we've finally made a Google Assistant Bot. You can do a lot more with Dialogflow, like submitting your flow to Google after fulfilling their policies and terms & conditions. Once reviewed and published, your application bot will be available worldwide and anyone can invoke the flow by saying the unique training phrases provided by you.

In the world of fast-growing businesses, customer support service is critical to fulfill the needs of customers and hence a chatbot can be a better solution as it minimizes human effort as well as labor costs.

Thank you, Happy coding!