coolify/app/Notifications/Server/Reachable.php

78 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Notifications\Server;
use App\Models\Server;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
2024-12-11 14:54:11 +00:00
use App\Notifications\Dto\PushoverMessage;
2024-12-09 15:57:15 +00:00
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
class Reachable extends CustomEmailNotification
{
protected bool $isRateLimited = false;
public function __construct(public Server $server)
{
$this->onQueue('high');
$this->isRateLimited = isEmailRateLimited(
2024-12-09 15:57:15 +00:00
limiterKey: 'server-reachable:'.$this->server->id,
);
}
public function via(object $notifiable): array
{
if ($this->isRateLimited) {
return [];
}
2024-12-09 15:57:15 +00:00
return $notifiable->getEnabledChannels('server_reachable');
}
public function toMail(): MailMessage
{
2024-07-24 19:11:12 +00:00
$mail = new MailMessage;
2023-10-10 11:10:43 +00:00
$mail->subject("Coolify: Server ({$this->server->name}) revived.");
$mail->view('emails.server-revived', [
'name' => $this->server->name,
]);
2024-06-10 20:43:34 +00:00
return $mail;
}
public function toDiscord(): DiscordMessage
{
return new DiscordMessage(
2024-10-21 20:40:43 +00:00
title: ":white_check_mark: Server '{$this->server->name}' revived",
description: 'All automations & integrations are turned on again!',
color: DiscordMessage::successColor(),
);
}
2024-06-10 20:43:34 +00:00
2024-12-11 14:54:11 +00:00
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Server revived',
message: "Server '{$this->server->name}' revived. All automations & integrations are turned on again!",
level: 'success',
);
}
public function toTelegram(): array
{
return [
2024-06-10 20:43:34 +00:00
'message' => "Coolify: Server '{$this->server->name}' revived. All automations & integrations are turned on again!",
];
}
2024-11-12 21:37:55 +00:00
public function toSlack(): SlackMessage
{
return new SlackMessage(
2024-12-09 15:57:15 +00:00
title: 'Server revived',
2024-11-12 21:37:55 +00:00
description: "Server '{$this->server->name}' revived.\nAll automations & integrations are turned on again!",
color: SlackMessage::successColor()
);
}
}