coolify/app/Notifications/Container/ContainerRestarted.php

63 lines
1.7 KiB
PHP
Raw Normal View History

2023-09-14 12:45:50 +02:00
<?php
namespace App\Notifications\Container;
use App\Models\Server;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class ContainerRestarted extends Notification implements ShouldQueue
{
use Queueable;
2023-09-18 15:04:50 +02:00
public $tries = 1;
2023-09-14 12:45:50 +02:00
public function __construct(public string $name, public Server $server, public ?string $url = null)
{
}
public function via(object $notifiable): array
{
return setNotificationChannels($notifiable, 'status_changes');
}
public function toMail(): MailMessage
{
$mail = new MailMessage();
2024-01-07 16:23:41 +01:00
$mail->subject("Coolify: A resource ({$this->name}) has been restarted automatically on {$this->server->name}");
2023-09-14 12:45:50 +02:00
$mail->view('emails.container-restarted', [
'containerName' => $this->name,
'serverName' => $this->server->name,
'url' => $this->url ,
]);
return $mail;
}
public function toDiscord(): string
{
2024-01-07 16:23:41 +01:00
$message = "Coolify: A resource ({$this->name}) has been restarted automatically on {$this->server->name}";
2023-09-14 12:45:50 +02:00
return $message;
}
public function toTelegram(): array
{
2024-01-07 16:23:41 +01:00
$message = "Coolify: A resource ({$this->name}) has been restarted automatically on {$this->server->name}";
2023-09-14 12:45:50 +02:00
$payload = [
"message" => $message,
];
if ($this->url) {
$payload['buttons'] = [
[
[
"text" => "Check Proxy in Coolify",
"url" => $this->url
]
]
];
};
return $payload;
}
}