This is a monolog telegram handler for laravel applications
You can install the package via composer:
composer require defstudio/laravel-telegram-log
You can publish the config file with:
php artisan vendor:publish --provider="Defstudio\LaravelTelegramLog\LaravelTelegramLogServiceProvider" --tag="config"
This is the contents of the published config file:
return [
'bot_token' => env('TELEGRAM_BOT_TOKEN'),
'chat_id' => env('TELEGRAM_CHAT_ID'),
];
Add the new Log Channel in config/logging.php:
'telegram' => [
'driver' => 'custom',
'via' => LaravelTelegramLog::class,
'level' => 'error',
],
If you use the stack channel as default logger, you can just the telegram channel to your stack:
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'telegram'],
]
Or you can simply change the default logging channel in the .env file.
LOG_CHANNEL=telegram
Great! Your Laravel project can now send logs to your Telegram chat.
You can use Laravel Log Facade to send logs to your chat:
// Use the Laravel Log Facade
use Illuminate\Support\Facades\Log;
...
// All Laravel log leves are avaiable
Log::channel('telegram')->emergency($message);
Log::channel('telegram')->alert($message);
Log::channel('telegram')->critical($message);
Log::channel('telegram')->error($message);
Log::channel('telegram')->warning($message);
Log::channel('telegram')->notice($message);
Log::channel('telegram')->info($message);
Log::channel('telegram')->debug($message);
Instructions for creating a new Telegram Bot and getting chat_id from a particular group or chat.
-
Go to @BotFather on Telegram.
-
Send
/newbot
, to start creating a new Bot. -
Set the bot's username and username.
-
Now you need to allow your Bot to send direct messages, so send
/setjoingroups
to @BotFather, select your Bot and click Enable: -
Get the Bot token and add it to your .env file.
Bot Token in .env:
-
If you want to send messages to a group:
- Add your Bot to a Telegram group.
- Send any message from another user to this group.
-
If you want send direct messages to a user:
- Search for your bot name, and select the chat.
- Send
/start
to your Bot.
-
Visit the following link to get updates about your bot and get chat_id:
https://api.telegram.org/botXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/getUpdates
Replace all X in the URL with your Bot Token.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.