- Add resource UUIDs (application_uuid, database_uuid, server_uuid, task_uuid) to all webhook notifications - Standardize URL field naming from various formats (resource_url, task_url, server_url) to consistent 'url' field - Include parent resource UUIDs for scheduled tasks (application_uuid or service_uuid) - Add direct URLs to Coolify resources for all notification types - Update UI to show "Webhook URL (POST)" label for clarity This enables webhook consumers to: - Uniquely identify resources using UUIDs used throughout Coolify UI - Directly link back to Coolify resource pages via the url field 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
104 lines
3.2 KiB
PHP
104 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications\Database;
|
|
|
|
use App\Models\ScheduledDatabaseBackup;
|
|
use App\Notifications\CustomEmailNotification;
|
|
use App\Notifications\Dto\DiscordMessage;
|
|
use App\Notifications\Dto\PushoverMessage;
|
|
use App\Notifications\Dto\SlackMessage;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
class BackupSuccess extends CustomEmailNotification
|
|
{
|
|
public string $name;
|
|
|
|
public string $frequency;
|
|
|
|
public function __construct(ScheduledDatabaseBackup $backup, public $database, public $database_name)
|
|
{
|
|
$this->onQueue('high');
|
|
|
|
$this->name = $database->name;
|
|
$this->frequency = $backup->frequency;
|
|
}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return $notifiable->getEnabledChannels('backup_success');
|
|
}
|
|
|
|
public function toMail(): MailMessage
|
|
{
|
|
$mail = new MailMessage;
|
|
$mail->subject("Coolify: Backup successfully done for {$this->database->name}");
|
|
$mail->view('emails.backup-success', [
|
|
'name' => $this->name,
|
|
'database_name' => $this->database_name,
|
|
'frequency' => $this->frequency,
|
|
]);
|
|
|
|
return $mail;
|
|
}
|
|
|
|
public function toDiscord(): DiscordMessage
|
|
{
|
|
$message = new DiscordMessage(
|
|
title: ':white_check_mark: Database backup successful',
|
|
description: "Database backup for {$this->name} (db:{$this->database_name}) was successful.",
|
|
color: DiscordMessage::successColor(),
|
|
);
|
|
|
|
$message->addField('Frequency', $this->frequency, true);
|
|
|
|
return $message;
|
|
}
|
|
|
|
public function toTelegram(): array
|
|
{
|
|
$message = "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was successful.";
|
|
|
|
return [
|
|
'message' => $message,
|
|
];
|
|
}
|
|
|
|
public function toPushover(): PushoverMessage
|
|
{
|
|
return new PushoverMessage(
|
|
title: 'Database backup successful',
|
|
level: 'success',
|
|
message: "Database backup for {$this->name} (db:{$this->database_name}) was successful.<br/><br/><b>Frequency:</b> {$this->frequency}.",
|
|
);
|
|
}
|
|
|
|
public function toSlack(): SlackMessage
|
|
{
|
|
$title = 'Database backup successful';
|
|
$description = "Database backup for {$this->name} (db:{$this->database_name}) was successful.";
|
|
|
|
$description .= "\n\n*Frequency:* {$this->frequency}";
|
|
|
|
return new SlackMessage(
|
|
title: $title,
|
|
description: $description,
|
|
color: SlackMessage::successColor()
|
|
);
|
|
}
|
|
|
|
public function toWebhook(): array
|
|
{
|
|
$url = base_url().'/project/'.data_get($this->database, 'environment.project.uuid').'/environment/'.data_get($this->database, 'environment.uuid').'/database/'.$this->database->uuid;
|
|
|
|
return [
|
|
'success' => true,
|
|
'message' => 'Database backup successful',
|
|
'event' => 'backup_success',
|
|
'database_name' => $this->name,
|
|
'database_uuid' => $this->database->uuid,
|
|
'database_type' => $this->database_name,
|
|
'frequency' => $this->frequency,
|
|
'url' => $url,
|
|
];
|
|
}
|
|
}
|