TelegramBotHandler
extends AbstractProcessingHandler
in package
Handler send logs to Telegram using Telegram Bot API.
How to use:
- Create telegram bot with https://telegram.me/BotFather
- Create a telegram channel where logs will be recorded.
- Add created bot from step 1 to the created channel from step 2.
Use telegram bot API key from step 1 and channel name with '@' prefix from step 2 to create instance of TelegramBotHandler
Tags
Table of Contents
- AVAILABLE_PARSE_MODES = ['HTML', 'MarkdownV2', 'Markdown']
- BOT_API = 'https://api.telegram.org/bot'
- $bubble : mixed
- $formatter : FormatterInterface
- $level : mixed
- $processors : mixed
- $apiKey : string
- Telegram bot access token provided by BotFather.
- $channel : string
- Telegram channel name.
- $disableNotification : bool|null
- Sends the message silently. Users will receive a notification with no sound.
- $disableWebPagePreview : bool|null
- Disables link previews for links in the message.
- $parseMode : string|null
- The kind of formatting that is used for the message.
- __construct() : mixed
- __destruct() : mixed
- close() : mixed
- Closes the handler.
- disableNotification() : self
- disableWebPagePreview() : self
- getBubble() : bool
- Gets the bubbling behavior.
- getFormatter() : FormatterInterface
- Gets the formatter.
- getLevel() : int
- Gets minimum logging level at which this handler will be triggered.
- handle() : mixed
- {@inheritdoc}
- handleBatch() : mixed
- Handles a set of records at once.
- isHandling() : bool
- Checks whether the given record will be handled by this handler.
- popProcessor() : callable
- Removes the processor on top of the stack and returns it.
- pushProcessor() : self
- Adds a processor in the stack.
- reset() : mixed
- setBubble() : self
- Sets the bubbling behavior.
- setFormatter() : self
- Sets the formatter.
- setLevel() : self
- Sets minimum logging level at which this handler will be triggered.
- setParseMode() : self
- getDefaultFormatter() : FormatterInterface
- Gets the default formatter.
- processRecord() : array<string|int, mixed>
- Processes a record.
- send() : void
- Send request to @link https://api.telegram.org/bot on SendMessage action.
- write() : void
- Writes the record down to the log of the implementing handler
Constants
AVAILABLE_PARSE_MODES
private
array<string|int, mixed>
AVAILABLE_PARSE_MODES
= ['HTML', 'MarkdownV2', 'Markdown']
AVAILABLE_PARSE_MODES The available values of parseMode according to the Telegram api documentation
BOT_API
private
mixed
BOT_API
= 'https://api.telegram.org/bot'
Properties
$bubble
protected
mixed
$bubble
= true
$formatter
protected
FormatterInterface
$formatter
$level
protected
mixed
$level
= MonologLogger::DEBUG
$processors
protected
mixed
$processors
= array()
$apiKey
Telegram bot access token provided by BotFather.
private
string
$apiKey
Create telegram bot with https://telegram.me/BotFather and use access token from it.
$channel
Telegram channel name.
private
string
$channel
Since to start with '@' symbol as prefix.
$disableNotification
Sends the message silently. Users will receive a notification with no sound.
private
bool|null
$disableNotification
$disableWebPagePreview
Disables link previews for links in the message.
private
bool|null
$disableWebPagePreview
$parseMode
The kind of formatting that is used for the message.
private
string|null
$parseMode
See available options at https://core.telegram.org/bots/api#formatting-options or in AVAILABLE_PARSE_MODES
Methods
__construct()
public
__construct(string $apiKey, string $channel[, mixed $level = Logger::DEBUG ][, bool $bubble = true ][, string $parseMode = null ][, bool $disableWebPagePreview = null ][, bool $disableNotification = null ]) : mixed
Parameters
- $apiKey : string
-
Telegram bot access token provided by BotFather
- $channel : string
-
Telegram channel name
- $level : mixed = Logger::DEBUG
- $bubble : bool = true
- $parseMode : string = null
- $disableWebPagePreview : bool = null
- $disableNotification : bool = null
Tags
Return values
mixed —__destruct()
public
__destruct() : mixed
Return values
mixed —close()
Closes the handler.
public
close() : mixed
This will be called automatically when the object is destroyed
Return values
mixed —disableNotification()
public
disableNotification([bool $disableNotification = null ]) : self
Parameters
- $disableNotification : bool = null
Return values
self —disableWebPagePreview()
public
disableWebPagePreview([bool $disableWebPagePreview = null ]) : self
Parameters
- $disableWebPagePreview : bool = null
Return values
self —getBubble()
Gets the bubbling behavior.
public
getBubble() : bool
Return values
bool —true means that this handler allows bubbling. false means that bubbling is not permitted.
getFormatter()
Gets the formatter.
public
getFormatter() : FormatterInterface
Return values
FormatterInterface —getLevel()
Gets minimum logging level at which this handler will be triggered.
public
getLevel() : int
Return values
int —handle()
{@inheritdoc}
public
handle(array<string|int, mixed> $record) : mixed
Parameters
- $record : array<string|int, mixed>
Return values
mixed —handleBatch()
Handles a set of records at once.
public
handleBatch(array<string|int, mixed> $records) : mixed
Parameters
- $records : array<string|int, mixed>
-
The records to handle (an array of record arrays)
Return values
mixed —isHandling()
Checks whether the given record will be handled by this handler.
public
isHandling(array<string|int, mixed> $record) : bool
Parameters
- $record : array<string|int, mixed>
-
Partial log record containing only a level key
Return values
bool —popProcessor()
Removes the processor on top of the stack and returns it.
public
popProcessor() : callable
Return values
callable —pushProcessor()
Adds a processor in the stack.
public
pushProcessor(mixed $callback) : self
Parameters
- $callback : mixed
Return values
self —reset()
public
reset() : mixed
Return values
mixed —setBubble()
Sets the bubbling behavior.
public
setBubble(bool $bubble) : self
Parameters
- $bubble : bool
-
true means that this handler allows bubbling. false means that bubbling is not permitted.
Return values
self —setFormatter()
Sets the formatter.
public
setFormatter(FormatterInterface $formatter) : self
Parameters
- $formatter : FormatterInterface
Return values
self —setLevel()
Sets minimum logging level at which this handler will be triggered.
public
setLevel(int|string $level) : self
Parameters
- $level : int|string
-
Level or level name
Return values
self —setParseMode()
public
setParseMode([string $parseMode = null ]) : self
Parameters
- $parseMode : string = null
Return values
self —getDefaultFormatter()
Gets the default formatter.
protected
getDefaultFormatter() : FormatterInterface
Return values
FormatterInterface —processRecord()
Processes a record.
protected
processRecord(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
- $record : array<string|int, mixed>
Return values
array<string|int, mixed> —send()
Send request to @link https://api.telegram.org/bot on SendMessage action.
protected
send(string $message) : void
Parameters
- $message : string
Return values
void —write()
Writes the record down to the log of the implementing handler
protected
write(array<string|int, mixed> $record) : void
Parameters
- $record : array<string|int, mixed>