fix: telegram group chat notifications

This commit is contained in:
Andras Bacsai 2024-05-17 12:09:22 +02:00
parent fec98f45ce
commit edc3b014cd
4 changed files with 30 additions and 22 deletions

View File

@ -1969,12 +1969,9 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
if (!$this->only_this_server) { if (!$this->only_this_server) {
$this->deploy_to_additional_destinations(); $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));
} }
} }
}
public function failed(Throwable $exception): void public function failed(Throwable $exception): void
{ {

View File

@ -43,7 +43,12 @@ class DeploymentSuccess extends Notification implements ShouldQueue
public function via(object $notifiable): array 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 public function toMail(): MailMessage
{ {

View File

@ -18,16 +18,18 @@ class TelegramChannel
$topicsInstance = get_class($notification); $topicsInstance = get_class($notification);
switch ($topicsInstance) { switch ($topicsInstance) {
case 'App\Notifications\StatusChange':
$topicId = data_get($notifiable, 'telegram_notifications_status_changes_message_thread_id');
break;
case 'App\Notifications\Test': case 'App\Notifications\Test':
$topicId = data_get($notifiable, 'telegram_notifications_test_message_thread_id'); $topicId = data_get($notifiable, 'telegram_notifications_test_message_thread_id');
break; 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'); $topicId = data_get($notifiable, 'telegram_notifications_deployments_message_thread_id');
break; 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'); $topicId = data_get($notifiable, 'telegram_notifications_database_backups_message_thread_id');
break; break;
} }

View File

@ -7,7 +7,7 @@
Save Save
</x-forms.button> </x-forms.button>
@if ($team->telegram_enabled) @if ($team->telegram_enabled)
<x-forms.button class="dark:text-white normal-case btn btn-xs no-animation btn-primary" <x-forms.button class="normal-case dark:text-white btn btn-xs no-animation btn-primary"
wire:click="sendTestNotification"> wire:click="sendTestNotification">
Send Test Notifications Send Test Notifications
</x-forms.button> </x-forms.button>
@ -18,40 +18,44 @@
</div> </div>
<div class="flex gap-2"> <div class="flex gap-2">
<x-forms.input type="password" <x-forms.input type="password"
helper="Get it from the <a class='inline-block dark:text-white underline' href='https://t.me/botfather' target='_blank'>BotFather Bot</a> on Telegram." helper="Get it from the <a class='inline-block underline dark:text-white' href='https://t.me/botfather' target='_blank'>BotFather Bot</a> on Telegram."
required id="team.telegram_token" label="Token" /> required id="team.telegram_token" label="Token" />
<x-forms.input helper="Recommended to add your bot to a group chat and add its Chat ID here." required <x-forms.input helper="Recommended to add your bot to a group chat and add its Chat ID here." required
id="team.telegram_chat_id" label="Chat ID" /> id="team.telegram_chat_id" label="Chat ID" />
</div> </div>
@if (data_get($team, 'telegram_enabled')) @if (data_get($team, 'telegram_enabled'))
<h2 class="mt-4">Subscribe to events</h2> <h2 class="mt-4">Subscribe to events</h2>
<div class="w-96"> <div class="flex flex-col gap-4 w-96">
@if (isDev()) @if (isDev())
<div class="w-64"> <div class="flex flex-col">
<h4>Test Notification</h4>
<x-forms.checkbox instantSave="saveModel" id="team.telegram_notifications_test" <x-forms.checkbox instantSave="saveModel" id="team.telegram_notifications_test"
label="Test" /> label="Enabled" />
<x-forms.input <x-forms.input
helper="If you are using Group chat with Topics, you can specify the topics ID. If empty, General topic will be used." helper="If you are using Group chat with Topics, you can specify the topics ID. If empty, General topic will be used."
id="team.telegram_notifications_test_message_thread_id" label="Custom Topic ID" /> id="team.telegram_notifications_test_message_thread_id" label="Custom Topic ID" />
</div> </div>
@endif @endif
<div class="w-64"> <div class="flex flex-col">
<h4>Container Status Changes</h4>
<x-forms.checkbox instantSave="saveModel" id="team.telegram_notifications_status_changes" <x-forms.checkbox instantSave="saveModel" id="team.telegram_notifications_status_changes"
label="Container Status Changes" /> label="Enabled" />
<x-forms.input <x-forms.input
helper="If you are using Group chat with Topics, you can specify the topics ID. If empty, General topic will be used." helper="If you are using Group chat with Topics, you can specify the topics ID. If empty, General topic will be used."
id="team.telegram_notifications_status_changes_message_thread_id" label="Custom Topic ID" /> id="team.telegram_notifications_status_changes_message_thread_id" label="Custom Topic ID" />
</div> </div>
<div class="w-64"> <div class="flex flex-col">
<h4>Application Deployments</h4>
<x-forms.checkbox instantSave="saveModel" id="team.telegram_notifications_deployments" <x-forms.checkbox instantSave="saveModel" id="team.telegram_notifications_deployments"
label="Application Deployments" /> label="Enabled" />
<x-forms.input <x-forms.input
helper="If you are using Group chat with Topics, you can specify the topics ID. If empty, General topic will be used." helper="If you are using Group chat with Topics, you can specify the topics ID. If empty, General topic will be used."
id="team.telegram_notifications_deployments_message_thread_id" label="Custom Topic ID" /> id="team.telegram_notifications_deployments_message_thread_id" label="Custom Topic ID" />
</div> </div>
<div class="w-64"> <div class="flex flex-col">
<h4>Database Backup Status</h4>
<x-forms.checkbox instantSave="saveModel" id="team.telegram_notifications_database_backups" <x-forms.checkbox instantSave="saveModel" id="team.telegram_notifications_database_backups"
label="Backup Status" /> label="Enabled" />
<x-forms.input <x-forms.input
helper="If you are using Group chat with Topics, you can specify the topics ID. If empty, General topic will be used." helper="If you are using Group chat with Topics, you can specify the topics ID. If empty, General topic will be used."
id="team.telegram_notifications_database_backups_message_thread_id" label="Custom Topic ID" /> id="team.telegram_notifications_database_backups_message_thread_id" label="Custom Topic ID" />