Skip to content

Commit 2d8a0df

Browse files
authored
Merge pull request #39 from akbarhps/master
feat: support sendMessage to group topic #38
2 parents 010d95c + f2fecb6 commit 2d8a0df

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

config/telegram-logger.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// Telegram chat id
88
'chat_id' => env('TELEGRAM_LOGGER_CHAT_ID'),
99

10+
// Telegram message thread id
11+
'message_thread_id' => env('TELEGRAM_LOGGER_MESSAGE_THREAD_ID', null),
12+
1013
// Blade Template to use formatting logs
1114
'template' => env('TELEGRAM_LOGGER_TEMPLATE', 'laravel-telegram-logging::standard'),
1215

src/TelegramHandler.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ class TelegramHandler extends AbstractProcessingHandler
3737
*/
3838
private $chatId;
3939

40+
/**
41+
* Message thread id for bot
42+
*
43+
* @var int|null
44+
*/
45+
private $messageThreadId;
46+
4047
/**
4148
* Application name
4249
*
@@ -62,9 +69,10 @@ public function __construct(array $config)
6269
parent::__construct($level, true);
6370

6471
// define variables for making Telegram request
65-
$this->config = $config;
66-
$this->botToken = $this->getConfigValue('token');
67-
$this->chatId = $this->getConfigValue('chat_id');
72+
$this->config = $config;
73+
$this->botToken = $this->getConfigValue('token');
74+
$this->chatId = $this->getConfigValue('chat_id');
75+
$this->messageThreadId = $this->getConfigValue('message_thread_id');
6876

6977
// define variables for text message
7078
$this->appName = config('app.name');
@@ -133,9 +141,10 @@ private function sendMessage(string $text): void
133141
{
134142
$httpQuery = http_build_query(array_merge(
135143
[
136-
'text' => $text,
137-
'chat_id' => $this->chatId,
138-
'parse_mode' => 'html',
144+
'text' => $text,
145+
'chat_id' => $this->chatId,
146+
'message_thread_id' => $this->messageThreadId,
147+
'parse_mode' => 'html',
139148
],
140149
config('telegram-logger.options', [])
141150
));

0 commit comments

Comments
 (0)