Nodejs dialogflow

How to create a Chatbot with DialogFlow / NodeJS | Step-by-Step Guide

Dialogflow is a natural language understanding platform that makes it easy to design and integrate conversational user interfaces into your applications. 

Chatbots are indeed recognized as valuable tools for collecting and disseminating relevant information. Their capabilities make them effective in various domains, such as customer service, education, and information retrieval.  In this blog, we will guide you on how to create a chatbot with Dialogflow in a detailed manner.

Let’s dive in!

What is ChatBot?

A ChatBot is a smart program designed to engage with people in a human-like manner, catering to specific domains where it is deployed. It assesses the user’s intention and crafts responses tailored to the conversation.

To rapidly develop a chat assistant, developers, and organizations often leverage Software as a Service (SaaS) products that run on cloud platforms, with Dialogflow from Google being a popular choice.

If you’re looking to create a chatbot, a Dialogflow tutorial is a great starting point. 

What is Dialogflow?

Dialogflow is a Google-owned framework that employs Natural Language Processing (NLP) to develop human-computer interaction technologies. In general, Dialogflow can be used to create digital programs to interact with the end users via natural languages. In other words, we can say that Dialogflow helps to create Conversational User Experience Platforms in a better way.

One-click integration in messaging platforms such as Instagram, Facebook, and Twitter was made easier after the advent of Dialogflow. Before you get started with the Dialogflow, you must be familiar with the below key terms:

Dialogflow-Core-Components

  • User: The user will be a human being who builds, trains, and interacts with the bot, or in general, they use a bot for varied purposes. Only humans can be users and chatbots cannot become a user.
  • Agents: Bots are referred to as agents and they do the supporting activity to humans. So, they are called agents. To see a practical example, you might explore a Dialogflow chatbot example to better understand how to implement and customize your conversational agent.
  • Expressions: Whatever you are converting to the chatbot can be termed an expression. If you want to interact with the bot or like to ask any question, like what is the latest movie released in Hollywood? Or How is the climate in India? These sentences are referred to as Expressions and we will learn more about this in the upcoming topics.
  • Intents: Intents serve as the foundational constructs for the comprehension of user expressions by a chatbot. Given the potential diversity in linguistic formulations conveying identical meanings, these common denominators are identified as intents. For instance, inquiries such as “When will this model of phone launch?” and “When will this model of phone be available?” can be collectively categorized under the intent of ‘model availability.’ This categorization streamlines the bot’s responsiveness to user queries.
  • Responses: It denotes the generated output by the chatbot upon receiving appropriately formatted input that aligns with user queries. For instance, when user expressions trigger the ‘model availability’ intent, the corresponding response may take the form of, “The model will be available from the second week of February.” An adept chatbot is characterized by the delivery of clear, concise responses.
  • Entities: It plays a pivotal role in extracting pertinent information embedded within the natural language input of users. In the framework of Dialogflow, entities are instrumental in discerning specific data points within user expressions, such as product names or street addresses.
  • Actions: Actions, as implemented in Dialogflow, function as mechanisms facilitating the identification and annotation of keywords. These keywords are subsequently connected with entities, thereby streamlining the extraction of relevant information from user input. Moreover, actions operate as prompts, prompting users for additional details as required.

Now that you understand what DialogFlow and chatbots are, let’s explore the process of creating a chatbot using DialogFlow.

Know More : Understanding the Role of Chatbots in DevOps

How to create a Chatbot with Dialogflow: A Step-by-step Guide

Step 1: Setting up a Dialogflow Account

To initiate the process, sign up for Dialogflow and access your dashboard. The first crucial step involves creating an agent, essentially the bot you’re constructing. Follow these steps:

dialogflow

  • Click on “Create Agent” in the left menu.
  • Enter your agent’s name, default language, default time zone, and GCP project, then click “Create.”

dialogflow-logout

 

Step 2: Develop the Bot-Preset Intents

Dialogflow provides access to fundamental intents like the Default Welcome Intent and Default Fallback Intent. For instances where the bot needs to welcome or respond to uncertain queries, it utilizes the Default Welcome Intent.

welcome-intent

 

Activate it by clicking the corresponding button. The ‘Training phrases’ section encompasses varied expressions grouped under the ‘Default Welcome Intent.’

create-intent

Step 3: Modifying Default Welcome Intent – Creating Custom Responses

