How to build a chatbot with Dialog flow | Chapter 3— Dialogs for Conversations

Moses Sam Paul
Jul 24, 2018 · 7 min read

In the last chapter we created a basic bot that can help us book flights, rooms and cars but did you notice that each time we had to give the city name and the date ..isn’t that a little annoying ? Right.

So in this chapter we will look at dialogs and how it can help us make the bot a little smarter by retaining relevant information from the previous conversations with the users.

Series Content:

Chapter 1: Basic Gyaan about Chatbots and setting up the dialog flow environment

Chapter 2: Understanding the building blocks of Dialogflow

Chapter 3: Using linear, followup and non-linear dialogs to create a “TripPlanner” bot

Chapter 4: We created a new bot “StockTracker” bot to pull data from an external site through fulfilment and revert the result to the user

Chapter 5: Connect the “StockTracker” Chatbot with Slack

Using Dialogs for Managing Conversations

  • Linear Dialogs can span a single intent or multiple intents
  • Flow Predictably to elicit information needed to complete actions
  • Contexts allow information sharing leading to more natural conversations
  • Non-linear dialogs help branch to intents based on user responses

…book a room — when ? where? type ? these are linear dialogs to collect information from the user to fulfill

Context: lets us use linear dialogs that can be used across multiple intents

Now an example of how linear dialogs can flow between multiple intents.

Within Book Flights intent…create “flight_context” as an output context. the Number 5 represents the lifespan of this context. By default it’s for 5 requests.

Go to BookRooms intent and add “flight_context” as the input context

Go to BookCars intent and add “flight_context” as the input context

Within BookRooms intent..once the input context is it, we gotta assign the default values for parameters.

set deafult value for date as “”


Remember geo-city1 is the destination city…go to BookFlight intent and check out the names.

similarly set default values in the bookCars intent as well.

Let’s test out the agent:

  1. Book a flight with all necessary inputs.
  2. Book a room
  3. Book a car (car type alone has to be specified)

Booking a flight with all inputs.

See “flight_context” being setup under contexts!

2. Book a room without specifying any date or city

great, see just saying “book a room” has resulted in a room booked for the destination city and date from the bookFlights intent through the flight_context.

3. Book a car

Book a car — user expression just asks for the type of car

as you can see in the parameter the rest (city, date) are retained from the “flight_context” input context.

Ok, don’t jump off your horses….the issue here is you always need to start with the Bookflight intent…as in, an user has to first book a flight and then a room / car this is not ideal right ?

To solve this, we have the followup intent.

Linear Dialog using a Followup Intent

  1. Clear all configuration settings…the “flight_context” has to be removed and the default values have to be removed form both “bookRooms” & “bookCars” intents. Leave it in the “bookFlights” intent.

2. Create a custom follow-up intent

Set the input context as flight_context which is the output context of bookFlights intent, remember?

set few user expressions too…

Make sure you manually add the geocity &date parameters

set the default response too…

So a normal book a room would trigger the BookRooms intent.. see below

booking a flight and then using the same expression would trigger the followup intent

Till now we have seen only linear dialogs…but real-world conversations aren’t linear…don’t trust me? try getting into an argument with your girl :P

Non-linear dialogs branch to the next intent based on responses from the previous intent,


customer satisfaction survey

Location Feedback:

Facilities Feedback

Configuration: create a new feedback intent — set output context, few training phrases and the text reponse

Set a new entity called rating

New Intent: Location- Good

New Intent : Location — Bad

New Intent: Facilitites — Good

New Intent : Facilities — Bad

Overall Intents:

Summary :

  • Dialogs can be linear or non-linear

Linear Dialogs

* Linear Dialogs can span single or multiple intents
* Primary reason of Linear Dialogs is to capture information from the user to complete actions
* Context allows information sharing to simulate a more natural conversations

Non-Linear Dialogs

* Non-linear dialogs help branch to intents based on user responses

So, our bot can now manage different types of dialogs and might look smarter…but till now we have not connected with an external site to pul data. So in the next chapter, we shall see how we can create one more bot / Agent (StockTracker) that will connect to an external site and get us the data real-time, no more pre-defined text responses. We are entering the fulfilment world!

This story is published in The Startup, Medium’s largest entrepreneurship publication followed by 351,974+ people.

Subscribe to receive our top stories here.

The Startup

Medium's largest active publication, followed by +566K people. Follow to join our community.

Moses Sam Paul

Written by

Bachelor: Information Technology; Master: Public Policy; Now: Growing; Building #SkillsChain; Curating @OpenHouse332

The Startup

Medium's largest active publication, followed by +566K people. Follow to join our community.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade