Nowadays, I'm working on a Chatbot project with Google Dialogflow. In this article, I will present some notions about Dialogflow and Chatbots. Then, I will talk about how to create a simple Chatbot with Dialogflow Platform.
What is Dialogflow?
According to Wikipedia:
Dialogflow (formerly Api.ai, Speaktoit) is a Google-owned developer of human–computer interaction technologies based on natural language conversations. The company is best known for creating the Assistant (by Speaktoit), a virtual buddy for Android, iOS, and Windows Phone smartphones that performs tasks and answers users' question in a natural language. Speaktoit has also created a natural language processing engine that incorporates conversation context like dialogue history, location and user preferences.
DialogFlow is quite a good choice to learn how to create Chatbots that you can then integrate them into your own websites or Apps.
Why choose Dialogflow?
There are several reasons for choosing Dialogflow:
If you just want to learn building a Chatbot or you don't have many users, a Standard Edition is totally free. As you can see below
Multi-channel easy integration
Dialogflos provides one-click integrations to most popular messaging Apps like Facebook Messenger, Slack, Twitter, Kik, Line, Skype, Telegram, Twilio and Viber. Even to some voice assistants like Google Assistant, Amazon Alexa and Microsoft Cortana.
Natural Language Processing(NLP)
Compared to some platforms which works on predefined questions like Chatfuel, Dialogflow can offer better user experience with NLP. DialogFlow Agents are pretty good at NLP.
How do Chatbots work?
There are detailed steps:
- A user sends a text/voice message to a device or an App
- The App/Device transfers the message to Dialogflow
- The message is categorized and matched to a corresponding intent (Intents are defined manually by developers in Dialogflow)
- We define following actions for each intent in the fulfillment (Webhook).
- When a certain intent is found by Dialogflow, the webhook will use external APIs to find a response in external data bases.
- The external data bases send back required information to the webhook.
- Webhook sends formatted response to the intent.
- Intent generates actionable data acoording to different channels.
- The actionable data go to output Apps/Devices.
- The user gets a text/image/voice response.
How to build your first chatbot?
Create an agent
- If you don't already have a Dialogflow account, sign up. If you have an account, login.
- Click on Create Agent in the left navigation and fill in the fields.
- Give a name and set a language to your agent. Then, click the Save button.
Create an intent
An intent maps what a user says with what your agent does. This first intent will cover when the user asks for the weather.
To create an intent:
Click on the plus icon add next to Intents. You will notice some default intents are already in your agent. Just leave them be for now.
Enter a name for your intent. This can be whatever you'd like, but it should be intuitive for what the intent is going to accomplish.
In the Training Phrases section, enter examples of what you might expect a user to ask for. Since you're creating a weather agent, you want to include questions about locations and different times. The more examples you provide, the more ways a user can ask a question and the agent will understand.
Enter these examples:
- What is the weather like
- What is the weather supposed to be
- Weather forecast
- What is the weather today
- Weather for tomorrow
- Weather forecast in San Francisco tomorrow
In the last three examples you'll notice the words today and tomorrow are highlighted with one color, and San Francisco is highlighted with another. This means they were annotated as parameters that are assigned to existing date and city system entities. These date and city parameters allow Dialogflow to understand other dates and cities the user may say, and not just "today", "tomorrow", and "San Francisco".
Now you'll add basic responses to the intent so the agent doesn't just sit there in awkward silence. As mentioned before, responses added to an intent don't use external information. So this will only address the information the agent gathered from the user's request.
If you've navigated away from the "weather" intent, return to it by clicking on Intents and then the "weather" intent.
In the same way you entered the Training Phrases, add the lines of text below in the Response section:
- Sorry I don't know the weather
- I'm not sure about the weather on
- I don't know the weather for
$geo-citybut I hope it's nice!
You can see the last two responses reference entities by their value placeholders.
$datewill insert the date from the request, and
$geo-citywill insert the city.
When the agent responds, it takes into account the parameter values gathered and will use a reply that includes those values it picked up. For example, if the request only includes a date, the agent will use the second response from the list.
Try it out
In the console on the right, type in a request. The request should be a little different than the examples you provided in the Training Phrases section. This can be something like "How's the weather in Denver tomorrow". After you type the request, hit "Enter/Return".
- Response - shows an appropriate response from the ones provided
- The response chosen is based off of the values you provide in the query (e.g. By providing only the date, the agent should respond with the option that only includes the date)
- Intent - weather again a successful trigger of the intent
- Parameter - the values you provided in your query, should be reflected in the appropriate response
Depending on your need, you can define custom Webhook to use external APIs and get extra data from external databases. A webhook can be written in Python and Node.js. It can be held in cloud servers like Heroku, AWS and Google Cloud Platform, and local servers. Please choose your favorite programing language and server: https://dialogflow.com/docs/getting-started/basic-fulfillment-conversation
Integration to your channels
Dialogflos provides one-click integrations to most popular messaging Apps and voice assistants. Integrations can be done within a few seconds.You can choose your favorite channels and follow the official integration tutorial on the Dialogflow website. Please see: https://dialogflow.com/docs/integrations/
In this article, you have seen what is Dialogflow, some advantages of choosing this platform, how a Chatbot works within Dialogflow and how to create your first Chatbot. Thanks for your reading. Do not hesitate to contact me if there is any problem.