nqxcode / laravel-exception-notifier
Notify about exception in laravel project via telegram and email
Requires
- php: ^7.4
- ext-json: *
- ext-phar: *
- facade/ignition: ^2.0
- laravel-notification-channels/telegram: ^0.5.0
- laravel/framework: ^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
Suggests
- ext-posix: Needed for getting the process info, like user name.
README
Notify about exception in laravel project via telegram and email.
Notification attachment contains gzipped html with exception dump that rendered with facade/ignition, for example:
Installation
Require this package in your composer.json:
composer require "nqxcode/laravel-exception-notifier"
Configuration
Publish the config file into your project by running:
php artisan vendor:publish --provider="Nqxcode\LaravelExceptionNotifier\ServiceProvider"
Change default config file config/laravel-exception-notifier.php
, for example remove unnecessary channel:
<?php return [ 'routes' => [ [ 'channel' => 'mail', 'route' => env('EXCEPTION_NOTIFIER_EMAIL', 'example@gmail.com'), ], [ 'channel' => 'telegram', 'route' => env('EXCEPTION_NOTIFIER_TELEGRAM_USER_ID', '1234567890') ] ], 'subject' => 'Исключение на сайте '.env('APP_URL'), ];
Add to config/services.php
following:
<?php return [ // ... 'telegram-bot-api' => [ 'token' => env('TELEGRAM_BOT_TOKEN'), ] ];
In .env
add correct environment variables:
# For email notification EXCEPTION_NOTIFIER_EMAIL=test@test.com # For telegram notification # recipient EXCEPTION_NOTIFIER_TELEGRAM_USER_ID=423460522 # sender TELEGRAM_BOT_TOKEN=1160101879:AAFzuda0o7X6Dp4RBp00K-7dYjjnwMY887A
To get telegram bot token create new bot in BotFather
with this action /newbot
, see more details here.
To notify about exception for production
environment in file app/Exceptions/Handler.php
modify report
method:
<?php namespace App\Exceptions; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Nqxcode\LaravelExceptionNotifier\ExceptionNotifierInterface; use Throwable; class Handler extends ExceptionHandler { // ... public function report(Throwable $exception) { if ($this->container->isProduction() && $this->shouldReport($exception)) { $this->container->make(ExceptionNotifierInterface::class)->notify($exception); } parent::report($exception); } // ... }
License
Package licenced under the MIT license.