A comprehensive Laravel package for sending error notifications to multiple platforms including Discord, Slack, WhatsApp, and Email. Get instant alerts when your application encounters critical errors.
- π¨ Multi-platform notifications: Discord, Slack, WhatsApp, Email
- β‘ Fail-safe design: If one service fails, others continue working
- ποΈ Highly configurable: Enable/disable channels, customize messages
- π Rate limiting: Prevent notification spam
- π Queue support: Async notifications for better performance
- π§ͺ Built-in testing: Test your notification channels easily
- π― Environment filtering: Different settings per environment
- π Rich formatting: Platform-specific message formatting
- π Full exception details: Complete error context and stack traces
Install the package via Composer:
composer require mktmsameera/laravel-error-notifier
Publish the configuration file:
php artisan vendor:publish --tag=error-notifier-config
Edit config/error-notifier.php
and enable your desired notification channels:
'channels' => [
'discord' => [
'enabled' => env('DISCORD_ENABLED', false),
'webhook_url' => env('DISCORD_WEBHOOK_URL'),
],
'slack' => [
'enabled' => env('SLACK_ENABLED', false),
'webhook_url' => env('SLACK_WEBHOOK_URL'),
],
'whatsapp' => [
'enabled' => env('WHATSAPP_ENABLED', false),
'provider' => env('WHATSAPP_PROVIDER', 'twilio'),
// ... provider specific config
],
'email' => [
'enabled' => env('EMAIL_ENABLED', false),
'to' => explode(',', env('ERROR_EMAIL_TO', '')),
'from' => env('ERROR_EMAIL_FROM'),
],
],
Add your credentials to .env
:
# Discord
DISCORD_ENABLED=true
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/your-webhook-url
# Slack
SLACK_ENABLED=true
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your-webhook-url
# WhatsApp (Twilio)
WHATSAPP_ENABLED=true
WHATSAPP_PROVIDER=twilio
TWILIO_SID=your_twilio_sid
TWILIO_TOKEN=your_twilio_token
TWILIO_WHATSAPP_FROM=whatsapp:+14155238886
TWILIO_WHATSAPP_TO=whatsapp:+1234567890
# Email
EMAIL_ENABLED=true
ERROR_EMAIL_TO=admin@yourapp.com,dev@yourapp.com
ERROR_EMAIL_FROM=errors@yourapp.com
Extend the provided exception handler or add the notification to your existing handler:
Option A: Extend the provided handler
// app/Exceptions/Handler.php
<?php
namespace App\Exceptions;
use Mktmsameera\LaravelErrorNotifier\Exceptions\Handler as BaseHandler;
class Handler extends BaseHandler
{
// Your existing handler code...
}
Option B: Add to your existing handler
// app/Exceptions/Handler.php
use Mktmsameera\LaravelErrorNotifier\ErrorNotifier;
public function report(Throwable $exception)
{
// Send error notification
if (app()->bound(ErrorNotifier::class)) {
try {
app(ErrorNotifier::class)->notify($exception);
} catch (\Exception $e) {
\Log::error('Error notifier failed: ' . $e->getMessage());
}
}
parent::report($exception);
}
Test all enabled channels:
php artisan error-notifier:test --all
Test a specific channel:
php artisan error-notifier:test discord
php artisan error-notifier:test slack
php artisan error-notifier:test whatsapp
php artisan error-notifier:test email
Only send notifications for specific environments:
'environments' => [
'production',
'staging',
],
Prevent spam by limiting identical errors:
'rate_limit' => [
'enabled' => true,
'throttle_seconds' => 300, // 5 minutes
],
Control which exceptions trigger notifications:
'filters' => [
'include_status_codes' => [500, 503, 504],
'exclude_exceptions' => [
\Illuminate\Validation\ValidationException::class,
\Illuminate\Auth\AuthenticationException::class,
],
],
Send notifications asynchronously:
'queue' => [
'enabled' => true,
'connection' => 'redis',
'queue' => 'notifications',
],
- Go to your Discord server
- Right-click on a channel β Settings β Integrations β Webhooks
- Create a new webhook and copy the URL
- Add to your
.env
:
DISCORD_ENABLED=true
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/your-webhook-url
DISCORD_USERNAME="Error Bot"
DISCORD_MENTION_ROLE=123456789012345678 # Optional: Role ID to mention
- Go to your Slack workspace
- Create a new app at api.slack.com
- Enable Incoming Webhooks and create a webhook
- Add to your
.env
:
SLACK_ENABLED=true
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your-webhook-url
SLACK_CHANNEL="#errors"
SLACK_USERNAME="Error Bot"
- Create a Twilio account at twilio.com
- Set up WhatsApp sandbox or get approved for production
- Add to your
.env
:
WHATSAPP_ENABLED=true
WHATSAPP_PROVIDER=twilio
TWILIO_SID=your_account_sid
TWILIO_TOKEN=your_auth_token
TWILIO_WHATSAPP_FROM=whatsapp:+14155238886
TWILIO_WHATSAPP_TO=whatsapp:+1234567890
- Set up Facebook Business account and WhatsApp Business API
- Get your access token and phone number ID
- Add to your
.env
:
WHATSAPP_ENABLED=true
WHATSAPP_PROVIDER=whatsapp-business
WHATSAPP_BUSINESS_TOKEN=your_access_token
WHATSAPP_BUSINESS_PHONE_ID=your_phone_number_id
WHATSAPP_BUSINESS_TO=1234567890
Uses Laravel's built-in mail configuration:
EMAIL_ENABLED=true
ERROR_EMAIL_TO=admin@yourapp.com,dev@yourapp.com
ERROR_EMAIL_FROM=errors@yourapp.com
ERROR_EMAIL_SUBJECT_PREFIX="[URGENT ERROR]"
You can also use the error notifier manually:
use Mktmsameera\LaravelErrorNotifier\ErrorNotifier;
// In a controller or service
try {
// Your code that might throw an exception
riskyOperation();
} catch (\Exception $e) {
// Send notification with custom context
app(ErrorNotifier::class)->notify($e, [
'user_action' => 'processing_payment',
'order_id' => 12345,
]);
// Re-throw or handle as needed
throw $e;
}
For more control over when notifications are sent:
public function report(Throwable $exception)
{
// Only notify for critical errors in production
if (app()->isProduction() && $this->isCriticalError($exception)) {
app(ErrorNotifier::class)->notify($exception, [
'severity' => 'critical',
'requires_immediate_attention' => true,
]);
}
parent::report($exception);
}
private function isCriticalError(Throwable $exception): bool
{
return $exception instanceof \Exception &&
!$exception instanceof \Illuminate\Validation\ValidationException;
}
Create different configurations for different environments:
// config/error-notifier.php
'channels' => [
'discord' => [
'enabled' => env('DISCORD_ENABLED', false),
'webhook_url' => env('APP_ENV') === 'production'
? env('DISCORD_WEBHOOK_PROD')
: env('DISCORD_WEBHOOK_STAGING'),
],
],
Run the package tests:
composer test
Test your notification setup:
# Test all channels
php artisan error-notifier:test --all
# Test specific channel
php artisan error-notifier:test discord
# Test with verbose output
php artisan error-notifier:test slack -v
-
Notifications not sending
- Check that the package is enabled:
ERROR_NOTIFIER_ENABLED=true
- Verify you're in the correct environment
- Check logs for any error messages
- Check that the package is enabled:
-
WhatsApp not working
- Ensure your Twilio sandbox is set up correctly
- Verify phone numbers are in the correct format
- Check Twilio account balance
-
Discord/Slack webhooks failing
- Verify webhook URLs are correct and active
- Check channel permissions
- Test webhooks manually with curl
-
Email notifications not sending
- Verify Laravel mail configuration
- Check email credentials and SMTP settings
- Ensure recipient emails are valid
Enable debug logging to troubleshoot issues:
// In your exception handler
\Log::debug('Error notifier triggered', [
'exception' => get_class($exception),
'message' => $exception->getMessage(),
]);
- Store all credentials in environment variables, never in code
- Use rate limiting to prevent notification spam
- Consider which information to include in notifications (avoid sensitive data)
- Regularly rotate API keys and tokens
- Use HTTPS for all webhook URLs
Contributions are welcome! Please read our contributing guide and submit pull requests to our GitHub repository.
This package is open-sourced software licensed under the MIT license.
- π Documentation
- π Issue Tracker
- π¬ Discussions
Please see CHANGELOG for more information on what has changed recently.