In the ‘Responses’ section, create the welcome messages to suit your application. For instance, customize the Default Welcome response for a specific context, like a movie theatre. Ensure a human-like flow in your responses. Delete redundant messages and add a new line with a custom welcome message, such as, “Hey there! Welcome to EVR Cinemas. My name is Ticket Bot. How can I help you?”

Step 4: Creating New Intents

Expand the capabilities of your TicketBot by training it to handle common questions from new visitors. Create new intents for queries like “What are your show timings?” or “Which movies are playing during the Matinee?” Ensure clear intent naming and precise responses.

Step 5: Working with Entities, Actions, and Parameters

Move to the next level by training TicketBot to book movie tickets. Click the ‘+’ button next to ‘Entities’ to add entities like “MovieNames” and “MovieTimings.” Create an intent named “Book Ticket” and add parameters corresponding to these entities. Enable prompts for bookings by checking the “Required” field. Craft prompt messages asking users about their preferred movie and showtime.

Step 6: Add a Concluding Response

Conclude the conversation with the bot using final responses. Optionally, use the ‘$’ value in the message to extract useful information from parameters. Toggle the button at the bottom to indicate the end of the conversation.

Step 7: Integrate Dialogflow with Your Website 

Here’s a step-by-step guide to integrating Dialogflow with your website:

  • Open Dialogflow agent settings by clicking on the gear icon.
  • Navigate to the Google Cloud link mentioned in the Google project bar.
  • On the Google Cloud page, go to the Credentials section under APIs & services.
  • Locate the service account and click on edit for Dialogflow integrations.
  • At the bottom, click on ADD key, choose the Create a key option, and download the JSON key.
  • Open the website dashboard, go to Bot Integrations, select Dialogflow ES, and name your bot.
  • Upload your JSON key, add the knowledge-base ID (optional), and choose the default language.
  • Choose whether to enable chatbot to human hand-off.
  • Move to the Install section, and follow the instructions to integrate the website chat widget into your website, mobile apps, and other platforms.

Step 8: Training the Bot

Your chatbot is an intelligent algorithm with machine-learning capabilities that benefits from continuous training. This enhances its performance and corrects errors. Follow these steps:

  • Navigate to the “Training” section in the left menu.
  • Review conversations in rows of data and click on a session to view it.
  • Correct intent mismatches by refining responses.
  • Train the bot to respond to unfamiliar questions using a Fallback intent.

Example:

User: “When do you screen The Hobbit: An Unexpected Journey?”

Intent: Book ticket

User: “I don’t see the listing of the new Hobbit movie.”

Bot: Default Fallback intent

For unanswered questions, use the Default Fallback intent and include variations like:

  • “When do you screen the new Hobbit movie?”
  • “Can I book all the tickets for a particular show?”
  • “When will EVR Cinemas introduce midnight shows?”

Continue adding these questions to new intents and training the bot. The more intents you provide, the better trained your bot will be.

Congratulations on creating a TicketBot! You can now showcase it on your general website to impress your family and friends.

FAQs

Is Dialogflow free or paid?

Dialogflow pricing varies based on the edition and the requests made during the month.

Is Dialogflow API free?

No, Dialogflow API is a paid version and it is used to build conversational interfaces such as chatbots, and voice-powered apps.

What is Dialogflow used for?

Dialogflow works by converting text or audio input from users into organized data that your applications and services can comprehend. To tailor conversations for your system, you create and develop a Dialogflow agent, which functions much like a human call center agent.

What is the difference between Dialogflow and ChatGPT?

Dialogflow and ChatGPT differ in their design, purpose, and capabilities. While OpenAI’s ChatGPT is a versatile tool suitable for various purposes and can be integrated with other software programs, Google Dialogflow, although commonly used in customer service applications, is not limited to that specific use case and it is designed to be integrated with various platforms and software applications.

Also Read : Top Applications of Chatbots

Conclusion

Hope this article delved into various facets of chatbot development from constructing it using DialogFlow, and establishing connections with a Node.js server, to seamlessly integrating it into a React app. 

Mastering chatbot development is indeed crucial in the modern world, and tools like Dialogflow play a significant role in achieving this mastery. To get familiarity with the Dialogflow in real-time settings, try our hands-on labs and sandboxes.

About Pavan Gumaste

Pavan Rao is a programmer / Developer by Profession and Cloud Computing Professional by choice with in-depth knowledge in AWS, Azure, Google Cloud Platform. He helps the organisation figure out what to build, ensure successful delivery, and incorporate user learning to improve the strategy and product further.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top