RASA - Google Chat integration
Tags: rasa, chatbot, nlp, ai
Published: 2021-08-09 17:22:55

In a [previous article](https://dev.to/petr7555/rasa-messaging-channels-4c2k), we saw how we can integrate a Rasa chatbot with Twilio messaging channel. In this article, I will show you how to integrate the chatbot with another messaging channel – Google Chat.

## Who can use Google Chat
Google Chat (previously called Google Hangouts Chat) is Google's paid team chat service, provided only as part of Google Workspace. This means regular Google account is not enough, you have to be inside a Google Workspace.
Furthermore, in order to add a chatbot to Google Chat, you have to be an admin of that workspace.

## Creating a Google Workspace
First, let's create a new workspace. To be able to create a new Google Workspace, you need to own a domain. You either already have one or you can purchase it. 
Go to https://workspace.google.com/ and click **Get started**. Fill in the business name, number of employees, country and your contact info (follow the Google Workspace setup wizard). 
Enter your domain name (e.g. `petrjanik.com`, but it must be yours). Complete the rest of the setup wizard.

Next, sign in to the newly created account. You will be prompted to select a payment plan. Google Workspace is a paid service, but it offers 14 days free trial, which will be enough for this experimental Rasa integration. Click **Next**. You will now need to fill in your address and payment method and details. You won't be billed until the 14 days free period ends. You can delete the account before the first payment.

You will be taken to the [Admin console](https://admin.google.com/).

![Admin console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5pj7hjo7kyn431gtmv48.png)

You will see a prompt to verify the domain you have entered earlier. You have to verify it in order to proceed with the setup. If you don't see the prompt, click Home -> Domains -> Manage domains. Click **Verify domain**. Follow the verification process till the end.

## Creating a Google Cloud project
After the domain is verified, go to the [Google Cloud Platform Console](https://console.cloud.google.com/). We will create a new project and enable the Google Chat API.

Click **Select a project** -> **NEW PROJECT**.

![Window for creating new project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4sb2in2qe7hw35od09ao.png)

Fill in the project name, organization and location. Click **CREATE**. Wait until it is created.
Select that project. 
Search for *"APIs & Services"* and go [there](https://console.cloud.google.com/apis/).

![APIs & Services screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m92ildpfoe7lehda0f6n.png)
  
Click `+ ENABLE APIS AND SERVICES`.
Search for *"Google Chat API"*. Open the Google Chat API search result and click **ENABLE**.

![Google Chat API](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kp635rf3fcn5qj3n1t3w.png)

On the [Hangouts Chat API page](https://console.cloud.google.com/apis/api/chat.googleapis.com/), go to the **Configuration**.

![Configuration screen first half](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n0387puob8bjsyknqb23.png)

Enter the name of the chatbot, avatar URL and a description. You can select whether the chatbot works in direct messages or in rooms and direct messages with multiple users.

In the **Connection settings section**, select **Bot URL**. The URL have the form of `https://<host>:<port>/webhooks/hangouts/webhook`. The protocol must be `https`, not `http`. Replace `host` and `port` with the host and port of your running rasa server. You can expose locally running rasa server using ngrok. Please refer to the [previous article](https://dev.to/petr7555/rasa-messaging-channels-4c2k) to find out how to use ngrok.

To make this channel endpoint available for Google Chat, all you need to do is to add the following to `credentials.yml` in your Rasa chatbot project.
```yml
# credentials.yml
hangouts:
  # no credentials required here
```

Run the rasa server: `rasa run`.
In a new terminal window, run the actions server: `rasa run actions`.
In a new terminal window, run ngrok: `ngrok http 5005`.
Ngrok is listening on port 5005 since this is where the rasa server is running.
Copy the https version of the tunnel URL that was generated by ngrok and paste it into the **Bot URL** input followed by `/webhooks/hangouts/webhook`.

![Configuration screen second half](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9uiodakul0frfgxdr9z1.png)

Lastly, choose who in your domain can install this chatbot.
Click **SAVE**.

## Start a chat with the chatbot
Go to the [Google Chat](https://mail.google.com/chat/) application. 
Click on **Start a chat** and search for your chatbot.
![Starting new conversation with Rasa Chatbot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ue8p1ls5dclc8e0uke71.png)

Now you are ready to chat with the chatbot! 🎉
![Chat with Rasa chatbot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ze6dnyeci1soebpnqgrn.png)

You can see that Google Chat nicely displays [rich responses](https://dev.to/petr7555/rasa-rich-responses-3419) as cards.

To learn more about Google Hangouts Chat channel connector, visit the Rasa [documentation](https://rasa.com/docs/rasa/connectors/hangouts/).

Repository for this tutorial:
{% github petr7555/rasa-dev-tutorial no-readme %}

You can checkout the state of the repository at the end of this tutorial by running:
```bash
git clone --branch 21-google-chat-integration git@github.com:petr7555/rasa-dev-tutorial.git
```