Skip to content

Commit 737d54e

Browse files
committed
[Feature] Enhance Telegram notifications with message thread support
1 parent b6c34e8 commit 737d54e

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

app/Actions/Notifications/SendTelegramTestNotification.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SendTelegramTestNotification
1111
{
1212
use AsAction;
1313

14-
public function handle(array $recipients)
14+
public function handle(array $recipients, ?int $messageThreadId = null)
1515
{
1616
if (! count($recipients)) {
1717
Notification::make()
@@ -24,7 +24,7 @@ public function handle(array $recipients)
2424

2525
foreach ($recipients as $recipient) {
2626
FacadesNotification::route('telegram_chat_id', $recipient['telegram_chat_id'])
27-
->notify(new TestNotification);
27+
->notify(new TestNotification($messageThreadId));
2828
}
2929

3030
Notification::make()

app/Notifications/Telegram/SpeedtestNotification.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class SpeedtestNotification extends Notification implements ShouldQueue
1717
public function __construct(
1818
public string $content,
1919
public bool $disableNotification = false,
20+
public ?int $messageThreadId = null,
2021
) {}
2122

2223
/**
@@ -39,6 +40,7 @@ public function toTelegram($notifiable): TelegramMessage
3940
return TelegramMessage::create()
4041
->to($notifiable->routes['telegram_chat_id'])
4142
->content($this->content)
42-
->disableNotification($this->disableNotification);
43+
->disableNotification($this->disableNotification)
44+
->options(['message_thread_id' => $this->messageThreadId]);
4345
}
4446
}

app/Notifications/Telegram/TestNotification.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ class TestNotification extends Notification implements ShouldQueue
1313
use Queueable;
1414

1515
protected $settings;
16+
protected ?int $messageThreadId;
1617

1718
/**
1819
* Create a new notification instance.
1920
*
2021
* @return void
2122
*/
22-
public function __construct()
23+
public function __construct(?int $messageThreadId = null)
2324
{
2425
$this->settings = new NotificationSettings;
26+
$this->messageThreadId = $messageThreadId;
2527
}
2628

2729
/**
@@ -43,7 +45,8 @@ public function toTelegram(object $notifiable): TelegramMessage
4345
{
4446
return TelegramMessage::create()
4547
->to($notifiable->routes['telegram_chat_id'])
48+
->content('👋 Testing the Telegram notification channel.')
4649
->disableNotification($this->settings->telegram_disable_notification)
47-
->content('👋 Testing the Telegram notification channel.');
50+
->options(['message_thread_id' => $this->messageThreadId]);
4851
}
4952
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)