coolify/app/Notifications/Application/StatusChanged.php

83 lines
2.3 KiB
PHP
Raw Normal View History

<?php
2023-07-28 10:55:26 +02:00
namespace App\Notifications\Application;
use App\Models\Application;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
2023-07-28 10:55:26 +02:00
class StatusChanged extends Notification implements ShouldQueue
{
use Queueable;
public $tries = 1;
public string $resource_name;
2024-06-10 22:43:34 +02:00
public string $project_uuid;
2024-06-10 22:43:34 +02:00
public string $environment_name;
public ?string $resource_url = null;
2024-06-10 22:43:34 +02:00
public ?string $fqdn;
public function __construct(public Application $resource)
{
$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);
if (str($this->fqdn)->explode(',')->count() > 1) {
$this->fqdn = str($this->fqdn)->explode(',')->first();
}
2024-06-10 22:43:34 +02:00
$this->resource_url = base_url()."/project/{$this->project_uuid}/".urlencode($this->environment_name)."/application/{$this->resource->uuid}";
}
public function via(object $notifiable): array
{
2023-09-06 14:31:38 +02:00
return setNotificationChannels($notifiable, 'status_changes');
}
public function toMail(): MailMessage
{
2024-07-24 14:27:21 +02:00
$mail = new MailMessage;
2023-07-26 15:20:04 +02:00
$fqdn = $this->fqdn;
$mail->subject("Coolify: {$this->resource_name} has been stopped");
2023-07-28 10:55:26 +02:00
$mail->view('emails.application-status-changes', [
'name' => $this->resource_name,
2023-07-26 15:20:04 +02:00
'fqdn' => $fqdn,
'resource_url' => $this->resource_url,
2023-07-26 15:20:04 +02:00
]);
2024-06-10 22:43:34 +02:00
2023-07-26 15:20:04 +02:00
return $mail;
}
public function toDiscord(): string
{
2024-06-10 22:43:34 +02:00
$message = 'Coolify: '.$this->resource_name.' has been stopped.
';
2024-06-10 22:43:34 +02:00
$message .= '[Open Application in Coolify]('.$this->resource_url.')';
return $message;
}
2024-06-10 22:43:34 +02:00
2023-09-06 14:31:38 +02:00
public function toTelegram(): array
{
2024-06-10 22:43:34 +02:00
$message = 'Coolify: '.$this->resource_name.' has been stopped.';
2023-09-06 14:31:38 +02:00
return [
2024-06-10 22:43:34 +02:00
'message' => $message,
'buttons' => [
2023-09-06 14:31:38 +02:00
[
2024-06-10 22:43:34 +02:00
'text' => 'Open Application in Coolify',
'url' => $this->resource_url,
],
2023-09-06 14:31:38 +02:00
],
];
}
}