itpekov / telegram-message
Send message to Telegram channel via bot
1.0.2
2024-05-25 02:31 UTC
Requires
- php: ^8.1
Requires (Dev)
- guzzlehttp/guzzle: ^7.8
- larastan/larastan: ^2.0
- laravel/pint: ^1.15
- orchestra/testbench: ^9.0.0||^8.22.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2025-01-02 00:33:41 UTC
README
Installation
You can install the package via composer:
composer require itpekov/telegram-message
Add in .env
file variables:
TELEGRAM_CHAT_ID=your_chat_id TELEGRAM_BOT_TOKEN=your_bot_token
Usage
Scenario 1: send message from any place with:
Telegram::sendMessage('Your message');
Scenario 2: send exception messages with
Telegram::sendExceptionMessage($e);
Scenario 3: send all unhandled exceptions from your app
by adding/updating report
method in Handler.php
class
use Itpekov\TelegramMessage\Facades\Telegram; public function report(Throwable $e) { $e = $this->mapException($e); if ($this->shouldntReport($e)) { return; } Telegram::sendExceptionMessage($e); $this->reportThrowable($e); }
Customization
Optionally, You can publish the config file with:
php artisan vendor:publish --provider="Itpekov\TelegramMessage\TelegramMessageServiceProvider" --tag="config"
This is the contents of the published config file:
return [ 'chat_id' => env('TELEGRAM_CHAT_ID'), 'bot_token' => env('TELEGRAM_BOT_TOKEN'), ];
Optionally, you can publish the views using
php artisan vendor:publish --provider="Itpekov\TelegramMessage\TelegramMessageServiceProvider" --tag="views"
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.