Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Create Your Own Chatbot Using Google Dialogflow

DZone's Guide to

Create Your Own Chatbot Using Google Dialogflow

Dialogflow is a popular AI and NLP platform for creating chatbots. Consider a simple use case in which a user asks a Dialogflow bot to find the best places to get pizza.

· AI Zone ·
Free Resource

Enable your enterprise to add AI to your existing infrastructure with EdgeVerve’s Business Applications built on AI platform Infosys Nia™. Register for our webinar to learn more.

Hi, all! In this tutorial, we’ll see how to create a simple, static, conversational, user-friendly chatbot. We consider a simple use case in which the user can find the best places to get pizza. Before going into the use case, let's get some basic knowledge on Dialogflow.

Dialogflow

Dialogflow is now the number-one AI and natural language processing platform in the world for all type of businesses. It's Google's product and is freely available to use. With integrations with both voice and text AI applications like Google Assistant, Amazon Alexa, and Microsoft Cortana, you can build any type of AI app for your customers, who will be able to interact through their mobile phones, Google Home, Amazon Alexa, and more.

Image title

Dialogflow not only integrates with all these platforms to allow voice recognition — it also has text integrations for Facebook Messenger, Twitter, Skype, Twilio, and more.

Prerequisites

  • Dialogflow account

Create an Agent

  • To create an Agent, log into your Dialogflow account. Click on down arrow on the left-side menu and select Create new Agent.
  • Provide the Agent name and click on the CREATE button. In this scenario, I call it BestPizzaPlace. You can even add some description to your application and choose a specified language.
  • The new Agent with the name you defined will be created along with two default intents: the Default Welcome intent and Default Fallback Intent. An agent is created successfully.

Image title

  • Let’s create our first intent or continue with the default welcome intent to start the conversation. Here, I am using the default intent as a starting point.

An intent is a symbolic representation of an utterance. The intent is what the user or bot wants to convey using utterances or button-presses.

Image title

  • Add the sample utterance in the User Says text field as shown in the below image. Let’s add few greeting phrases that the user might say to the chatbot.
    • “Hi”

    • “Hello”

    • “Hey”

    • “Hello there”

  • Skip the Events tab and go to the Action tab and add an action name to identify the system intent. Here, I have named it Bot_greetings.

Image title

  • Scroll down to the RESPONSES tab, click on ADD RESPONSES, and add the bot’s responses to the user. This is the actual message that the bot will send to the user. Let’s add few responses in the Text Response field as following:
    • “Hello, welcome. I can help you know the best place for pizza.”

    • “Hello, greeting! Want to know about pizza locations?”

    • “I can help you to find the best place to get pizza.”

You can add more responses so that the agent can randomly pick one to make it less boring and more interesting. You can add up to ten additional response of any type.

Image title

  • Click on the SAVE button in the top-right corner of the window. Now, you have created the first intent of your agent.
  • Create a new intent to continue the conversation and add the user requests from above as the user says in this new intent, e.g. User_request.
  • For example, the user want to ask the bot to tell the best restaurants for pizza using the following utterances:
    • “Best place to find pizza”

    • “Where can I find pizza?”

Image title

  • In the above utterance, the user is asking for the best place to find tasty pizza in different ways. The first step is to map all these utterances to the single intent with the name User_request and click on the SAVE button.
  • Scroll down to the RESPONSES tab, click on ADD RESPONSES, and add the bot’s responses to the user. This is the actual message that the bot will send to the user. Let’s add few responses in the Text Response field as following:
    • “Here are the best places to get pizza: Domino's Pizza, Pizza Hut, and Italian Pizza. Thank you. Have a nice day!”

Image title

  • Click on the SAVE button on the top-right corner of the window to save the defined data. Now, your bot is ready to test.
  • Test the bot using the simulator on the right side of the page. In the Try it now box, type Hello and press enter.

Image title

  • You will see the chatbot recognizing your typed utterance and responding appropriately.

Image title

  • You can even see the message structure from Dialogflow by clicking on SHOW JSON at the bottom of the page.

Image title

You can go on more and more intents with different options for what the user says and different use cases. To add new intents, click on the + sign beside the Intents option in the menu on the left. Think about the kind of information the users will ask the chatbot and make a list.

Adopting a digital strategy is just the beginning. For enterprise-wide digital transformation to take effect, you need an infrastructure that’s #BuiltOnAI. Register for our webinar to learn more.

Topics:
chatbot ,dialogflow ,tutorial ,ai ,bot development

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}