Configuration & Transports
Pre-release Version
These documentation pages are for the pre-release v2 of this package.
This guide covers space routing, environment variables, local testing overrides, and choosing between Webhook and Service Account transports.
Published Configuration File
Publishing php artisan vendor:publish --tag=google-chat-config generates config/google-chat.php:
return [
/*
|--------------------------------------------------------------------------
| Transport Driver
|--------------------------------------------------------------------------
|
| Supported: "webhook", "service_account"
|
*/
'driver' => env('GOOGLE_CHAT_DRIVER', 'webhook'),
/*
|--------------------------------------------------------------------------
| Default Space Webhook URL / Alias
|--------------------------------------------------------------------------
*/
'space' => env('GOOGLE_CHAT_DEFAULT_SPACE', null),
/*
|--------------------------------------------------------------------------
| Named Space Aliases
|--------------------------------------------------------------------------
*/
'spaces' => [
'dev' => env('GOOGLE_CHAT_SPACE_DEV'),
'sales' => env('GOOGLE_CHAT_SPACE_SALES'),
'alerts' => env('GOOGLE_CHAT_SPACE_ALERTS'),
],
/*
|--------------------------------------------------------------------------
| Service Account Credentials
|--------------------------------------------------------------------------
*/
'service_account' => [
'access_token' => env('GOOGLE_CHAT_ACCESS_TOKEN'),
],
/*
|--------------------------------------------------------------------------
| Development Test Space Override
|--------------------------------------------------------------------------
*/
'test_space' => env('GOOGLE_CHAT_TEST_SPACE'),
];Space Routing Strategies
1. Default Space Alias
If your application posts notifications to a single primary Google Chat space, configure space:
GOOGLE_CHAT_DEFAULT_SPACE=https://chat.googleapis.com/v1/spaces/AAAA/messages?key=XXX&token=YYYNotifications that do not explicitly specify a target room will automatically route to this default space.
CAUTION
If your application transmits sensitive data via notifications, leave space set to null to require explicit routing destinations for every notification.
2. Named Space Aliases (Recommended)
To route different notifications to specific rooms (such as #sales, #dev, or #alerts), define space aliases in config/google-chat.php:
'spaces' => [
'sales' => env('GOOGLE_CHAT_SPACE_SALES'),
'dev' => env('GOOGLE_CHAT_SPACE_DEV'),
'alerts' => env('GOOGLE_CHAT_SPACE_ALERTS'),
],You can target a named space in several ways:
Via Notification Route Call
Notification::route('googleChat', 'sales')->notify(new InvoicePaid($invoice));Via Message Builder to() Method
GoogleChatMessage::create()->to('dev')->text('Deployment complete.');Via Notifiable Model
public function routeNotificationForGoogleChat(object $notification): string
{
return 'alerts';
}3. Explicit Webhook URLs
You can also pass complete Google Chat webhook URLs directly:
GoogleChatMessage::create()
->to('https://chat.googleapis.com/v1/spaces/AAAA/messages?key=XXX&token=YYY')
->text('Direct webhook notification');Local Development & Test Space Overrides
During local development or staging verification, you can override all outbound notification routing to send every message into a single test space without modifying application code.
Set GOOGLE_CHAT_TEST_SPACE in your .env file:
GOOGLE_CHAT_TEST_SPACE=https://chat.googleapis.com/v1/spaces/TEST_SPACE/messages?key=XXX&token=YYYWhen present, all outbound Google Chat notifications are automatically redirected to this test space endpoint.
Transport Drivers
1. Webhook Transport (webhook)
The default webhook transport posts incoming webhook requests to Google Chat space URLs. It uses Laravel's native Illuminate\Support\Facades\Http facade.
Testing in Application Test Suites (Http::fake())
Because the webhook transport uses Laravel's Http facade, you can fake outbound notifications in your unit and feature tests effortlessly:
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Notification;
public function test_it_sends_google_chat_notification()
{
Http::fake([
'chat.googleapis.com/*' => Http::response(['name' => 'spaces/AAAA/messages/123'], 200),
]);
Notification::route('googleChat', 'dev')->notify(new DeploymentNotification());
Http::assertSent(function ($request) {
return str_contains($request->url(), 'chat.googleapis.com')
&& $request['text'] === 'Deployment complete.';
});
}2. Service Account REST Transport (service_account)
For advanced Google Workspace API features (such as updating existing cards, deleting messages, or interacting with space resource IDs), switch to the service_account driver:
GOOGLE_CHAT_DRIVER=service_account
GOOGLE_CHAT_ACCESS_TOKEN=ya29.a0AfH6SM...The Service Account transport attaches an Authorization: Bearer <token> header to REST requests targeted at Google Chat REST endpoints (https://chat.googleapis.com/v1/...).
Google API Reference
For official Google documentation on space webhooks and authentication: