2017 © Pedro Peláez
 

library telegram-handler

Monolog handler to send log by Telegram

image

jokaorgua/telegram-handler

Monolog handler to send log by Telegram

  • Saturday, May 19, 2018
  • by jokaorgua
  • Repository
  • 1 Watchers
  • 0 Stars
  • 48 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

TelegramHandler

SensioLabsInsight Build Status Coverage Status Latest Stable Version Total Downloads License, (*1)

Monolog handler to send log by Telegram., (*2)

Requirements

  • PHP 5.6 or above

Instalation with composer

  1. Open your project directory;
  2. Run composer require mero/telegram-handler to add TelegramHandler in your project vendor.

Declaring handler object

To declare this handler, you need to know the bot token and the chat identifier(chat_id) to which the log will be sent., (*3)

// ...
$handler = new \Mero\Monolog\Handler\TelegramHandler('<token>', <chat_id>, <log_level>);
// ...

Example:, (*4)

<?php

$log = new \Monolog\Logger('telegram_channel');

$handler = new \Mero\Monolog\Handler\TelegramHandler(
    '000000000:XXXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    111111111,
    \Monolog\Logger::DEBUG
);
$handler->setFormatter(new \Monolog\Formatter\LineFormatter());
$log->pushHandler($handler);

$log->debug('Message log');

Creating a bot

To use this handler, you need to create your bot on telegram and receive the Bot API access token. To do this, start a conversation with @BotFather., (*5)

Conversation example:, (*6)

In the example below, I'm talking to @BotFather. to create a bot named "Cronus Bot" with user "@cronus_bot"., (*7)

Me: /newbot
---
@BotFather: Alright, a new bot. How are we going to call it? Please choose a name for your bot.
---
Me: Cronus Bot
---
@BotFather: Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: 
TetrisBot or tetris_bot.
---
Me: cronus_bot
---
@BotFather: Done! Congratulations on your new bot. You will find it at telegram.me/cronus_bot. You can now add a 
description, about section and profile picture for your bot, see /help for a list of commands. By the way, when 
you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure 
the bot is fully operational before you do this.

Use this token to access the HTTP API:
000000000:XXXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

For a description of the Bot API, see this page: https://core.telegram.org/bots/api

Give a chat identifier

To retrieve the chat_id in which the log will be sent, the recipient user will first need a conversation with the bot. After the conversation has started, make the request below to know the chat_id of that conversation., (*8)

URL: https://api.telegram.org/bot_token_/getUpdates, (*9)

Example:, (*10)

Request
-------
POST https://api.telegram.org/bot000000000:XXXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/getUpdates

Response
--------
{
  "ok": true,
  "result": [
    {
      "update_id": 141444845,
      "message": {
        "message_id": 111,
        "from": {
          "id": 111111111,
          "first_name": "Rafael",
          "last_name": "Mello",
          "username": "merorafael"
        },
        "chat": {
          "id": 111111111,
          "first_name": "Rafael",
          "last_name": "Mello",
          "username": "merorafael",
          "type": "private"
        },
        "date": 1480701504,
        "text": "test"
      }
    }
  ]
}

In the above request, the chat_id is represented by the number "111111111"., (*11)

The Versions

19/05 2018

dev-master

9999999-dev

Monolog handler to send log by Telegram

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Kovalenko

log logging monolog telegram

19/05 2018

0.2.2

0.2.2.0

Monolog handler to send log by Telegram

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Kovalenko

log logging monolog telegram

03/02 2018

0.2.1

0.2.1.0

Monolog handler to send log by Telegram

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Kovalenko

log logging monolog telegram

02/12 2016

0.2.0

0.2.0.0

Monolog handler to send log by Telegram

  Sources   Download

MIT

The Requires

 

The Development Requires

log logging monolog telegram

18/10 2016

0.1.0

0.1.0.0

Monolog handler to send log by Telegram

  Sources   Download

MIT

The Requires

 

The Development Requires

log logging monolog telegram