Skip to content

Commit

Permalink
Merge pull request #39 from akbarhps/master
Browse files Browse the repository at this point in the history
feat: support sendMessage to group topic #38
  • Loading branch information
grkamil authored Dec 23, 2024
2 parents 010d95c + f2fecb6 commit 2d8a0df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions config/telegram-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// Telegram chat id
'chat_id' => env('TELEGRAM_LOGGER_CHAT_ID'),

// Telegram message thread id
'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'),

Expand Down
21 changes: 15 additions & 6 deletions src/TelegramHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class TelegramHandler extends AbstractProcessingHandler
*/
private $chatId;

/**
* Message thread id for bot
*
* @var int|null
*/
private $messageThreadId;

/**
* Application name
*
Expand All @@ -62,9 +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->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');
Expand Down Expand Up @@ -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_thread_id' => $this->messageThreadId,
'parse_mode' => 'html',
],
config('telegram-logger.options', [])
));
Expand Down

0 comments on commit 2d8a0df

Please sign in to comment.