2023-07-26 12:46:28 +00:00
|
|
|
<?php
|
|
|
|
|
2023-07-28 08:55:26 +00:00
|
|
|
namespace App\Notifications\Application;
|
2023-07-26 12:46:28 +00:00
|
|
|
|
|
|
|
use App\Notifications\Channels\DiscordChannel;
|
2023-08-08 09:51:36 +00:00
|
|
|
use App\Notifications\Channels\EmailChannel;
|
2023-07-26 12:46:28 +00:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
2023-07-28 08:55:26 +00:00
|
|
|
class StatusChanged extends Notification implements ShouldQueue
|
2023-07-26 12:46:28 +00:00
|
|
|
{
|
|
|
|
use Queueable;
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-09-08 14:53:19 +00:00
|
|
|
public $tries = 5;
|
2023-08-07 20:14:21 +00:00
|
|
|
public $application;
|
2023-07-26 12:46:28 +00:00
|
|
|
|
|
|
|
public string $application_name;
|
|
|
|
public string|null $application_url = null;
|
|
|
|
public string $project_uuid;
|
|
|
|
public string $environment_name;
|
2023-08-07 20:14:21 +00:00
|
|
|
public string|null $fqdn;
|
2023-07-26 12:46:28 +00:00
|
|
|
|
2023-08-07 20:14:21 +00:00
|
|
|
public function __construct($application)
|
2023-07-26 12:46:28 +00:00
|
|
|
{
|
|
|
|
$this->application = $application;
|
|
|
|
$this->application_name = data_get($application, 'name');
|
|
|
|
$this->project_uuid = data_get($application, 'environment.project.uuid');
|
|
|
|
$this->environment_name = data_get($application, 'environment.name');
|
2023-08-07 20:14:21 +00:00
|
|
|
$this->fqdn = data_get($application, 'fqdn', null);
|
2023-07-26 12:46:28 +00:00
|
|
|
if (Str::of($this->fqdn)->explode(',')->count() > 1) {
|
|
|
|
$this->fqdn = Str::of($this->fqdn)->explode(',')->first();
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
$this->application_url = base_url() . "/project/{$this->project_uuid}/{$this->environment_name}/application/{$this->application->uuid}";
|
2023-07-26 12:46:28 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-26 12:46:28 +00:00
|
|
|
public function via(object $notifiable): array
|
|
|
|
{
|
2023-09-06 12:31:38 +00:00
|
|
|
return setNotificationChannels($notifiable, 'status_changes');
|
2023-07-26 12:46:28 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-26 12:46:28 +00:00
|
|
|
public function toMail(): MailMessage
|
|
|
|
{
|
2023-07-26 13:20:04 +00:00
|
|
|
$mail = new MailMessage();
|
|
|
|
$fqdn = $this->fqdn;
|
|
|
|
$mail->subject("⛔ {$this->application_name} has been stopped");
|
2023-07-28 08:55:26 +00:00
|
|
|
$mail->view('emails.application-status-changes', [
|
2023-07-26 13:20:04 +00:00
|
|
|
'name' => $this->application_name,
|
|
|
|
'fqdn' => $fqdn,
|
|
|
|
'application_url' => $this->application_url,
|
|
|
|
]);
|
|
|
|
return $mail;
|
2023-07-26 12:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function toDiscord(): string
|
|
|
|
{
|
|
|
|
$message = '⛔ ' . $this->application_name . ' has been stopped.
|
2023-07-27 19:26:15 +00:00
|
|
|
|
2023-07-26 12:46:28 +00:00
|
|
|
';
|
2023-09-06 12:31:38 +00:00
|
|
|
$message .= '[Open Application in Coolify](' . $this->application_url . ')';
|
2023-07-26 12:46:28 +00:00
|
|
|
return $message;
|
|
|
|
}
|
2023-09-06 12:31:38 +00:00
|
|
|
public function toTelegram(): array
|
|
|
|
{
|
|
|
|
$message = '⛔ ' . $this->application_name . ' has been stopped.';
|
|
|
|
return [
|
|
|
|
"message" => $message,
|
|
|
|
"buttons" => [
|
|
|
|
[
|
|
|
|
"text" => "Open Application in Coolify",
|
|
|
|
"url" => $this->application_url
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|