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
|
|
|
|
2023-09-15 13:34:25 +00:00
|
|
|
use App\Models\Application;
|
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;
|
|
|
|
|
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-18 13:19:27 +00:00
|
|
|
public $tries = 1;
|
2023-07-26 12:46:28 +00:00
|
|
|
|
2023-10-14 12:22:07 +00:00
|
|
|
public string $resource_name;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-07-26 12:46:28 +00:00
|
|
|
public string $project_uuid;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-07-26 12:46:28 +00:00
|
|
|
public string $environment_name;
|
2023-09-15 13:34:25 +00:00
|
|
|
|
2023-10-14 12:22:07 +00:00
|
|
|
public ?string $resource_url = null;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-15 13:34:25 +00:00
|
|
|
public ?string $fqdn;
|
2023-07-26 12:46:28 +00:00
|
|
|
|
2023-10-14 12:22:07 +00:00
|
|
|
public function __construct(public Application $resource)
|
2023-07-26 12:46:28 +00:00
|
|
|
{
|
2023-10-14 12:22:07 +00:00
|
|
|
$this->resource_name = data_get($resource, 'name');
|
|
|
|
$this->project_uuid = data_get($resource, 'environment.project.uuid');
|
|
|
|
$this->environment_name = data_get($resource, 'environment.name');
|
|
|
|
$this->fqdn = data_get($resource, 'fqdn', null);
|
2024-06-25 08:37:10 +00:00
|
|
|
if (str($this->fqdn)->explode(',')->count() > 1) {
|
|
|
|
$this->fqdn = str($this->fqdn)->explode(',')->first();
|
2023-07-26 12:46:28 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
$this->resource_url = base_url()."/project/{$this->project_uuid}/".urlencode($this->environment_name)."/application/{$this->resource->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
|
|
|
|
{
|
2024-07-24 12:27:21 +00:00
|
|
|
$mail = new MailMessage;
|
2023-07-26 13:20:04 +00:00
|
|
|
$fqdn = $this->fqdn;
|
2023-10-14 12:22:07 +00:00
|
|
|
$mail->subject("Coolify: {$this->resource_name} has been stopped");
|
2023-07-28 08:55:26 +00:00
|
|
|
$mail->view('emails.application-status-changes', [
|
2023-10-14 12:22:07 +00:00
|
|
|
'name' => $this->resource_name,
|
2023-07-26 13:20:04 +00:00
|
|
|
'fqdn' => $fqdn,
|
2023-10-14 12:22:07 +00:00
|
|
|
'resource_url' => $this->resource_url,
|
2023-07-26 13:20:04 +00:00
|
|
|
]);
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-07-26 13:20:04 +00:00
|
|
|
return $mail;
|
2023-07-26 12:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function toDiscord(): string
|
|
|
|
{
|
2024-06-10 20:43:34 +00:00
|
|
|
$message = 'Coolify: '.$this->resource_name.' has been stopped.
|
2023-07-27 19:26:15 +00:00
|
|
|
|
2023-07-26 12:46:28 +00:00
|
|
|
';
|
2024-06-10 20:43:34 +00:00
|
|
|
$message .= '[Open Application in Coolify]('.$this->resource_url.')';
|
|
|
|
|
2023-07-26 12:46:28 +00:00
|
|
|
return $message;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-06 12:31:38 +00:00
|
|
|
public function toTelegram(): array
|
|
|
|
{
|
2024-06-10 20:43:34 +00:00
|
|
|
$message = 'Coolify: '.$this->resource_name.' has been stopped.';
|
|
|
|
|
2023-09-06 12:31:38 +00:00
|
|
|
return [
|
2024-06-10 20:43:34 +00:00
|
|
|
'message' => $message,
|
|
|
|
'buttons' => [
|
2023-09-06 12:31:38 +00:00
|
|
|
[
|
2024-06-10 20:43:34 +00:00
|
|
|
'text' => 'Open Application in Coolify',
|
|
|
|
'url' => $this->resource_url,
|
|
|
|
],
|
2023-09-06 12:31:38 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|