Back to Blog

How to Integrate DialogFlow with Google Chat

Tellephant

Thinking about integrating Dialogflow with Google Chat? In this below video, Google Cloud shows us how to use Dialogflow, Google Chat, and a Google Sheets API to create a reliable, conversational chatbot. Watch to see step-by-step how Priyanka and Anu seamlessly create this chatbot!

What's important to note is that Tellephant and Aiyo Labs are part of the Google Cloud for StartUps program and can help your business get on Google Business Messages live and running in no time.

A full transcript of the video is below. Enjoy!

How to Integrate DialogFlow with Google Chat

[MUSIC PLAYING] 

PRIYANKA VERGADIA: Hi I'm Priyanka Vergadia, and thanks for tuning in to Deconstructing Chatbots. Today's episode is a special one, because I have invited Anu Srivastava from our Cloud ML team. Hey Anu, how are you? 

ANU SRIVASTAVA: I'm doing great. I'm really excited to be here and share some things about integrating Google Chat with DialogFlow. 

PRIYANKA VERGADIA: Well, awesome. Let's dive in. We know that DialogFlow is a natural language understanding platform that helps us design and integrate conversational experiences for mobile, web, phone, and lots of other things. And Google Chat is an intelligent messaging app within G-Suite, built for teams to make it easy to have one or more threads of communications in a virtual room. ANU SRIVASTAVA: Right. So it also has a third-party platform, an SDK, for bot integrations. And that's what I'm excited to be talking to you about today. 

PRIYANKA VERGADIA: Well, cool. What are some of the benefits of bots in Google Chat? 

ANU SRIVASTAVA: So if I'm a user, I don't really want to have to install an app for every task that I have to do. So installing apps for mobile or desktop, you can just do some of your workflows and automation in a chat room by directly messaging a bot with an app mention to get started. 

PRIYANKA VERGADIA: Right. So if I wanted to chat with you, normally when I chat, I would just say @Anu and your name would pop up and then I would start typing whatever I want to ask you. So it seems like that's exactly what you do with bots. You just type @ the name of the bot. And if you don't remember the name, it will just populate a list of names and then you can select from it, which is awesome. 

ANU SRIVASTAVA: Yeah. So to make it easy with bots, you can kind of treat bots as you would humans in the chat room. And then now you have this team memory in the chat. 

PRIYANKA VERGADIA: Awesome. So as a developer, how do I get started in setting up bots in Google Chat? 

ANU SRIVASTAVA: So let's take an example. Today we'll use a use case that comes from our sales team. Our story actually starts on a sheet. Google is a large company and it's hard to know who the right person is to contact. Our sales accounts are grouped into clusters and each cluster has accounts. And then within those accounts, we have account managers and engineers that specialize in skills like security and networking.

So it gets really complicated to figure out who the right person is to ping when you get a question, even within your department. So we have lots of spreadsheets like this used by the sales team. I have a copy of one of these sheets from one of the European teams. I have scrapped out their names and test accounts. This is test data. And instead of actual customers listed, we're using some Google products. But the setup of the sheet is the exact same. 

PRIYANKA VERGADIA: Currently, say if I'm a sales rep and I have a question about who is responsible for this particular piece of information. I would come to this sheet and look for my answers, right? 

ANU SRIVASTAVA: Right. So for example, let's say I get a question like, who can advise on security best practices for the YouTube account? First, I would want to find the engineer in that cluster and then figure out who is on security. Or, maybe I actually need to connect to someone who knows the account info. So I would connect to the account manager. Let's say I need networking for analytics. Then I would check here. 

PRIYANKA VERGADIA: Well, this works fine. But if you're on the go and you're just looking for this information, you really don't want to look for a sheet URL and then try and find that information within it, because that can be too hard. 

ANU SRIVASTAVA: Right. And it would be great if I could just get this information in chat. Most likely, what I'm going to do next is open a chat tab to talk to whoever I find in the sheet. And that's where this bot comes in. I don't want to have to open a new tab and wait for it to load. Reducing context switching is a key point in using bots. 

PRIYANKA VERGADIA: Right, and then slow Chrome tabs when I have 1,000 of them open. 

ANU SRIVASTAVA: Right. 

PRIYANKA VERGADIA: That would be cool, but this sheet looks pretty complicated. How are we going to be able to extract all this information into things that we need?

ANU SRIVASTAVA: I'm glad you asked. So we'll actually be using the Sheets API. And you're right, this is pretty complicated. It's designed for human consumption. It's not really a database. But we can work around that. So to answer a query, we need to know three pieces of information. Number one, the account name, so we can't get the cluster. Number two, the speciality. And last but not least, the role type. 

PRIYANKA VERGADIA: Oh, I see where this is going. Usually when you create bots, or chat applications, you need the pieces of information that act as your input. So in this case, these three pieces of information become your input to the bot. 

ANU SRIVASTAVA: Exactly. So I could write a basic bot that expects these three inputs in a certain order, but it would be unnatural and difficult to use. As a user, I'd have to remember the exact order and I'd always have to spell everything right, which I definitely don't do. And we know that with technology, if it's too hard to use, people aren't going to use it. So this is where DialogFlow comes in. 

