Skip to content

Repository files navigation

Telegram message

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.

About

Send message to Telegram channel via bot

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages