feat: slack notifications

This commit is contained in:
Marvin von Rappard
2024-11-12 22:37:55 +01:00
parent 9af3fe9c97
commit eb0686fe20
27 changed files with 822 additions and 181 deletions

View File

@@ -8,7 +8,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Notifications\Dto\SlackMessage;
class StatusChanged extends Notification implements ShouldQueue
{
use Queueable;
@@ -34,7 +34,7 @@ class StatusChanged extends Notification implements ShouldQueue
if (str($this->fqdn)->explode(',')->count() > 1) {
$this->fqdn = str($this->fqdn)->explode(',')->first();
}
$this->resource_url = base_url()."/project/{$this->project_uuid}/".urlencode($this->environment_name)."/application/{$this->resource->uuid}";
$this->resource_url = base_url() . "/project/{$this->project_uuid}/" . urlencode($this->environment_name) . "/application/{$this->resource->uuid}";
}
public function via(object $notifiable): array
@@ -60,7 +60,7 @@ class StatusChanged extends Notification implements ShouldQueue
{
return new DiscordMessage(
title: ':cross_mark: Application stopped',
description: '[Open Application in Coolify]('.$this->resource_url.')',
description: '[Open Application in Coolify](' . $this->resource_url . ')',
color: DiscordMessage::errorColor(),
isCritical: true,
);
@@ -68,7 +68,7 @@ class StatusChanged extends Notification implements ShouldQueue
public function toTelegram(): array
{
$message = 'Coolify: '.$this->resource_name.' has been stopped.';
$message = 'Coolify: ' . $this->resource_name . ' has been stopped.';
return [
'message' => $message,
@@ -80,4 +80,20 @@ class StatusChanged extends Notification implements ShouldQueue
],
];
}
public function toSlack(): SlackMessage
{
$title = "Application stopped";
$description = "{$this->resource_name} has been stopped";
$description .= "\n\n**Project:** " . data_get($this->resource, 'environment.project.name');
$description .= "\n**Environment:** {$this->environment_name}";
$description .= "\n**Application URL:** {$this->resource_url}";
return new SlackMessage(
title: $title,
description: $description,
color: SlackMessage::errorColor()
);
}
}