Dialogflow is a framework which provides NLP (Natural language processing) to build conversational interfaces for websites, mobile applications or IOT devices. Learn about its intricacies below.

by Shwetha Talapalli, Software Engineer, YML

Architecture

Below is the detailed working of the dialogflow

  1. A user sends a text/voice message to a device.
  2. The device transfers this message to Dialogflow.
  3. The message is processed and matched to a corresponding intent (Intent is an action that has to be taken in response to a user’s request. We will learn more about this later)
  4. The corresponding action to the matched intent is taken. Webhook is called if enabled, local saved response is returned otherwise. (Webhook is a HTTP push API that makes a request to your server and delivers data as it happens)
  5. Webhook calls external API.
  6. The external API queries external DB to fetch related information.
  7. The processed information is sent back to the webhook.
  8. Webhook sends formatted response to the intent.
  9. Intent sends webhook information to Dialogflow.
  10. The data is sent to the output device.
  11. The user gets a response in the form of text/voice.

Get Your Feet Wet

The best way to truly understand something is to try one. There are number of examples out there. Check the simple example below for quick reference.

I am taking an example of vehicle doorstep service for understanding. I want to get my vehicle repair done and my conversation with the bot goes like this.

Me: Hi, I need to get my vehicle repair done this Saturday. 
Bot: Sure. I will help you with that. Can you share me your address details?
Me: XYZ.
Bot: OK. What time would you prefer for pickup?
Me: Anytime. I prefer in the evenings.
Bot: Shall I confirm for Saturday 4 O'clock in the evening.
Me: Yes please.
Bot: Your booking is confirmed and a person will reach the destination on Saturday 4 O'clock for vehicle pickup.
Bot: Please feel free to call 1111-1111 for any queries.
Me: Thanks!
Bot: Anytime

Components

  • Agent :- Module that handles end-users conversations which incorporates Natural language understanding to understand what the user has meant and what action has to be carried out accordingly. Agents manage conversations with the user through intent, entities, contexts and other building blocks.
Fig 1.1 - Agent Creation
  • Intent :- Intent tells the action that has to be performed for the user search/request. For a conversation, you may have to create a set of intents. When user searches, agent finds out the intention of the user with the help of trained phrases and transfers the request to the best matched intent.
Fig 2.1 - Intent Creation -Training Phrases

BookVehiclePickup is our intent here. We have added some training phrases for now. You can add more if needed.

Fig 2.2 - Intent Creation — Action And Parameters

Some parameters like date, time, date-period etc are already system defined. You can also create your own custom entity for your other parameters if required.

Fig 2.2.1 - Action And Parameters — Prompt Values

Add the text under prompts for the message user should be prompted with for each parameter.

Fig 2.3 - Intent Creation — Responses

Add the text response with the message that your bot should respond with. This is a static response. Your bot will respond with the same response whenever this intent matched.

  • Fulfillment : Fulfillment is the code to take some action depending on the user’s request. If you want your bot to send dynamic response based on user queries, you can enable fulfillment for the intent. If there is no fulfillment enabled for matched intent, bot will respond with static response configured. If user request matches the intent with fulfillment enabled, request is sent to web-hook with matched intent’s information. Our service can perform required actions and respond back.
Fig 2.4- Intent Creation — Enable fulfillment

Enable webhook call for the created intent. Request will be processed by our service either via web-hook or inline editor.

a) Inline editor: You can use inline editor to write your functions than having your own service which gets deployed in firebase.

b) Webhook: Webhook is the HTTP request that is called along with intent information when an intent is matched with fulfillment enabled.

You can use ngrok (tunneling tool that establishes secure tunnels from a public endpoint to your locally running network) for calling the service. Setup webhook in dialogflow by entering the webhook url generated by ngrok and test.

Make it work, make it right and make it fast. Have fun and happy developing 🙂