diff --git a/app/Notifications/ScheduledTask/TaskSuccess.php b/app/Notifications/ScheduledTask/TaskSuccess.php new file mode 100644 index 000000000..aaf9cf14b --- /dev/null +++ b/app/Notifications/ScheduledTask/TaskSuccess.php @@ -0,0 +1,88 @@ +onQueue('high'); + if ($task->application) { + $this->url = $task->application->failedTaskLink($task->uuid); + } elseif ($task->service) { + $this->url = $task->service->failedTaskLink($task->uuid); + } + } + + public function via(object $notifiable): array + { + return $notifiable->getEnabledChannels('scheduled_task_success'); + } + + public function toMail(): MailMessage + { + $mail = new MailMessage; + $mail->subject("Coolify: Scheduled task ({$this->task->name}) succeeded."); + $mail->view('emails.scheduled-task-failed', [ + 'task' => $this->task, + 'url' => $this->url, + 'output' => $this->output, + ]); + + return $mail; + } + + public function toDiscord(): DiscordMessage + { + $message = new DiscordMessage( + title: ':check_mark: Scheduled task succeeded', + description: "Scheduled task ({$this->task->name}) succeeded.", + color: DiscordMessage::successColor(), + ); + + if ($this->url) { + $message->addField('Scheduled task', '[Link]('.$this->url.')'); + } + + return $message; + } + + public function toTelegram(): array + { + $message = "Coolify: Scheduled task ({$this->task->name}) succeeded."; + if ($this->url) { + $buttons[] = [ + 'text' => 'Open task in Coolify', + 'url' => (string) $this->url, + ]; + } + + return [ + 'message' => $message, + ]; + } + + public function toSlack(): SlackMessage + { + $title = 'Scheduled task succeeded'; + $description = "Scheduled task ({$this->task->name}) succeeded."; + + if ($this->url) { + $description .= "\n\n**Task URL:** {$this->url}"; + } + + return new SlackMessage( + title: $title, + description: $description, + color: SlackMessage::successColor() + ); + } +}