diff --git a/app/Livewire/Notifications/Telegram.php b/app/Livewire/Notifications/Telegram.php index 15ec20577..c83020830 100644 --- a/app/Livewire/Notifications/Telegram.php +++ b/app/Livewire/Notifications/Telegram.php @@ -3,6 +3,7 @@ namespace App\Livewire\Notifications; use App\Models\Team; +use App\Models\TelegramNotificationSettings; use App\Notifications\Test; use Livewire\Attributes\Validate; use Livewire\Component; @@ -11,6 +12,8 @@ class Telegram extends Component { public Team $team; + public TelegramNotificationSettings $settings; + #[Validate(['boolean'])] public bool $telegramEnabled = false; @@ -21,42 +24,76 @@ class Telegram extends Component public ?string $telegramChatId = null; #[Validate(['boolean'])] - public bool $telegramNotificationsTest = false; + public bool $deploymentSuccessTelegramNotifications = false; #[Validate(['boolean'])] - public bool $telegramNotificationsDeployments = false; + public bool $deploymentFailureTelegramNotifications = true; #[Validate(['boolean'])] - public bool $telegramNotificationsStatusChanges = false; + public bool $statusChangeTelegramNotifications = false; #[Validate(['boolean'])] - public bool $telegramNotificationsDatabaseBackups = false; + public bool $backupSuccessTelegramNotifications = false; #[Validate(['boolean'])] - public bool $telegramNotificationsScheduledTasks = false; - - #[Validate(['nullable', 'string'])] - public ?string $telegramNotificationsTestMessageThreadId = null; - - #[Validate(['nullable', 'string'])] - public ?string $telegramNotificationsDeploymentsMessageThreadId = null; - - #[Validate(['nullable', 'string'])] - public ?string $telegramNotificationsStatusChangesMessageThreadId = null; - - #[Validate(['nullable', 'string'])] - public ?string $telegramNotificationsDatabaseBackupsMessageThreadId = null; - - #[Validate(['nullable', 'string'])] - public ?string $telegramNotificationsScheduledTasksThreadId = null; + public bool $backupFailureTelegramNotifications = true; #[Validate(['boolean'])] - public bool $telegramNotificationsServerDiskUsage = false; + public bool $scheduledTaskSuccessTelegramNotifications = false; + + #[Validate(['boolean'])] + public bool $scheduledTaskFailureTelegramNotifications = true; + + #[Validate(['boolean'])] + public bool $dockerCleanupTelegramNotifications = false; + + #[Validate(['boolean'])] + public bool $serverDiskUsageTelegramNotifications = true; + + #[Validate(['boolean'])] + public bool $serverReachableTelegramNotifications = false; + + #[Validate(['boolean'])] + public bool $serverUnreachableTelegramNotifications = true; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsDeploymentSuccessTopicId = null; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsDeploymentFailureTopicId = null; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsStatusChangeTopicId = null; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsBackupSuccessTopicId = null; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsBackupFailureTopicId = null; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsScheduledTaskSuccessTopicId = null; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsScheduledTaskFailureTopicId = null; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsDockerCleanupTopicId = null; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsServerDiskUsageTopicId = null; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsServerReachableTopicId = null; + + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsServerUnreachableTopicId = null; public function mount() { try { $this->team = auth()->user()->currentTeam(); + $this->settings = $this->team->telegramNotificationSettings; $this->syncData(); } catch (\Throwable $e) { return handleError($e, $this); @@ -67,39 +104,65 @@ class Telegram extends Component { if ($toModel) { $this->validate(); - $this->team->telegram_enabled = $this->telegramEnabled; - $this->team->telegram_token = $this->telegramToken; - $this->team->telegram_chat_id = $this->telegramChatId; - $this->team->telegram_notifications_test = $this->telegramNotificationsTest; - $this->team->telegram_notifications_deployments = $this->telegramNotificationsDeployments; - $this->team->telegram_notifications_status_changes = $this->telegramNotificationsStatusChanges; - $this->team->telegram_notifications_database_backups = $this->telegramNotificationsDatabaseBackups; - $this->team->telegram_notifications_scheduled_tasks = $this->telegramNotificationsScheduledTasks; - $this->team->telegram_notifications_test_message_thread_id = $this->telegramNotificationsTestMessageThreadId; - $this->team->telegram_notifications_deployments_message_thread_id = $this->telegramNotificationsDeploymentsMessageThreadId; - $this->team->telegram_notifications_status_changes_message_thread_id = $this->telegramNotificationsStatusChangesMessageThreadId; - $this->team->telegram_notifications_database_backups_message_thread_id = $this->telegramNotificationsDatabaseBackupsMessageThreadId; - $this->team->telegram_notifications_scheduled_tasks_thread_id = $this->telegramNotificationsScheduledTasksThreadId; - $this->team->telegram_notifications_server_disk_usage = $this->telegramNotificationsServerDiskUsage; - $this->team->save(); + $this->settings->telegram_enabled = $this->telegramEnabled; + $this->settings->telegram_token = $this->telegramToken; + $this->settings->telegram_chat_id = $this->telegramChatId; + + $this->settings->deployment_success_telegram_notifications = $this->deploymentSuccessTelegramNotifications; + $this->settings->deployment_failure_telegram_notifications = $this->deploymentFailureTelegramNotifications; + $this->settings->status_change_telegram_notifications = $this->statusChangeTelegramNotifications; + $this->settings->backup_success_telegram_notifications = $this->backupSuccessTelegramNotifications; + $this->settings->backup_failure_telegram_notifications = $this->backupFailureTelegramNotifications; + $this->settings->scheduled_task_success_telegram_notifications = $this->scheduledTaskSuccessTelegramNotifications; + $this->settings->scheduled_task_failure_telegram_notifications = $this->scheduledTaskFailureTelegramNotifications; + $this->settings->docker_cleanup_telegram_notifications = $this->dockerCleanupTelegramNotifications; + $this->settings->server_disk_usage_telegram_notifications = $this->serverDiskUsageTelegramNotifications; + $this->settings->server_reachable_telegram_notifications = $this->serverReachableTelegramNotifications; + $this->settings->server_unreachable_telegram_notifications = $this->serverUnreachableTelegramNotifications; + + $this->settings->telegram_notifications_deployment_success_topic_id = $this->telegramNotificationsDeploymentSuccessTopicId; + $this->settings->telegram_notifications_deployment_failure_topic_id = $this->telegramNotificationsDeploymentFailureTopicId; + $this->settings->telegram_notifications_status_change_topic_id = $this->telegramNotificationsStatusChangeTopicId; + $this->settings->telegram_notifications_backup_success_topic_id = $this->telegramNotificationsBackupSuccessTopicId; + $this->settings->telegram_notifications_backup_failure_topic_id = $this->telegramNotificationsBackupFailureTopicId; + $this->settings->telegram_notifications_scheduled_task_success_topic_id = $this->telegramNotificationsScheduledTaskSuccessTopicId; + $this->settings->telegram_notifications_scheduled_task_failure_topic_id = $this->telegramNotificationsScheduledTaskFailureTopicId; + $this->settings->telegram_notifications_docker_cleanup_topic_id = $this->telegramNotificationsDockerCleanupTopicId; + $this->settings->telegram_notifications_server_disk_usage_topic_id = $this->telegramNotificationsServerDiskUsageTopicId; + $this->settings->telegram_notifications_server_reachable_topic_id = $this->telegramNotificationsServerReachableTopicId; + $this->settings->telegram_notifications_server_unreachable_topic_id = $this->telegramNotificationsServerUnreachableTopicId; + + $this->settings->save(); refreshSession(); } else { - $this->telegramEnabled = $this->team->telegram_enabled; - $this->telegramToken = $this->team->telegram_token; - $this->telegramChatId = $this->team->telegram_chat_id; - $this->telegramNotificationsTest = $this->team->telegram_notifications_test; - $this->telegramNotificationsDeployments = $this->team->telegram_notifications_deployments; - $this->telegramNotificationsStatusChanges = $this->team->telegram_notifications_status_changes; - $this->telegramNotificationsDatabaseBackups = $this->team->telegram_notifications_database_backups; - $this->telegramNotificationsScheduledTasks = $this->team->telegram_notifications_scheduled_tasks; - $this->telegramNotificationsTestMessageThreadId = $this->team->telegram_notifications_test_message_thread_id; - $this->telegramNotificationsDeploymentsMessageThreadId = $this->team->telegram_notifications_deployments_message_thread_id; - $this->telegramNotificationsStatusChangesMessageThreadId = $this->team->telegram_notifications_status_changes_message_thread_id; - $this->telegramNotificationsDatabaseBackupsMessageThreadId = $this->team->telegram_notifications_database_backups_message_thread_id; - $this->telegramNotificationsScheduledTasksThreadId = $this->team->telegram_notifications_scheduled_tasks_thread_id; - $this->telegramNotificationsServerDiskUsage = $this->team->telegram_notifications_server_disk_usage; - } + $this->telegramEnabled = $this->settings->telegram_enabled; + $this->telegramToken = $this->settings->telegram_token; + $this->telegramChatId = $this->settings->telegram_chat_id; + $this->deploymentSuccessTelegramNotifications = $this->settings->deployment_success_telegram_notifications; + $this->deploymentFailureTelegramNotifications = $this->settings->deployment_failure_telegram_notifications; + $this->statusChangeTelegramNotifications = $this->settings->status_change_telegram_notifications; + $this->backupSuccessTelegramNotifications = $this->settings->backup_success_telegram_notifications; + $this->backupFailureTelegramNotifications = $this->settings->backup_failure_telegram_notifications; + $this->scheduledTaskSuccessTelegramNotifications = $this->settings->scheduled_task_success_telegram_notifications; + $this->scheduledTaskFailureTelegramNotifications = $this->settings->scheduled_task_failure_telegram_notifications; + $this->dockerCleanupTelegramNotifications = $this->settings->docker_cleanup_telegram_notifications; + $this->serverDiskUsageTelegramNotifications = $this->settings->server_disk_usage_telegram_notifications; + $this->serverReachableTelegramNotifications = $this->settings->server_reachable_telegram_notifications; + $this->serverUnreachableTelegramNotifications = $this->settings->server_unreachable_telegram_notifications; + + $this->telegramNotificationsDeploymentSuccessTopicId = $this->settings->telegram_notifications_deployment_success_topic_id; + $this->telegramNotificationsDeploymentFailureTopicId = $this->settings->telegram_notifications_deployment_failure_topic_id; + $this->telegramNotificationsStatusChangeTopicId = $this->settings->telegram_notifications_status_change_topic_id; + $this->telegramNotificationsBackupSuccessTopicId = $this->settings->telegram_notifications_backup_success_topic_id; + $this->telegramNotificationsBackupFailureTopicId = $this->settings->telegram_notifications_backup_failure_topic_id; + $this->telegramNotificationsScheduledTaskSuccessTopicId = $this->settings->telegram_notifications_scheduled_task_success_topic_id; + $this->telegramNotificationsScheduledTaskFailureTopicId = $this->settings->telegram_notifications_scheduled_task_failure_topic_id; + $this->telegramNotificationsDockerCleanupTopicId = $this->settings->telegram_notifications_docker_cleanup_topic_id; + $this->telegramNotificationsServerDiskUsageTopicId = $this->settings->telegram_notifications_server_disk_usage_topic_id; + $this->telegramNotificationsServerReachableTopicId = $this->settings->telegram_notifications_server_reachable_topic_id; + $this->telegramNotificationsServerUnreachableTopicId = $this->settings->telegram_notifications_server_unreachable_topic_id; + } } public function instantSave() diff --git a/resources/views/livewire/notifications/telegram.blade.php b/resources/views/livewire/notifications/telegram.blade.php index 76378ada1..790bf3143 100644 --- a/resources/views/livewire/notifications/telegram.blade.php +++ b/resources/views/livewire/notifications/telegram.blade.php @@ -12,7 +12,7 @@ @if ($telegramEnabled) - Send Test Notifications + Send Test Notification @endif @@ -20,7 +20,6 @@
- @@ -28,51 +27,80 @@ id="telegramChatId" label="Chat ID" />
@if ($telegramEnabled) -

Subscribe to events

-
- @if (isDev()) -
-

Test Notification

- - +

Notification Settings

+

+ Select events for which you would like to receive Telegram notifications. +

+
+
+

Backups

+
+

Backup Success

+
+ + +
+ +

Backup Failure

+
+ + +
- @endif -
-

Container Status Changes

- -
-
-

Application Deployments

- - + +
+

Scheduled Tasks

+
+

Scheduled Task Success

+
+ + +
+ +

Scheduled Task Failure

+
+ + +
+
-
-

Database Backup Status

- - -
-
-

Scheduled Tasks Status

- - -
-
-

Server Disk Usage

- + +
+

Server

+
+

Docker Cleanup

+
+ + +
+ +

Server Disk Usage

+
+ + +
+ +

Server Reachable

+
+ + +
+ +

Server Unreachable

+
+ + +
+
@endif