nghia-kun / laravel-chat-api
Send messages to Google Chat via webhooks in Laravel
v1.0.0
2026-05-29 05:27 UTC
Requires
- php: ^8.1
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
This package is auto-updated.
Last update: 2026-05-29 06:46:33 UTC
README
Send messages to Google Chat spaces directly from your Laravel application using incoming webhooks.
Requirements
- PHP 8.1+
- Laravel 10 / 11 / 12
Installation
composer require kun/laravel-chat-api
Laravel auto-discovers the service provider and facade automatically.
Publish the config file (optional)
php artisan vendor:publish --tag=google-chat-config
Configuration
Add the webhook URL to your .env file:
GOOGLE_CHAT_WEBHOOK_URL=https://chat.googleapis.com/v1/spaces/XXXXX/messages?key=...&token=...
How to get the webhook URL: Open your Google Chat space, click the space name, go to Apps & integrations > Webhooks > Add webhook, then copy the generated URL.
Usage
Using the Facade
use Kun\LaravelChatApi\Facades\GoogleChat; // Simple text message GoogleChat::sendMessage('Hello from Laravel!'); // Card with title and body GoogleChat::sendCard('Deploy finished', 'v2.5.0 was deployed to production successfully.'); // Alert / error notification GoogleChat::sendAlert('Payment failed', 'Order #1234 could not be charged.', 'ERROR'); GoogleChat::sendAlert('Disk usage high', 'Server disk at 90%.', 'WARNING'); GoogleChat::sendAlert('Backup done', 'Nightly backup completed.', 'SUCCESS');
Send to a different webhook at runtime
GoogleChat::to('https://chat.googleapis.com/v1/spaces/OTHER/messages?...') ->sendMessage('Message to a different space.');
Using dependency injection
use Kun\LaravelChatApi\GoogleChatService; class OrderController extends Controller { public function __construct(protected GoogleChatService $chat) {} public function store(Request $request) { // ... create order ... $this->chat->sendMessage("New order #{$order->id} received!"); } }
Available Methods
| Method | Description |
|---|---|
sendMessage(string $message) |
Send a plain text message (supports basic Markdown) |
sendCard(string $title, string $body) |
Send a card with a header and text body |
sendAlert(string $title, string $message, string $level) |
Send a prefixed alert: ERROR, WARNING, INFO, SUCCESS |
to(string $webhookUrl) |
Override the webhook URL for one call (returns a cloned instance) |
License
MIT