subscribe to events

This commit is contained in:
Andras Bacsai
2023-06-19 14:31:42 +02:00
parent 631968ee5b
commit f7dd110a49
15 changed files with 155 additions and 25 deletions

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Notifications\Notifications;
use App\Models\Application;
use App\Models\Team;
use App\Notifications\Channels\EmailChannel;
use App\Notifications\Channels\DiscordChannel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;
class ApplicationDeployedNotification extends Notification implements ShouldQueue
{
use Queueable;
public Application $application;
public string $application_name;
public string $deployment_uuid;
public string|null $deployment_url = null;
public string $project_uuid;
public string $environment_name;
public string $fqdn;
public function __construct(Application $application, string $deployment_uuid)
{
$this->application = $application;
$this->application_name = data_get($application, 'name');
$this->deployment_uuid = $deployment_uuid;
$this->project_uuid = data_get($application, 'environment.project.uuid');
$this->environment_name = data_get($application, 'environment.name');
$this->fqdn = data_get($application, 'fqdn');
if (Str::of($this->fqdn)->explode(',')->count() > 1) {
$this->fqdn = Str::of($this->fqdn)->explode(',')->first();
}
$this->deployment_url = base_url() . "/project/{$this->project_uuid}/{$this->environment_name}/application/{$this->application->uuid}/deployment/{$this->deployment_uuid}";
}
public function via(object $notifiable): array
{
$channels = [];
if ($notifiable->extra_attributes?->get('email_active') && $notifiable->extra_attributes?->get('notifications_deployments')) {
$channels[] = EmailChannel::class;
}
if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_deployments')) {
$channels[] = DiscordChannel::class;
}
return $channels;
}
public function toMail(Team $team): MailMessage
{
$mail = new MailMessage();
$mail->subject("New version is deployed of {$this->application_name}");
$mail->view('emails.application-deployed', [
'name' => $this->application_name,
'fqdn' => $this->fqdn,
'url' => $this->deployment_url,
]);
return $mail;
}
public function toDiscord(): string
{
return '⚒️ A new version has been deployed of **' . $this->application_name . '**.
[Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')';
}
}

View File

@@ -15,20 +15,26 @@ class TestNotification extends Notification implements ShouldQueue
public function via(object $notifiable): array
{
$channels = [];
$notifiable->extra_attributes?->get('smtp_active') && $channels[] = EmailChannel::class;
$notifiable->extra_attributes?->get('discord_active') && $channels[] = DiscordChannel::class;
if ($notifiable->extra_attributes?->get('email_active') && $notifiable->extra_attributes?->get('notifications_test')) {
$channels[] = EmailChannel::class;
}
if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_test')) {
$channels[] = DiscordChannel::class;
}
return $channels;
}
public function toMail(): MailMessage
{
return (new MailMessage)
->subject('Coolify Test Notification')
->line('Congratulations!')
->line('You have successfully received a test Email notification from Coolify. 🥳');
$mail = new MailMessage();
$mail->subject("Coolify Test Notification");
$mail->view('emails.test');
return $mail;
}
public function toDiscord(): string
{
return 'You have successfully received a test Discord notification from Coolify. 🥳 [Go to your dashboard](' . base_url() . ')';
return 'This is a test Discord notification from Coolify.
[Go to your dashboard](' . base_url() . ')';
}
}