From 737d54e3e450fcc2704b2b871c46ecb0519e34c1 Mon Sep 17 00:00:00 2001 From: JFC <47096567+MrCaringi@users.noreply.github.com> Date: Thu, 17 Apr 2025 03:46:48 +0000 Subject: [PATCH] [Feature] Enhance Telegram notifications with message thread support --- app/Actions/Notifications/SendTelegramTestNotification.php | 4 ++-- app/Notifications/Telegram/SpeedtestNotification.php | 4 +++- app/Notifications/Telegram/TestNotification.php | 7 +++++-- package-lock.json | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Actions/Notifications/SendTelegramTestNotification.php b/app/Actions/Notifications/SendTelegramTestNotification.php index c7c64a815..94f81a523 100644 --- a/app/Actions/Notifications/SendTelegramTestNotification.php +++ b/app/Actions/Notifications/SendTelegramTestNotification.php @@ -11,7 +11,7 @@ class SendTelegramTestNotification { use AsAction; - public function handle(array $recipients) + public function handle(array $recipients, ?int $messageThreadId = null) { if (! count($recipients)) { Notification::make() @@ -24,7 +24,7 @@ public function handle(array $recipients) foreach ($recipients as $recipient) { FacadesNotification::route('telegram_chat_id', $recipient['telegram_chat_id']) - ->notify(new TestNotification); + ->notify(new TestNotification($messageThreadId)); } Notification::make() diff --git a/app/Notifications/Telegram/SpeedtestNotification.php b/app/Notifications/Telegram/SpeedtestNotification.php index 5317f7bf9..02f239c54 100644 --- a/app/Notifications/Telegram/SpeedtestNotification.php +++ b/app/Notifications/Telegram/SpeedtestNotification.php @@ -17,6 +17,7 @@ class SpeedtestNotification extends Notification implements ShouldQueue public function __construct( public string $content, public bool $disableNotification = false, + public ?int $messageThreadId = null, ) {} /** @@ -39,6 +40,7 @@ public function toTelegram($notifiable): TelegramMessage return TelegramMessage::create() ->to($notifiable->routes['telegram_chat_id']) ->content($this->content) - ->disableNotification($this->disableNotification); + ->disableNotification($this->disableNotification) + ->options(['message_thread_id' => $this->messageThreadId]); } } diff --git a/app/Notifications/Telegram/TestNotification.php b/app/Notifications/Telegram/TestNotification.php index 111ddc47d..4cd278028 100644 --- a/app/Notifications/Telegram/TestNotification.php +++ b/app/Notifications/Telegram/TestNotification.php @@ -13,15 +13,17 @@ class TestNotification extends Notification implements ShouldQueue use Queueable; protected $settings; + protected ?int $messageThreadId; /** * Create a new notification instance. * * @return void */ - public function __construct() + public function __construct(?int $messageThreadId = null) { $this->settings = new NotificationSettings; + $this->messageThreadId = $messageThreadId; } /** @@ -43,7 +45,8 @@ public function toTelegram(object $notifiable): TelegramMessage { return TelegramMessage::create() ->to($notifiable->routes['telegram_chat_id']) + ->content('👋 Testing the Telegram notification channel.') ->disableNotification($this->settings->telegram_disable_notification) - ->content('👋 Testing the Telegram notification channel.'); + ->options(['message_thread_id' => $this->messageThreadId]); } } diff --git a/package-lock.json b/package-lock.json index a7e3f6825..779226e9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "html", + "name": "speedtest-tracker", "lockfileVersion": 3, "requires": true, "packages": {