diff --git a/app/Http/Livewire/Notifications/TelegramSettings.php b/app/Http/Livewire/Notifications/TelegramSettings.php
index be7081012..d6c6c8395 100644
--- a/app/Http/Livewire/Notifications/TelegramSettings.php
+++ b/app/Http/Livewire/Notifications/TelegramSettings.php
@@ -17,6 +17,10 @@ class TelegramSettings extends Component
'team.telegram_notifications_deployments' => 'nullable|boolean',
'team.telegram_notifications_status_changes' => 'nullable|boolean',
'team.telegram_notifications_database_backups' => 'nullable|boolean',
+ 'team.telegram_notifications_test_message_thread_id' => 'nullable|string',
+ 'team.telegram_notifications_deployments_message_thread_id' => 'nullable|string',
+ 'team.telegram_notifications_status_changes_message_thread_id' => 'nullable|string',
+ 'team.telegram_notifications_database_backups_message_thread_id' => 'nullable|string',
];
protected $validationAttributes = [
'team.telegram_token' => 'Token',
diff --git a/app/Jobs/SendMessageToTelegramJob.php b/app/Jobs/SendMessageToTelegramJob.php
index 08afbab23..1fa1347c4 100644
--- a/app/Jobs/SendMessageToTelegramJob.php
+++ b/app/Jobs/SendMessageToTelegramJob.php
@@ -31,6 +31,7 @@ public function __construct(
public array $buttons,
public string $token,
public string $chatId,
+ public ?string $topicId = null,
) {
}
@@ -63,7 +64,9 @@ public function handle(): void
'chat_id' => $this->chatId,
'text' => $this->text,
];
- ray($payload);
+ if ($this->topicId) {
+ $payload['message_thread_id'] = $this->topicId;
+ }
$response = Http::post($url, $payload);
if ($response->failed()) {
throw new \Exception('Telegram notification failed with ' . $response->status() . ' status code.' . $response->body());
diff --git a/app/Models/Team.php b/app/Models/Team.php
index 2d7ef3c9e..485811a17 100644
--- a/app/Models/Team.php
+++ b/app/Models/Team.php
@@ -28,7 +28,7 @@ public function routeNotificationForTelegram()
{
return [
"token" => data_get($this, 'telegram_token', null),
- "chat_id" => data_get($this, 'telegram_chat_id', null)
+ "chat_id" => data_get($this, 'telegram_chat_id', null),
];
}
diff --git a/app/Notifications/Channels/TelegramChannel.php b/app/Notifications/Channels/TelegramChannel.php
index 938ef5d25..5dbc7e049 100644
--- a/app/Notifications/Channels/TelegramChannel.php
+++ b/app/Notifications/Channels/TelegramChannel.php
@@ -10,16 +10,30 @@ public function send($notifiable, $notification): void
{
$data = $notification->toTelegram($notifiable);
$telegramData = $notifiable->routeNotificationForTelegram();
-
$message = data_get($data, 'message');
$buttons = data_get($data, 'buttons', []);
- ray($message, $buttons);
$telegramToken = data_get($telegramData, 'token');
$chatId = data_get($telegramData, 'chat_id');
+ $topicId = null;
+ $topicsInstance = get_class($notification);
+ switch ($topicsInstance) {
+ case 'App\Notifications\StatusChange':
+ $topicId = data_get($notifiable, 'telegram_notifications_status_changes_message_thread_id');
+ break;
+ case 'App\Notifications\Test':
+ $topicId = data_get($notifiable, 'telegram_notifications_test_message_thread_id');
+ break;
+ case 'App\Notifications\Deployment':
+ $topicId = data_get($notifiable, 'telegram_notifications_deployments_message_thread_id');
+ break;
+ case 'App\Notifications\DatabaseBackup':
+ $topicId = data_get($notifiable, 'telegram_notifications_database_backups_message_thread_id');
+ break;
+ }
if (!$telegramToken || !$chatId || !$message) {
throw new \Exception('Telegram token, chat id and message are required');
}
- dispatch(new SendMessageToTelegramJob($message, $buttons, $telegramToken, $chatId));
+ dispatch(new SendMessageToTelegramJob($message, $buttons, $telegramToken, $chatId, $topicId));
}
}
diff --git a/database/migrations/2023_08_22_071056_update_telegram_notifications.php b/database/migrations/2023_08_22_071056_update_telegram_notifications.php
new file mode 100644
index 000000000..6e1da18e3
--- /dev/null
+++ b/database/migrations/2023_08_22_071056_update_telegram_notifications.php
@@ -0,0 +1,29 @@
+text('telegram_notifications_test_message_thread_id')->nullable();
+ $table->text('telegram_notifications_deployments_message_thread_id')->nullable();
+ $table->text('telegram_notifications_status_changes_message_thread_id')->nullable();
+ $table->text('telegram_notifications_database_backups_message_thread_id')->nullable();
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::table('teams', function (Blueprint $table) {
+ $table->dropColumn('telegram_message_thread_id');
+ $table->dropColumn('telegram_notifications_test_message_thread_id');
+ $table->dropColumn('telegram_notifications_deployments_message_thread_id');
+ $table->dropColumn('telegram_notifications_status_changes_message_thread_id');
+ $table->dropColumn('telegram_notifications_database_backups_message_thread_id');
+ });
+ }
+};
diff --git a/resources/views/livewire/notifications/telegram-settings.blade.php b/resources/views/livewire/notifications/telegram-settings.blade.php
index 654ca106d..12b62af4d 100644
--- a/resources/views/livewire/notifications/telegram-settings.blade.php
+++ b/resources/views/livewire/notifications/telegram-settings.blade.php
@@ -16,27 +16,50 @@