itpekov/telegram-message

Send message to Telegram channel via bot

1.0.2 2024-05-25 02:31 UTC

This package is auto-updated.

Last update: 2024-09-08 05:08:48 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

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.