defstudio / laravel-telegram-log
Telegram log channel for Laravel
Installs: 1 350
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: ^7.4|^8.0
- ext-json: *
- illuminate/contracts: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^11.2
- vimeo/psalm: ^5.0
This package is auto-updated.
Last update: 2024-11-12 12:26:03 UTC
README
This is a monolog telegram handler for laravel applications
Installation
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'), ];
Usage
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);
Telegram Instructions
Instructions for creating a new Telegram Bot and getting chat_id from a particular group or chat.
Creating a Bot
-
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:
Getting a Telegram Chat ID
-
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.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.