firith / laravel-converse-google-chat
Google Chat driver for Laravel Converse.
Package info
github.com/firith/laravel-converse-google-chat
pkg:composer/firith/laravel-converse-google-chat
Requires
- php: ^8.4
- ext-openssl: *
- illuminate/cache: ^13.0
- illuminate/http: ^13.0
- illuminate/support: ^13.0
- laravel/converse: ^1.0
Requires (Dev)
- larastan/larastan: ^3.9
- laravel/pao: ^1.0
- laravel/pint: ^1.29
- orchestra/testbench: ^11.0
- pestphp/pest: ^5.0
- pestphp/pest-plugin-laravel: ^5.0
- pestphp/pest-plugin-type-coverage: ^5.0
- phpstan/extension-installer: ^1.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Google Chat for Laravel Converse
A Google Chat driver for Laravel Converse. With it, the same Converse bot (agent or handler) that answers on Slack, Telegram and the web chat also answers in Google Chat.
- Receives Google Chat interaction events over HTTP, from both classic Chat apps and Google Workspace add-ons
- Verifies Google-signed requests (RS256 JWT) without any extra dependency
- Sends replies asynchronously through the Chat REST API, authenticated as a service account (app authentication)
- Converts Markdown to Google Chat text formatting and Converse cards to
cardsV2
Requirements
- PHP 8.4 with
ext-openssl - Laravel 13 and
laravel/converse^1.0 - A running queue worker (Converse handles every webhook on the queue)
- A cache store that supports atomic locks for Converse; the driver keeps Google's certificates and the access token in the default cache store
Installation
You can install the package via Composer:
composer require firith/converse-google-chat
The GoogleChatServiceProvider is loaded through package discovery and registers the driver with Converse as google-chat.
Configuration
Add a connection to config/converse.php:
'connections' => [ 'google-chat' => [ 'driver' => 'google-chat', 'credentials' => env('GOOGLE_CHAT_CREDENTIALS'), 'audience' => env('GOOGLE_CHAT_AUDIENCE'), 'project_number' => env('GOOGLE_CHAT_PROJECT_NUMBER'), 'addon' => env('GOOGLE_CHAT_ADDON', false), 'commands' => [ // 1 => 'help', ], ], ],
| Key | Description |
|---|---|
credentials |
The service account JSON key: a file path (absolute or relative to the project root), a JSON string, or an array. client_email and private_key are required. |
audience |
The token audience configured in the Chat API: the Cloud project number (e.g. 123456789012) or the endpoint URL. Without it, every request is rejected. |
project_number |
Required for Workspace add-ons using the endpoint URL audience. Only tokens from this project's service agent (service-<project-number>@gcp-sa-gsuiteaddons.iam.gserviceaccount.com) are accepted. With a project number audience it is taken from the audience. |
addon |
true when the app is built as a Google Workspace add-on. Card buttons then call the endpoint URL instead of a function name. |
endpoint_url |
Optional. In add-on mode, card actions are sent to this URL. Defaults to audience. |
commands |
A command ID → name map for commands whose events carry no name (such as quick commands). |
Then add the connection to your bot in routes/bot.php:
Converse::agent('assistant', Assistant::class) ->connections(['web', 'slack', 'google-chat']);
The webhook URL is the usual Converse route:
https://<domain>/converse/{bot}/google-chat
Converse responds with 404 until the bot is registered on the connection, so register the bot before you configure Google Chat.
Setup Wizard
The driver supports Converse's converse:setup command, just like the built-in Slack and Telegram channels:
php artisan converse:setup google-chat
With several bots, choose the one that should answer with --bot=<name>. The wizard:
- Offers to continue with an already configured service account. Otherwise it walks you through creating one, asks for the path of the downloaded JSON key, and checks with Google that the key is valid, asking again if it is rejected.
- Offers to copy the key into
storage/app/private/google-chat/(outside of git; the copy gets0600permissions). - Asks for the Cloud project number, the app type (classic Chat app or Workspace add-on), and, for classic apps, the authentication audience.
- Asks for the public HTTPS URL of your application and builds the webhook URL from it.
- Writes
GOOGLE_CHAT_CREDENTIALS,GOOGLE_CHAT_AUDIENCE,GOOGLE_CHAT_PROJECT_NUMBERandGOOGLE_CHAT_ADDONto.env. - Prints the exact values to enter in the Cloud Console, with a direct link to the Chat API configuration page. Google offers no API to configure a Chat app, so this step is manual.
- After you save, checks with Google that the Chat app is reachable. On failure it prints Google's error and lets you retry.
Restart running queue workers so they pick up the new variables, and run php artisan config:clear if your configuration is cached.
Configuring the Google Chat App Manually
- Create (or pick) a Google Cloud project and enable the Google Chat API in it.
- Create a service account and download a JSON key for it. Set it as
GOOGLE_CHAT_CREDENTIALS; relative paths are resolved from the project root. No role is needed: app authentication uses thechat.botscope. - On the Chat API Configuration page:
- give the app a name, avatar and description;
- under Interactive features, enable 1:1 messages and joining spaces;
- Connection settings: HTTP endpoint URL →
https://<domain>/converse/assistant/google-chat; - Authentication Audience: choose Project Number (recommended) or HTTP endpoint URL;
- Visibility: choose who in your domain may install the app.
- If Build this Chat app as a Google Workspace add-on is checked (the default since July 2025), set
GOOGLE_CHAT_ADDON=true,GOOGLE_CHAT_AUDIENCE=<endpoint URL>andGOOGLE_CHAT_PROJECT_NUMBER=<project number>.
Example .env for a classic app:
GOOGLE_CHAT_CREDENTIALS=/var/secrets/google-chat-service-account.json GOOGLE_CHAT_AUDIENCE=123456789012
Example .env for a Workspace add-on:
GOOGLE_CHAT_CREDENTIALS=/var/secrets/google-chat-service-account.json GOOGLE_CHAT_AUDIENCE=https://example.com/converse/assistant/google-chat GOOGLE_CHAT_PROJECT_NUMBER=123456789012 GOOGLE_CHAT_ADDON=true
Security: for classic apps with the endpoint URL audience, a Chat app in another project can also obtain a Google-signed token addressed to your URL. Use the project number audience for classic apps.
Event Mapping
| Google Chat | Converse |
|---|---|
MESSAGE in a space (@mention) |
Message, a mention, in the Chat thread (spaces/X/threads/Y) |
MESSAGE in a DM |
Message, a direct message. The whole DM is one Converse thread, so the agent remembers the history |
ADDED_TO_SPACE with a message (e.g. added by @mention) |
Message |
Slash command (message.slashCommand) / APP_COMMAND |
Command: the name is the command name without /, the text is the arguments |
CARD_CLICKED |
Action: the button ID and value, or the selected option for menus |
REMOVED_FROM_SPACE and others |
ignored |
- The message text is Chat's
argumentText, i.e. the text without the app mention. - The user ID is the Chat resource name (
users/123…); account linking (RequireLinkedAccount) uses it as well. - Uploaded attachments are downloaded and staged by Converse. Google Drive links are skipped, since they cannot be downloaded with app authentication.
Sending Messages
$thread->send('Plain text'); $thread->send(Markdown::make('**Bold**, [link](https://example.com)')); $thread->send(Card::make('Deploy')->add(Actions::make(Button::make('deploy')->withLabel('Start')))); $thread->sendEphemeral('Only you can see this', $user);
- Markdown:
**bold**→*bold*,*italic*→_italic_,~~strike~~→~strike~,[text](url)→<url|text>; headings become bold and code fences lose their language hint. - Cards: sent as
cardsV2, with card text rendered in the HTML subset Chat supports.Fieldsmap todecoratedText,ActionstobuttonListandselectionInput, andTableto a formatted text paragraph. - Send a platform-specific card with
Card::withRaw('google-chat', [...]); the fields of the Chat message resource (such ascardsV2ortext) are passed through unchanged. - Mention a user with
$thread->driver()->mention($user)→<users/123…>.
Capabilities
| Capability | Supported |
|---|---|
| Edit / delete messages | ✅ (only the app's own messages) |
| Private (ephemeral) messages | ✅ (privateMessageViewer) |
| Opening a DM | ✅ (spaces.findDirectMessage, only when a DM with the user already exists) |
Space details (GetChannel) |
✅ |
| Receiving attachments | ✅ (uploaded files) |
| Reactions, typing indicator, message history, sending attachments | ❌ (Google requires user authentication for these; they are unavailable with app authentication) |
Check $thread->supports(Capability::…) before using an unsupported operation.
Testing
In your application's tests, use Converse's usual Converse::fake() + Converse::incoming() pattern with the google-chat connection.
To run the package's own test suite:
composer test
Known Limitations
- Verified webhooks are acknowledged immediately with
200and an empty{}JSON body, and the reply is sent asynchronously. Workspace add-ons treat Converse's default body-less204response as an error and show " not responding". - Synchronous responses (such as dialogs or
actionResponse) are not used: every reply goes out asynchronously through the REST API. - Workload Identity / Application Default Credentials are not supported; a service account key is required.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Thank you for considering contributing to Google Chat for Laravel Converse! Please review our contributing guide to get started.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
Google Chat for Laravel Converse is open-sourced software licensed under the MIT license.