From edc3b014cdd558c10618519287a84c2f519c4836 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 17 May 2024 12:09:22 +0200 Subject: [PATCH] fix: telegram group chat notifications --- app/Jobs/ApplicationDeploymentJob.php | 5 +--- .../Application/DeploymentSuccess.php | 7 ++++- .../Channels/TelegramChannel.php | 14 +++++----- .../livewire/notifications/telegram.blade.php | 26 +++++++++++-------- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 9e05962ba..8f9c14206 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1969,10 +1969,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); if (!$this->only_this_server) { $this->deploy_to_additional_destinations(); } - if (!isCloud()) { - // TODO: turn off until we have a better solution - $this->application->environment->project->team?->notify(new DeploymentSuccess($this->application, $this->deployment_uuid, $this->preview)); - } + $this->application->environment->project->team?->notify(new DeploymentSuccess($this->application, $this->deployment_uuid, $this->preview)); } } diff --git a/app/Notifications/Application/DeploymentSuccess.php b/app/Notifications/Application/DeploymentSuccess.php index 816dac19d..e138ac91e 100644 --- a/app/Notifications/Application/DeploymentSuccess.php +++ b/app/Notifications/Application/DeploymentSuccess.php @@ -43,7 +43,12 @@ class DeploymentSuccess extends Notification implements ShouldQueue public function via(object $notifiable): array { - return setNotificationChannels($notifiable, 'deployments'); + $channels = setNotificationChannels($notifiable, 'deployments'); + if (isCloud()) { + // TODO: Make batch notifications work with email + $channels = array_diff($channels, ['App\Notifications\Channels\EmailChannel']); + } + return $channels; } public function toMail(): MailMessage { diff --git a/app/Notifications/Channels/TelegramChannel.php b/app/Notifications/Channels/TelegramChannel.php index 1401bb324..12695497a 100644 --- a/app/Notifications/Channels/TelegramChannel.php +++ b/app/Notifications/Channels/TelegramChannel.php @@ -14,20 +14,22 @@ class TelegramChannel $buttons = data_get($data, 'buttons', []); $telegramToken = data_get($telegramData, 'token'); $chatId = data_get($telegramData, 'chat_id'); - $topicId = null; + $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': + case 'App\Notifications\Application\StatusChanged': + $topicId = data_get($notifiable, 'telegram_notifications_status_changes_message_thread_id'); + break; + case 'App\Notifications\Application\DeploymentSuccess': + case 'App\Notifications\Application\DeploymentFailed': $topicId = data_get($notifiable, 'telegram_notifications_deployments_message_thread_id'); break; - case 'App\Notifications\DatabaseBackup': + case 'App\Notifications\Database\BackupSuccess': + case 'App\Notifications\Database\BackupFailed': $topicId = data_get($notifiable, 'telegram_notifications_database_backups_message_thread_id'); break; } diff --git a/resources/views/livewire/notifications/telegram.blade.php b/resources/views/livewire/notifications/telegram.blade.php index 4925b9f75..1d8e1231c 100644 --- a/resources/views/livewire/notifications/telegram.blade.php +++ b/resources/views/livewire/notifications/telegram.blade.php @@ -7,7 +7,7 @@ Save @if ($team->telegram_enabled) - Send Test Notifications @@ -18,40 +18,44 @@
@if (data_get($team, 'telegram_enabled'))

Subscribe to events

-
+
@if (isDev()) -
+
+

Test Notification

+ label="Enabled" />
@endif -
+
+

Container Status Changes

+ label="Enabled" />
-
+
+

Application Deployments

+ label="Enabled" />
-
+
+

Database Backup Status

+ label="Enabled" />