arus/monolog-telegram-handler

Arus // Monolog Telegram Handler for PHP 7.2+ (incl. PHP 8)

v2.1.0 2021-02-02 14:24 UTC

README

Build Status Code Coverage Scrutinizer Code Quality Total Downloads Latest Stable Version License

Installation (via composer)

composer require 'arus/monolog-telegram-handler:^2.1'

How to use?

use Arus\Monolog\Handler\TelegramHandler;
use Monolog\Logger;

$token = '000000000:000000000ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$recipient = '000000000';

$sender = new TelegramHandler($token, $recipient);

$logger = new Logger('app');
$logger->pushHandler($sender);

$logger->debug('Hello, world!');

Send a photo

$logger->debug('Hello, world!', [
    'photo' => 'https://example.com/photo.jpeg',
]);

Send an animation

$logger->debug('Hello, world!', [
    'animation' => 'https://example.com/animation.gif',
]);

Send a video

$logger->debug('Hello, world!', [
    'video' => 'https://example.com/video.mp4',
]);

Set custom API URL (relevant for Russia)

Via API

$sender->setUrl('https://proxy.api.telegram.example.com');

Via environment

putenv('TELEGRAM_URL=https://proxy.api.telegram.example.com');

Test run

Create your phpunit.xml file:

cp phpunit.xml.dist phpunit.xml

Open your phpunit.xml file and set the following environment variables: TELEGRAM_TOKEN and TELEGRAM_RECIPIENT, then:

php vendor/bin/phpunit --colors=always --coverage-text

Useful links