How to build a chatbot with Dialog flow | Chapter 3— Dialogs for Conversations
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.
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 “#flight_context.date”
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:
- Book a flight with all necessary inputs.
- Book a room
- 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
- 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
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
- Dialogs can be linear or non-linear
* 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 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!