# Google Chat app

> Ask MergeHarbor about pull requests in Google Chat, get review summaries and open fix pull requests: connect, roles, caps and data handling.

The MergeHarbor app for Google Chat does what the [Slack app](https://mergeharbor.com/docs/slack) does: it answers questions about pull requests, summarises reviews, explains findings, opens a fix pull request after someone allowed confirms it, and posts review alerts with buttons. This page covers how to connect it and where Google Chat differs. If you only want alerts in a space, an [incoming webhook](https://mergeharbor.com/docs/integrations#slack-microsoft-teams-and-google-chat) is the simpler option.

## Connect

1. Add MergeHarbor to a space in Google Chat, or start a direct message with it. **Integrations → Google Chat** in the console says where to find the app. Your Google Workspace administrator may need to allow it first.
2. The app answers with a **Connect to MergeHarbor** card.
3. Someone with the `settings.manage` permission in MergeHarbor opens the card's link while signed in and confirms. The link works once and expires after seven days.
4. Map spaces to repositories in the console.

A connection covers your Google Workspace account: once connected, every space in your Workspace that adds the app belongs to the same MergeHarbor organization. For people outside a Google Workspace, the connection covers the one space. Each connection belongs to one organization at a time.

## What you can ask

@mention MergeHarbor in a space, or message it directly. It answers in the message's thread. The requests are the same as in Slack and Teams:

| You write                           | MergeHarbor answers with                                               | Credits |
| ----------------------------------- | ---------------------------------------------------------------------- | ------- |
| A pull request link, or `summarise` | The stored review summary, confidence, counts and findings             | None    |
| `explain finding 2`                 | One finding with its suggested change                                  | None    |
| `status`                            | Pull request state, review status, open findings and the latest fix PR | None    |
| `open a fix`                        | A confirmation card                                                    | None    |
| `link`                              | A card with a one-time link to connect your Google account             | None    |
| `help`                              | What the app can do                                                    | None    |
| Any other question                  | An answer from the same engine as **Ask** in the console               | Yes     |

A question needs a pull request, named with a link or as `PR #12 in acme/payments`. Follow-ups in the same thread can leave it out. Answers are cards with a **View in MergeHarbor** button and a line saying whether credits were used. Questions and answers also appear on the pull request in the console, under **Questions from Google Chat**.

## How Google Chat differs from Slack

- **No slash command.** Use `@MergeHarbor link` and `@MergeHarbor status`.
- **Space history is not read.** For a follow-up, the app uses only its own redacted memory of the thread, not earlier messages in the space.
- **Private refusals.** When someone who is not allowed presses a button, only they see the refusal.
- **Which spaces are public.** A space counts as public unless its access is restricted. Group chats count as private, and direct messages as direct messages. A private repository is answered in a public space only when that space is mapped to it by name.

## People, roles, caps and alerts

These work as in Slack:

- **People** are linked by the email address Google Workspace manages for them, or with `@MergeHarbor link`. People who are not linked get read-only answers.
- **Mappings** give a space a set of repositories and a role: **ask**, **fix** or **approver**. The most specific mapping wins. See [Channels, repositories and roles](https://mergeharbor.com/docs/slack#channels-repositories-and-roles).
- **Credit caps** per space and per person, each calendar month.
- **Fix pull requests** are opened only after the author or an approver (in **fix** spaces) or an approver (in **approver** spaces) presses **Open fix pull request**.
- **Alerts** go to a space you pick, to every space mapped to the repository, or to the author's direct message with the app, with **Explain**, **Open fix PR** and **Mute 24h** buttons.
- **Activity log** with filters and CSV export, and no message text.

## Data handling

- **Verified requests.** Every request from Google Chat carries a token signed by Google. MergeHarbor checks its signature, issuer, audience and expiry, and rejects anything else. Replies go only to `chat.googleapis.com`.
- **Redaction.** Message text is redacted of secrets before it is queued, and the queued copy is deleted once handled. Everything the app posts is redacted and escaped, so it cannot mention people.
- **What is stored.** Per thread, the pull request it is about and a short redacted memory, kept for 90 days after the last answer; the activity log, with no message text, for 400 days. Questions and answers are kept on the pull request like console questions.
- **Disconnect.** Removing the app from its last space, or disconnecting in the console, revokes the connection.

## Self-hosted installations

Self-hosted installations configure their own Chat app in a Google Cloud project and set `GOOGLE_CHAT_PROJECT_NUMBER` and `GOOGLE_CHAT_SERVICE_ACCOUNT_JSON`. Steps are in `docs/integrations/GOOGLE_CHAT.md` and `docs/OAUTH_APPS.md`, "Google Chat app".
