MARGO

News

A brief introduction to Chatbots with Dialogflow

Discover how do chatbots work and how to easily create one with Dialogflow

By Hao Chen Data Scientist

07/05/2018

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:

  1. PriceIf 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

     

  2. 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.

3. 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:

  1. A user sends a text/voice message to a device or an App
  2. The App/Device transfers the message to Dialogflow
  3. The message is categorized and matched to a corresponding intent (Intents are defined manually by developers in Dialogflow)
  4. We define following actions for each intent in the fulfillment (Webhook).
  5. When a certain intent is found by Dialogflow, the webhook will use external APIs to find a response in external data bases.
  6. The external data bases send back required information to the webhook.
  7. Webhook sends formatted response to the intent.
  8. Intent generates actionable data acoording to different channels.
  9. The actionable data go to output Apps/Devices.
  10. The user gets a text/image/voice response.

 

How to build your first chatbot?

Create an agent

  1. If you don’t already have a Dialogflow account, sign up. If you have an account, login.
  2. Click on Create Agent in the left navigation and fill in the fields.
  3. 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:

  1. 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.
  2. 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.
  3. 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”.

  4. Click Save

 

Add response

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.

  1. 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 $date
    • I don’t know the weather for $date in $geo-city but I hope it’s nice!

    You can see the last two responses reference entities by their value placeholders. $date will insert the date from the request, and $geo-city will 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.

  2. Click Save

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

Basic Fulfillment(Webhook)

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/

 

Conclusion

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.

 

References

  1. Dialogflow Quick Starts
  2. DialogFlow(formerly API.AI): Let’s create a Movie ChatBot in minutes

 

 


By Hao Chen Data Scientist
Chatbot
DataScience
Dialogflow
Machine Learning
NLP
News

Tutorial - Artificial Intelligence: from prototype to deployment

In this article we present a practical case study for building an AI model and deploying it in a mobile application, all in less than an hour.

02/05/2019 Discover 
News

Kaggle Challenge: TalkingData AdTracking Fraud Detection

TalkingData, China’s largest independent big data service platform, covers over 70% of active mobile devices nationwide. Their current approach to prevent click fraud for app developers is to measure the journey of a user’s click across their portfolio, and flag IP addresses who produce lots of clicks, but never end up installing apps. While successful, they want to always be one step ahead of fraudsters and have turned to the Kaggle community for help in further developing their solution.

31/05/2018 Discover 
News

Data Science applied to the retail industry: 10 essential use cases

Data Science is having an increasing impact on business models in all industries, including retail. According to IBM, 62% of retailers say the use of Big Data techniques gives them a serious competitive advantage. Knowing what your customer wants and when, is today at your fingertips thanks to data science. You just need the right tools and the right processes. We present in this article 10 essential applications of data science in the field of retail.

31/05/2018 Discover 
News

Lamport clocks and the pattern of the Idempotent Producer (Kafka)

Do you know the Lamport clocks? Devoxx France 2018 was the opportunity, during the very interesting talk of DuyHai DOAN , to discover or rediscover this algorithm formalized by Leslie Lamport in 1978, more than ever used today in the field of distributed systems, and which would have inspired the Kafka developers in the implementation of the pattern of Idempotent Producer .

23/05/2018 Discover 
News

Establishment of a centralised log management platform with the Elastic suite

The volume of data generated by our systems and applications continues to grow, resulting in the proliferation of data centers and data storage systems.  In the face of this data explosion and the investment in skills and resources, decision-makers need sophisticated analysis and sophisticated dashboards to help them manage their systems and customers.

14/05/2018 Discover 
News

A Gentle Introduction to Reinforcement Learning

Reinforcement learning is considered as the science of decision-making: trying to understand the optimal way to make decisions. Nowadays, it is applied in many different fields and has achieved many distinguished accomplishments.

20/03/2018 Discover