lasthourcloud/app/Notifications/Container/ContainerStopped.php

64 lines
1.7 KiB
PHP
Raw Normal View History

2023-09-14 10:45:50 +00: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 ContainerStopped extends Notification implements ShouldQueue
{
use Queueable;
public $tries = 1;
2024-06-19 06:59:46 +00:00
public function __construct(public string $name, public Server $server, public ?string $url = null) {}
2023-09-14 10:45:50 +00:00
public function via(object $notifiable): array
{
return setNotificationChannels($notifiable, 'status_changes');
}
public function toMail(): MailMessage
{
$mail = new MailMessage();
2024-01-07 15:23:41 +00:00
$mail->subject("Coolify: A resource has been stopped unexpectedly on {$this->server->name}");
2023-09-14 10:45:50 +00:00
$mail->view('emails.container-stopped', [
'containerName' => $this->name,
'serverName' => $this->server->name,
'url' => $this->url,
]);
2024-06-10 20:43:34 +00:00
2023-09-14 10:45:50 +00:00
return $mail;
}
public function toDiscord(): string
{
$message = "Coolify: A resource ($this->name) has been stopped unexpectedly on {$this->server->name}";
2024-06-10 20:43:34 +00:00
2023-09-14 10:45:50 +00:00
return $message;
}
2024-06-10 20:43:34 +00:00
2023-09-14 10:45:50 +00:00
public function toTelegram(): array
{
$message = "Coolify: A resource ($this->name) has been stopped unexpectedly on {$this->server->name}";
2023-09-14 10:45:50 +00:00
$payload = [
2024-06-10 20:43:34 +00:00
'message' => $message,
2023-09-14 10:45:50 +00:00
];
if ($this->url) {
$payload['buttons'] = [
[
[
2024-06-10 20:43:34 +00:00
'text' => 'Open Application in Coolify',
'url' => $this->url,
],
],
2023-09-14 10:45:50 +00:00
];
}
2024-06-10 20:43:34 +00:00
2023-09-14 10:45:50 +00:00
return $payload;
}
}