savan / gchat-error-alert
Google Chat error alert package for Laravel
Requires
- php: ^7.4|^8.0|^8.1|^8.2|^8.3
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0
README
Send Laravel application error alerts directly to Google Chat using Incoming Webhooks.
This package integrates with Laravel's logging system and sends log events to a Google Chat space.
Supports Laravel 8, 9, 10, 11 and 12.
๐ Features
- Google Chat webhook integration
- Custom Monolog logging driver
- Supports Laravel 8--12
- Environment-based log level filtering
- Auto-discovery support
- Works with HTTP & CLI errors
- Compatible with Monolog 2 & 3
- Plug & Play configuration
๐ฆ Installation
Install via Composer:
composer require savan/gchat-error-alert
๐ง Step 1: Create Google Chat Webhook
- Open Google Chat
- Go to the Space where you want alerts
- Click Space name โ Manage Webhooks
- Click Add Webhook
- Copy the generated Webhook URL
Example webhook:
https://chat.googleapis.com/v1/spaces/XXXX/messages?key=XXX&token=XXX
โ Step 2: Publish Configuration
Run:
php artisan vendor:publish --tag=gchat-alert-config
This will create:
config/gchat-alert.php
๐งพ Step 3: Configure Environment Variables
Add to your .env file:
GCHAT_ALERT_ENABLED=true
GCHAT_ALERT_WEBHOOK=https://chat.googleapis.com/v1/spaces/XXXX/messages?key=XXX&token=XXX
GCHAT_ALERT_LEVEL=error
๐ Step 4: Configure Logging
Open:
config/logging.php
Add this channel inside channels:
'gchat' => [
'driver' => 'gchat',
],
Then add it to your stack:
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'gchat'],
],
Make sure your default log channel is:
LOG_CHANNEL=stack
๐ฅ Step 5: Clear Configuration Cache
php artisan config:clear
php artisan cache:clear
๐งช Testing
Create a test route:
use Illuminate\Support\Facades\Log;
Route::get('/test-alert', function () {
Log::error('Test error from Laravel GChat Alert');
return 'Alert Sent';
});
Visit:
/test-alert
You should receive a Google Chat alert.
๐ Log Levels
Available levels (highest to lowest severity):
- emergency
- alert
- critical
- error
- warning
- notice
- info
- debug
If GCHAT_ALERT_LEVEL=error, it will send:
- error
- critical
- alert
- emergency
๐ฅ CLI & Queue Support
This package captures:
- HTTP request errors
- Artisan command errors
- Queue worker failures
- Scheduled task errors
- Runtime CLI exceptions
๐ Requirements
- PHP 7.4+
- Laravel 8 -- 12
- Google Chat Incoming Webhook
โ Troubleshooting
If you are not receiving alerts, check:
LOG_CHANNEL=stackGCHAT_ALERT_ENABLED=true- Webhook URL is correct
- Log level is set correctly
- Configuration cache is cleared
Run:
php artisan config:clear
composer dump-autoload
๐ท Versioning
This package follows Semantic Versioning:
- v1.0.0 -- Initial release
- v1.1.0 -- Feature update
- v1.1.1 -- Bug fix
๐ License
MIT License
๐ค Author
Savan Rathod
โญ Support
If you find this package useful, please consider giving it a star on GitHub.