- Can I use this package directly in Laravel without Symfony’s Notifier component?
- No, this package requires Symfony’s Notifier component (v5.4+). For Laravel, you’ll need to extract the GoogleChatTransport logic or use a Symfony microkernel/Lumen instance to host the Notifier. Alternatively, abstract the transport behind an interface to swap implementations.
- How do I configure Google Chat credentials securely in Laravel?
- Store `ACCESS_KEY` and `ACCESS_TOKEN` in Laravel’s `.env` file (e.g., `GOOGLE_CHAT_ACCESS_KEY=your_key`). For production, use Laravel Forge, Vault, or service accounts. Avoid hardcoding tokens. For OAuth, implement a token refresh mechanism via Laravel’s caching or a dedicated service.
- What’s the DSN format for Laravel, and how do I set it?
- The DSN follows `googlechat://ACCESS_KEY:ACCESS_TOKEN@default/SPACE?thread_key=THREAD_KEY`. In Laravel, set it in `.env` (e.g., `GOOGLE_CHAT_DSN=googlechat://key:token@default/space123?thread_key=alerts`). Use a config helper or Symfony’s `Notifier` facade to parse it if integrating via a microkernel.
- Will this work with Laravel’s queues for async notifications?
- Yes, pair this with Laravel’s queues or Symfony’s Messenger. Dispatch notifications asynchronously via `dispatch()` or `dispatchSync()`. For high volume, configure queue workers with exponential backoff to handle Google Chat’s rate limits (1,000 messages/day per space).
- How do I group messages into threads in Google Chat?
- Use the `thread_key` parameter in the DSN (e.g., `?thread_key=incidents`). For dynamic threads, map keys to incidents in your database (e.g., `thread_key=incident_{$incident->id}`). Avoid static keys to prevent message sprawl in shared spaces.
- What Laravel versions are supported, and are there Symfony dependencies?
- This package isn’t Laravel-native, but it works with Laravel 8+ if you abstract Symfony’s Notifier. The package adds ~5MB (Symfony dependencies). Mitigate bloat by using Composer’s `replace` to avoid pulling the full Symfony stack or extracting only the `GoogleChatTransport` class.
- How do I handle Google Chat API failures or rate limits?
- Configure retries in Laravel’s queue worker or Symfony’s `HttpClient` (e.g., 3 retries with exponential backoff). Log failures via Laravel’s logging or monitor dead-letter queues. For critical alerts, implement a fallback (e.g., email) using Laravel’s `fallback` method in notifications.
- Can I send interactive messages (cards/buttons) with this package?
- Yes, use Google Chat’s card format in your notification payload. Symfony’s Notifier supports rich messages, so pass a JSON payload with `buttons`, `sections`, or `widgets`. Example: `$notification->info('Alert')->asGoogleChatCard(['text' => 'Click me', 'buttons' => [...]])`.
- What if Google Chat’s API changes or the package is abandoned?
- Monitor Google’s API deprecations and Symfony’s changelog. The package is MIT-licensed, but no dependents exist yet. Mitigate risk by wrapping the transport in an interface (e.g., `GoogleChatTransportInterface`) and implementing your own fallback logic or using a maintained alternative like `spatie/laravel-google-chat`.
- How do I test this in Laravel without hitting Google Chat’s API?
- Mock HTTP calls using Laravel’s `MockHttpClient` or Symfony’s `HttpClientMock`. For unit tests, inject a fake transport or use a test DSN pointing to a local server. Example: `$this->app->bind('google_chat_transport', fn() => new FakeGoogleChatTransport());` in your `TestCase` setup.