Hands-on Chatbots with Google Dialogflow
Course Outline
Module 1: The Big Picture Module 3: Dialogs in DialogFlow
Bots, DialogFlow Linear & Non-linear Dialogs
Voice and free-flowing chat Managing conversation flow
Module 2: Interaction models in ChatBots Module 4: Fulfillment & Deployment
Agents,Intents,Entities,Contexts Webhooks & Integrations
The Building Blocks of DialogFlow External APIs for fulfillment &Deploying DialogFlow apps
Overview
Machine learning has made possible bots which can conduct
intelligent conversations
Technologies underlying bots are complex but platforms make
building these bots simple
Google’s Dialogflow (formerly api.ai) offers an easy way to build
sophisticated chatbots
Where Would You Use Chatbots?
A chatbot is a program that can conduct an
intelligent conversation
Convincingly simulate human behavior and
pass the Turing test
Help Navigating a Site
Can’t find what you’re Chat window pops up - just
looking for? ask questions!
Help Navigating a Site
Chat is usually powered by a
bot
Customer Support for Your Order
Order not received from your Call customer support on the
favorite e-commerce site? phone
Customer Support for Your Order
Order not received from your Chat on the site, track your order
favorite e-commerce site? using an intelligent bot
Chatbots for Business
Weather bot
Grocery bot
News bot
Personal finance bot
Shopping bot
Introducing Dialogflow
Types of Chatbots
Rule Based AI Based
Basic, know only about rules that have been pre- Intelligent, learns from conversations using ML
programmed techniques
Types of Chatbots
Rule Based AI Based
Basic, know only about rules that have been pre- Intelligent, learns from conversations using ML
programmed techniques
A Little History
2011: Speaktoit developed an intelligent personal
assistant for mobile phones
2014: Speaktoit released api.ai to third party
developers
2016: Google buys Speaktoit to to power Google
Assistant
2017: api.ai is renamed to Dialogflow
Dialogflow is Sophisticated
Build natural, rich conversations with an intuitive UI
Uses machine learning to understand what users are
saying
Each ML model is unique to an individual user’s bot
Dialogflow is Cutting Edge
Supports 14+ languages
Develop in 16 programming languages
SDKs to work with web apps, mobile apps and
wearables
Integrates with 14 major chat platforms such as
Slack, Cortana, Alexa, Facebook etc
The Big Picture
Flow of Conversation
User Expressions
Conversations snippets that a user
might use to ask the bot questions
Dialogflow Integrated with Apps
Slack, Kik, Viber, Twilio, Skype,
Google Assistant
Agent
A module which incorporates Natural
Language Processing to understand
what the user meant
Agent
Transforms user requests to
actionable data
Intent
Maps user requests to an
intent
Intent
The intent determines action
taken by code
Fulfillment
The code executes to fulfill the
intent of the user
Response
The response in the form of a
text message is sent back to the
user
Response
The response in the form of a
text message is sent back to the
user
Response
The response in the form of a
text message is sent back to the
user
Response
The response in the form of a
text message is sent back to the
user
Flow of Conversation
Flow of Conversation
Flow of Conversation
Simple intuitive UI to configure
the agents
Flow of Conversation
Only write code for fulfillment
Using the Building Blocks of Chatbots
Building a chatbot using DialogFlow
Create Agent Define Entities
Custom or pre-existing sample Entities are user parameters
TripPlanner sedan or hatchback? suite or single?
Specify Intents User says
Intents are actions user wishes to accomplish Training data for NLP ML models
Welcome, Fallback, BookCars, BookRooms “Hey! Get me a sedan for tomorrow”
Agents
Flow of Conversation
Agent
A module which incorporates Natural
Language Processing to understand
what the user meant
Agent
Transforms user requests to
actionable data
Agents manage conversation flow with
the user using intents, entities, contexts
and other building blocks
Demo
Build an agent which helps plan business trips
Intents
Flow of Conversation
Intent
Intents are configured by
developers and used to determine
the action taken by code
Intent maps what a user says and what
your software should execute
Default Intents
Welcome Fallback
Greet the user, exchange pleasantries (partially Default or fall through intent when no others
configured) match (fully configured)
Intent Sections
User says Action Response Context
Custom Intents
BookRooms BookCars
Intents
Manage Conversation flow in DialogFlow chatbots
Contexts & Follow-ups Non-Linear Dialogs
Contexts represent the current May have several branches, depending on users’
context of a user's request. answers
“Get me more of that?” A customer satisfaction survey for a hotel
Linear Dialogs
Collect the information necessary to complete
the required action.
Slot filling using required parameters and prompts
A Conversation
Book a room for me please
Which city do you plan to visit?
Bangalore
What date should I book for?
This Friday
Any room preference?
A
double room
Slots to be Filled
Book a room for me please
Which city do you plan to visit?
Bangalore
What date should I book for?
This Friday
Any room preference?
A
double room
Parameter values
Book a room for me please
Which city do you plan to visit?
Bangalore
What date should I book for?
This Friday
Any room preference?
A
double room
Entities are used to extract parameter
values from user queries
Entities
Book a room for me please
Which city do you plan to visit?
Bangalore
What date should I book for?
This Friday
Any room preference?
A
double room
Entities
city
All the information we need in a user query will
date have a corresponding entity
room
Type of Data Expected
city
System entities
date
room
} Developer entity
Entities
city
User entities are those that can be defined at a
date session level i.e. a user’s playlist
room
BookRooms Intent
City Date Room type
BookCars Intent
City Date Car type
A Conversation
Book a room for me please
Which city do you plan to visit?
Bangalore
What date should I book for?
This Friday
Any room preference?
A
double room
Prompts
Book a room for me please
Which city do you plan to visit?
Bangalore
What date should I book for?
This Friday
Any room preference?
A
double room
Linear Dialogs
A Conversation
Book a room for me please
Which city do you plan to visit?
Bangalore
What date should I book for?
This Friday
Any room preference?
A
double room
A Conversation
Book a room for me please
Which city do you plan to visit?
This dialog is entirely
Bangalore
configured within a single
intent What date should I book for?
This Friday
Any room preference?
A
double room
Collect information required to complete
the action
May invoke one or more intents
A Conversation
Book a queen room for me in Bangalore
tomorrow
Done.
Room booked!
Book a car too
…..
A Conversation
Book a queen room for me in Bangalore BookRooms
tomorrow
intent
Done.
Room booked!
Book a car too BookCars
intent
…..
Context
BookRooms BookCars
Book a
Book a
car
room
…
Done. Room booked!
These are not 2 separate conversations - the car booking is an
extension of the rooms conversation
Context
BookRooms BookCars
Book a
Book a
car
room
…
Done. Room booked!
Information relevant to the second conversation needs to flow through
from the first
Context
BookRooms BookCars
Date
Non-linear Dialog
Non-linear dialogs branch to the next
intent based on responses from the
previous intent
Customer Satisfaction Survey
Location was very
The facilities were bad
good
Would you like to offer
feedback on the
hotel?
The location was The facilities were
terrible great
Customer Satisfaction Survey
Location was very
The facilities were bad
good
Would you like to offer
feedback on the
hotel?
The location was The facilities were
terrible great
Customer Satisfaction Survey
Location was very
The facilities were bad
good
Would you like to offer
feedback on the
hotel?
The location was The facilities were
terrible great
Customer Satisfaction Survey
Location was very
The facilities were bad
good
Would you like to offer
feedback on the
hotel?
The location was The facilities were
terrible great
Customer Satisfaction Survey
Location was very
The facilities were bad
good
Would you like to offer
feedback on the
hotel?
The location was The facilities were
terrible great
Customer Satisfaction Survey
Location was very
The facilities were bad
good
Would you like to offer
feedback on the
hotel?
The location was The facilities were
terrible great
Customer Satisfaction Survey
location-
feedback Location was very
The facilities were bad
good
Would you like to offer
feedback on the
hotel?
The location was The facilities were
location- terrible great
feedback
Customer Satisfaction Survey
facilities-
feedback
Location was very
The facilities were bad
good
Would you like to offer
feedback on the
hotel?
The location was The facilities were
terrible great
facilities-
feedback
Customer Satisfaction Survey
Location was very
The facilities were bad
good
Would you like to offer
feedback on the
hotel?
The location was The facilities were
terrible great
Customer Satisfaction Survey
Location was very
The facilities were bad
good
Would you like to offer
feedback on the
hotel?
The location was The facilities were
terrible great
Fulfillment and Deployment using External APIs
Fulfilling Intents using External APIs
In DialogFlow: Build a Bot In Github: Create a repository In DialogFlow: Link Webhook to Intent
Set up intents, entities, contexts Upload webhook Enable Webhooks
Already done Create procfile & requirements.txt Define fulfillment model in intent, test in console.
In Local Machine: Create a webhook 1n Heroku: Deploy Webapp
Integrate with Slack!
Build a flask app to fulfill intents Connect to GitHub
Can chat with the bot in Slack.
Detect intent, Extract parameters from intent request JSON, Set Buildpack, Build branch, Deploy and
Invoke Weather API, Construct Response get address
The Slack-DialogFlow Handshake
In DialogFlow: Activate Slack Integration In Slack: Add app to workspace
Get Event Request and OAuth URL Manage distributions of Slack app
Need to paste in Slack credentials Bot comes online in Slack
In Slack: Create a Slack app with a Bot user 1n Slack: Link DialogFlow URLs Use the app!
Get credentials for OAuth Event Requests and OAuth URLs Can chat with the Bot
Slack app with Bot user to chat with Also enable event subscription