> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cake.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up Google Chat

> Connect Cake Agents to Google Chat so users can start sessions from direct messages and @-mentions.

Administrators connect Google Chat to Cake Agents once for the whole organization. After setup, users can start Cake sessions from Google Chat and follow the agent's progress in the same conversation.

## What this enables

Connecting Google Chat allows Cake Agents to:

* start a Cake session when a user sends the Cake Agents app a direct message
* start a Cake session when a user @-mentions the app at the start of a message in a space
* stream agent output back into the Google Chat thread
* read attachments sent with the message

## How Google Chat sessions work

When a user sends a direct message or starts a message with an @-mention of the app, Cake Agents creates a new session and replies with a link to it. Follow-up messages in the same thread go to the same session. Sessions started from a direct message are [private](https://docs.cake.ai/user/private-sessions.md) by default.

Cake Agents identifies the Google Chat user by email. If no Cake user with that email exists, Cake Agents creates one.

If the user hasn't linked GitHub, the reply includes a **Link GitHub** link so Cake can open pull requests and push commits for them. See [Link GitHub](https://docs.cake.ai/user/link-github.md).

## Admin responsibilities

Unlike the GitHub, Linear, and Slack integrations, you create the Google Chat app from the command line with the Google Cloud CLI. As an admin, you are responsible for:

* creating a Google Group for the people who can use the app
* running the Cake Agents setup script, which creates a Google Cloud project, configures the Chat app, and creates a service account key
* pasting the script's output into Cake Agents
* keeping the credentials up to date if you rotate the service account key

## Requirements

* You need the **admin** role in Cake Agents.
* Google must be able to reach your Cake Agents instance. Google Chat sends events to `https://<your-cake-host>/api/webhooks/gchat`. Deployments that [disable public ingress](https://docs.cake.ai/admin/getting-started-kubernetes.md#optional-disable-public-ingress) return `404` for these events.
* The [Google Cloud CLI](https://cloud.google.com/sdk/docs/install) (`gcloud`) must be installed, including the `beta` component.
* You must be signed in to `gcloud` as a user (`gcloud auth login`), not a service account, with permission to create Google Cloud projects.
* The setup script, `create-gchat-app.sh`. For now, a member of the Cake team shares the script with you directly.
* A Google Group whose members can use the app. See [Choose who can use the app](#choose-who-can-use-the-app).

## Instructions

### Choose who can use the app

Cake Agents isn't published to the Google Workspace Marketplace. Instead, the setup script allowlists the users and groups that can use the app in your Google Workspace. Anyone not on the allowlist can't message the app.

Create a Google Group for the people who should use Cake Agents in Google Chat, and pass the group's email to the script. To give someone access later, add them to the group. You don't need to run the script again.

### Run the setup script

Run the script with three arguments:

```bash theme={null}
./create-gchat-app.sh <base-url> <project-id> <allowed-principals>
```

| Argument | Description |
| - | - |
| `<base-url>` | The protocol, host, and optional base path where Cake Agents is publicly reachable, for example `https://cake-agents.example.com`. Don't include a trailing slash. |
| `<project-id>` | The ID of a new Google Cloud project for the app. The script creates this project. |
| `<allowed-principals>` | The email of the Google Group whose members can use the app, for example `cake-agents-users@example.com`. You can pass a comma-separated list of group or user emails. |

The script:

1. Creates the Google Cloud project and sets it as your active `gcloud` project.
2. Enables the Google Chat, Google Workspace add-ons, and IAM APIs.
3. Configures the Chat app with the display name **Cake Agents**, the endpoint `<base-url>/api/webhooks/gchat`, and support for spaces with multiple users, and allowlists the principals you passed.
4. Creates a service account named `cake-agents-gchat` and a key for it.
5. Prints two values you need in the next step:
   * a line starting with `workspaceAddOnServiceAccountEmail:`, followed by an address like `service-<project-number>@gcp-sa-gsuiteaddons.iam.gserviceaccount.com`
   * the service account key as a JSON object

The script deletes its temporary copy of the key when it exits. Copy the JSON from the terminal before you close it, and store it as a secret.

### Save the credentials in Cake Agents

1. In Cake Agents, go to `Settings → Organization → Integrations`.
2. Next to **Google Chat**, select **Connect**.
3. In **Service Account Email**, paste the address printed after `workspaceAddOnServiceAccountEmail:`. Cake Agents saves the field when you leave it.
4. Expand **Credentials JSON**, paste the service account key JSON, and select **Save**.

The integration shows as **Connected** once both the service account email and the credentials JSON are saved.

### Set the bot user ID

Cake Agents needs the Chat app's own user ID (`users/<number>`) to recognize @-mentions in spaces. Until the **Bot User ID** field is set, Cake Agents ignores @-mentions.

Cake Agents fills in **Bot User ID** automatically when the app is added to a space or someone opens a direct message with it. After setup, add the app to a space or open a direct message with it as one of the allowed principals, then check that the field has a value. You can also paste the ID yourself.

## Rotate or update credentials

To rotate the service account key:

1. Create a new key for the `cake-agents-gchat` service account in your Google Cloud project.
2. In Cake Agents, go to `Settings → Organization → Integrations` and select **Connected** next to Google Chat.
3. Expand **Credentials JSON**, paste the new key, and select **Save**.

To remove the integration's credentials, select **Clear** under **Credentials JSON**.

## Troubleshooting

### The app doesn't respond to @-mentions in a space

The **Bot User ID** field is empty. To fill it in, add the app to a space or open a direct message with it. If the app is already in the space, remove it and add it again. You can also paste the app's `users/<number>` ID into the field.

### The app doesn't respond to direct messages

Check that Google can reach `https://<your-cake-host>/api/webhooks/gchat` and that public ingress is enabled. Cake Agents verifies each request against the saved **Service Account Email**, so also check that the field matches the address the setup script printed.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.