Search by

firith / laravel-converse-google-chat

firith

Google Chat driver for Laravel Converse.

Package info

github.com/firith/laravel-converse-google-chat

pkg:composer/firith/laravel-converse-google-chat

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.1 2026-12-04 11:41 UTC

This package is auto-updated.

Last update: 2026-12-04 11:49:19 UTC


README

Google Chat for Laravel Converse

Packagist PHP from Packagist Laravel versions GitHub Workflow Status (main) Total Downloads

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:

  1. 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.
  2. Offers to copy the key into storage/app/private/google-chat/ (outside of git; the copy gets 0600 permissions).
  3. Asks for the Cloud project number, the app type (classic Chat app or Workspace add-on), and, for classic apps, the authentication audience.
  4. Asks for the public HTTPS URL of your application and builds the webhook URL from it.
  5. Writes GOOGLE_CHAT_CREDENTIALS, GOOGLE_CHAT_AUDIENCE, GOOGLE_CHAT_PROJECT_NUMBER and GOOGLE_CHAT_ADDON to .env.
  6. 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.
  7. 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

  1. Create (or pick) a Google Cloud project and enable the Google Chat API in it.
  2. 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 the chat.bot scope.
  3. 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.
  4. 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> and GOOGLE_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. Fields map to decoratedText, Actions to buttonList and selectionInput, and Table to a formatted text paragraph.
  • Send a platform-specific card with Card::withRaw('google-chat', [...]); the fields of the Chat message resource (such as cardsV2 or text) 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 200 and an empty {} JSON body, and the reply is sent asynchronously. Workspace add-ons treat Converse's default body-less 204 response 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.