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;
|
|
|
|
|
|
|
|
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-02-21 23:21:08 +00:00
|
|
|
$mail->subject("Last Hour: 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,
|
|
|
|
]);
|
|
|
|
return $mail;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toDiscord(): string
|
|
|
|
{
|
2024-02-21 23:21:08 +00:00
|
|
|
$message = "Last Hour: A resource ($this->name) has been stopped unexpectedly on {$this->server->name}";
|
2023-09-14 10:45:50 +00:00
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
public function toTelegram(): array
|
|
|
|
{
|
2024-02-21 23:21:08 +00:00
|
|
|
$message = "Last Hour: A resource ($this->name) has been stopped unexpectedly on {$this->server->name}";
|
2023-09-14 10:45:50 +00:00
|
|
|
$payload = [
|
|
|
|
"message" => $message,
|
|
|
|
];
|
|
|
|
if ($this->url) {
|
|
|
|
$payload['buttons'] = [
|
|
|
|
[
|
|
|
|
[
|
2024-02-21 23:21:08 +00:00
|
|
|
"text" => "Open Application in Last Hour",
|
2023-09-14 10:45:50 +00:00
|
|
|
"url" => $this->url
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return $payload;
|
|
|
|
}
|
|
|
|
}
|