team = auth()->user()->currentTeam(); $this->syncData(); } catch (\Throwable $e) { return handleError($e, $this); } } public function syncData(bool $toModel = false) { 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(); 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; } } public function instantSave() { try { $this->syncData(true); } catch (\Throwable $e) { return handleError($e, $this); } } public function submit() { try { $this->resetErrorBag(); $this->syncData(true); $this->saveModel(); } catch (\Throwable $e) { return handleError($e, $this); } } public function instantSaveTelegramEnabled() { try { $this->validate([ 'telegramToken' => 'required', 'telegramChatId' => 'required', ], [ 'telegramToken.required' => 'Telegram Token is required.', 'telegramChatId.required' => 'Telegram Chat ID is required.', ]); $this->saveModel(); } catch (\Throwable $e) { $this->telegramEnabled = false; return handleError($e, $this); } } public function saveModel() { $this->syncData(true); refreshSession(); $this->dispatch('success', 'Settings saved.'); } public function sendTestNotification() { try { $this->team->notify(new Test); $this->dispatch('success', 'Test notification sent.'); } catch (\Throwable $e) { return handleError($e, $this); } } public function render() { return view('livewire.notifications.telegram'); } }