Developers & Practitioners
Integrating Dialogflow with Google Chat
In today's world, where online collaborative work is crucial and maintaining productivity is key, chatbots have an important role to play. Why chatbots? Workers frequently need to incorporate information from external sources in their communications, and chatbots can help them find that information all in one place. In this post we'll walk you through a bot that was inspired by a real use case here at Google.
In large companies such as Google, it can be difficult to find out which person is responsible for a specific product area. When customer teams have a question they often have to go through many ad hoc trackers such as the one here in Sheets (sample scrubbed data) to find answers.
When you are on the go a lot, this gets even harder, especially if you don't remember the Sheets URL and how to use it to find your answer. Instead of sifting through a spreadsheet, what if you could just send a chat message to see who to contact for networking or security expertise? That’s where the integration between Dialogflow and Google Chat comes in! It helps reduce context switching for users, because they can ask their questions right within Google Chat, addressing a bot built in Dialogflow that integrates with the Sheets API to find answers. Let’s see how it works!
If you’d rather watch than read, we share the entire process in this video:
How does it work?
When a user asks a question in Google Chat, the bot that is initiated integrates with Dialogflow to facilitate natural conversations. Dialogflow, in turn, integrates with a backend database or Sheets (as shown in the image) via a Cloud Functions fulfillment.
Extracting the information from Google Sheets
To extract the information from Sheets we first need to know exactly what information is relevant to fulfill a request. After identifying the pieces of information we need, we use the Sheets API to extract them.
Defining the input phrases
While it would be easier to write a basic bot that requires the input to be formatted in a predetermined order, such a bot would be difficult to use. Users would have to remember the order and always spell everything correctly. And if a tool is too hard to use, people aren't going to use it.
The key to chatbot adoption is usability, and that means the ability to handle phrases that occur in natural conversation, like these:
- "Who is on Gmail for data management?"
- "I would like to know the data management guru "
- "Tell me who is the data management specialist"
This is where Dialogflow comes in. Dialogflow is a natural language understanding platform that simplifies the design and integration of conversational user experiences for mobile apps, web apps, bots, and more.
We built our bot in three easy steps, which should look familiar to you if you've completed the Deconstructing Chatbots video series.
Step 1: Define the entities
Dialogflow uses models trained on natural conversation. Before we can use these models, however, our bot needs to know the key phrases in our context, such as the role types, skills, and account names (e.g., Account Specialist, Gmail, and Security).
Step 2: Configure the intents
An intent is essentially the user's question. This is where we define how to use the entities we just created by defining Actions and Parameters. When we add the bot to a room, the intent is where the response comes from.
Actions and Parameters
The entities you define are used in configuring your actions and parameters. In this case, Roles, Skills, and Accounts are all required parameters for this intent to be fulfilled (and the user can provide these in any order they like). If a user forgets one, we define a prompt to get it from the user.
Because different people talk differently, we use training phrases to provide different examples of user requests. Dialogflow uses a pretrained NLP model, and these training phrases are the realistic questions that help train a specific model for our use case.
Step 3: Set up fulfillment code
Fulfillment is where we glue everything together, connecting all the APIs in a Node.js Firebase function. In this case, we use the Sheets API but you can connect to any backend you choose. Refer to the sample code for details.
Dialogflow integrates with many popular conversation platforms like Google Chat, Google Assistant, Slack, and more. Direct end-user interactions are handled for you, so you can focus on building your agent. Each integration handles end-user interactions in a platform-specific way, so see the documentation for your integration platform for details.
Building a chatbot that integrates Google Chat, Dialogflow, and Sheets (or another data source) is straightforward. For more details, watch our Integrate Dialogflow with Google Chat video, where we talk in more depth about the process, and check out the full source code on GitHub.
Want to learn more about building chat and voice applications using Dialogflow? We’ve created an entire video series on Deconstructing Chatbots that will take you from zero to hero in no time!