PRIYANKA VERGADIA: Yep. And that is what DialogFlow is great at doing, because it's powered with natural language understanding. And it helps understand normal human words. And it's OK to make mistakes. It's OK to ask not in order sometimes, and it would still be able to understand what you're saying. 

ANU SRIVASTAVA: Yes. So, I'm going to show this to you in reverse. Let's take a look at the bot, and then we'll break it down on how we built it. So let's do a couple test queries. 

PRIYANKA VERGADIA: Say I want to know who is on Gmail for data management. 

ANU SRIVASTAVA: Great. And now we see the follow-up intent, because you need one more piece of information. Awesome. So now let's actually break it down. First, we need to define the entities, then we'll make the intents, and then we'll implement fulfillment to make this all work. 

PRIYANKA VERGADIA: Well, if you've watched previous episodes of this series, these concepts should be familiar. But if not, then the playlist is linked below. Go check them out. 

ANU SRIVASTAVA: Step one, defining the entities. Let's look at the specialities that we have in this table, which will group together similar words. I've defined the synonyms and enabled fuzzy matching to be generous with the input. Meaning, if I make a typo, which I definitely will, it will still connect to the same entity. The synonyms are really key to making the system robust. 

PRIYANKA VERGADIA: Right. And say in this case, if you look down into G-Suite, we can see that they are all grouped together, like Docs and Gmail. So now let's define the intents. 

ANU SRIVASTAVA: The intent is a category of what the user is asking for, their intentions. So you always want to have a welcome intent. And it's best practice to give the user some instructions on how to interact with your bot. So when I first add the bot to this room, this is where the response comes from. 

PRIYANKA VERGADIA: And then now we want to know what happens with those intents, or when those intents are triggered. So, the actions and the parameters for those intents. 

ANU SRIVASTAVA: Right. So we've defined the intent lookup Google. So this is where all the good stuff goes. Let's go ahead and put those entities into this intent. They are all required for this intent to be fulfilled. If a user forgets one of them, I define a prompt to get it from the user, as we saw earlier. So if they forget a piece of information, they'll see this prompting question. 

PRIYANKA VERGADIA: Got it. In our example use case, they forgot the account, so they see the question to input the account information. 

ANU SRIVASTAVA: Yep. 

PRIYANKA VERGADIA: Cool. Different people talk differently, so they will ask the question in a different way. How do I train the bot so that all these examples are incorporated? 

ANU SRIVASTAVA: So that's where step four comes in, training phrases. In my opinion, this is the fun part. DialogFlow uses a pre-trained model, but we can add our own specific questions for this bot. So I've added these as training data, and you can see that it'll detect the parameters I have just told it about. 

PRIYANKA VERGADIA: So once we put all that information into the training phrases, how do we actually know that it's all working? How can we test this? 

ANU SRIVASTAVA: So in the console, you can actually test it out exactly how it would work on Google Assistant. So I know that we're building ours for G-Suite, but I will touch on how you can support multiple platforms just right out of the box in a bit. 

PRIYANKA VERGADIA: Now, let's see how this actually connects to the back end. In this case, the Sheets API. We would have to go and create a webhook. How do we do that? 

ANU SRIVASTAVA: Let me just go ahead and show you step five, the fulfillment code. So we can look at this Node.js code, which is using those libraries we're talking about. So like the Sheets API, the chat API, all of these in the package, which has all of these libraries. 

PRIYANKA VERGADIA: Now, how can we add the images and buttons and other types of widgets if they are needed for the interaction to work? 

ANU SRIVASTAVA: Yeah, this is how we make it really rich. We just construct these with JSON how we want the chat cards to look and then push it to the DialogFlow agent. 

PRIYANKA VERGADIA: We want to make this work with Google Chat. So how do we make that integration? 

ANU SRIVASTAVA: So here in the integration section, chat is actually enabled by default. But let's say I wanted it to work with multiple platforms. I could just select some of the other boxes in this section. 

PRIYANKA VERGADIA: So it's that simple. It was really just a click of the button to actually enable it, once we got the bot to work. This has been awesome, Anu. Thank you so much for showing how it's done. For anyone who wants to try this out, Anu has the code up on GitHub, which we have linked below. 

ANU SRIVASTAVA: And if you'd like to dive deeper, or have any questions, leave us a comment or tweet at us. 

ANU AND PRIYANKA: Bye. 

[MUSIC PLAYING]


Have more questions?

Just reach out, we’re always around to answer any questions.
Contact Us

More from the Blog

Fully Utilize Instagram API To Enhance Your Business.

Fully Utilize Instagram API To Enhance Your Business.

With the new Instagram's Messenger API, you can now iterate Instagram messaging with apps you’re already using, and offer more meaningful conversations to your customers, and grow sales even further using Instagram.

Read Story
Integrate HubSpot With WhatsApp

Integrate HubSpot With WhatsApp

Integrate your WhatsApp Business Account with hubspot and automate your CRM processes, like updating customer information and data, and reaching out to customers. It helps you streamline your CRM workflow, and eases processes. 

Read Story
Integrate Salesforce With WhatsApp

Integrate Salesforce With WhatsApp

With Salesforce’s integration with WhatsApp’s business APIs, you can automate list updates and customer outreach. It’s an effective way to streamline your CRM process, automate customer data collection, and reach out to your customers. 

Read Story

Get started today with a free trial!

Create an account
Sign Up
Tellephant Product