From 2b3db3f824394158881519bd2217fd4cd36d134a Mon Sep 17 00:00:00 2001 From: Akbar Date: Wed, 23 Aug 2023 07:34:33 +0700 Subject: [PATCH 1/3] feat: support sendMessage to group topic #38 --- config/telegram-logger.php | 3 +++ src/TelegramHandler.php | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config/telegram-logger.php b/config/telegram-logger.php index 9cc0a16..83e74d7 100644 --- a/config/telegram-logger.php +++ b/config/telegram-logger.php @@ -7,6 +7,9 @@ // Telegram chat id 'chat_id' => env('TELEGRAM_LOGGER_CHAT_ID'), + // Telegram chat id + 'message_thread_id' => env('TELEGRAM_LOGGER_MESSAGE_THEAD_ID', null), + // Blade Template to use formatting logs 'template' => env('TELEGRAM_LOGGER_TEMPLATE', 'laravel-telegram-logging::standard'), diff --git a/src/TelegramHandler.php b/src/TelegramHandler.php index 86e3d01..e5f13a0 100644 --- a/src/TelegramHandler.php +++ b/src/TelegramHandler.php @@ -37,6 +37,13 @@ class TelegramHandler extends AbstractProcessingHandler */ private $chatId; + /** + * Message thread id for bot + * + * @var int|null + */ + private $messageThreadId; + /** * Application name * @@ -65,6 +72,7 @@ public function __construct(array $config) $this->config = $config; $this->botToken = $this->getConfigValue('token'); $this->chatId = $this->getConfigValue('chat_id'); + $this->messageThreadId = $this->getConfigValue('message_thread_id'); // define variables for text message $this->appName = config('app.name'); @@ -133,9 +141,10 @@ private function sendMessage(string $text): void { $httpQuery = http_build_query(array_merge( [ - 'text' => $text, - 'chat_id' => $this->chatId, - 'parse_mode' => 'html', + 'text' => $text, + 'chat_id' => $this->chatId, + 'message_thead_id' => $this->messageThreadId, + 'parse_mode' => 'html', ], config('telegram-logger.options', []) )); From 2d54e2a268f0c482bee6c1af47e11b0e6e23863e Mon Sep 17 00:00:00 2001 From: Akbar Date: Wed, 23 Aug 2023 07:39:08 +0700 Subject: [PATCH 2/3] fix: wrong comment and indentation --- config/telegram-logger.php | 2 +- src/TelegramHandler.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/telegram-logger.php b/config/telegram-logger.php index 83e74d7..01c42cf 100644 --- a/config/telegram-logger.php +++ b/config/telegram-logger.php @@ -7,7 +7,7 @@ // Telegram chat id 'chat_id' => env('TELEGRAM_LOGGER_CHAT_ID'), - // Telegram chat id + // Telegram message thread id 'message_thread_id' => env('TELEGRAM_LOGGER_MESSAGE_THEAD_ID', null), // Blade Template to use formatting logs diff --git a/src/TelegramHandler.php b/src/TelegramHandler.php index e5f13a0..1155d25 100644 --- a/src/TelegramHandler.php +++ b/src/TelegramHandler.php @@ -69,10 +69,10 @@ public function __construct(array $config) parent::__construct($level, true); // define variables for making Telegram request - $this->config = $config; - $this->botToken = $this->getConfigValue('token'); - $this->chatId = $this->getConfigValue('chat_id'); - $this->messageThreadId = $this->getConfigValue('message_thread_id'); + $this->config = $config; + $this->botToken = $this->getConfigValue('token'); + $this->chatId = $this->getConfigValue('chat_id'); + $this->messageThreadId = $this->getConfigValue('message_thread_id'); // define variables for text message $this->appName = config('app.name'); From 8f5e051a4bdbbe9bbe6d90f24101c112bd8be8f6 Mon Sep 17 00:00:00 2001 From: Akbar Date: Wed, 23 Aug 2023 07:58:00 +0700 Subject: [PATCH 3/3] fix: typo --- config/telegram-logger.php | 2 +- src/TelegramHandler.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/telegram-logger.php b/config/telegram-logger.php index 01c42cf..cb1a8d7 100644 --- a/config/telegram-logger.php +++ b/config/telegram-logger.php @@ -8,7 +8,7 @@ 'chat_id' => env('TELEGRAM_LOGGER_CHAT_ID'), // Telegram message thread id - 'message_thread_id' => env('TELEGRAM_LOGGER_MESSAGE_THEAD_ID', null), + 'message_thread_id' => env('TELEGRAM_LOGGER_MESSAGE_THREAD_ID', null), // Blade Template to use formatting logs 'template' => env('TELEGRAM_LOGGER_TEMPLATE', 'laravel-telegram-logging::standard'), diff --git a/src/TelegramHandler.php b/src/TelegramHandler.php index 1155d25..6c6beca 100644 --- a/src/TelegramHandler.php +++ b/src/TelegramHandler.php @@ -141,10 +141,10 @@ private function sendMessage(string $text): void { $httpQuery = http_build_query(array_merge( [ - 'text' => $text, - 'chat_id' => $this->chatId, - 'message_thead_id' => $this->messageThreadId, - 'parse_mode' => 'html', + 'text' => $text, + 'chat_id' => $this->chatId, + 'message_thread_id' => $this->messageThreadId, + 'parse_mode' => 'html', ], config('telegram-logger.options', []) ));