coolify/app/Notifications/Test.php

113 lines
3.2 KiB
PHP
Raw Normal View History

<?php
2023-07-28 08:55:26 +00:00
namespace App\Notifications;
use App\Notifications\Channels\DiscordChannel;
2024-12-09 18:44:43 +00:00
use App\Notifications\Channels\EmailChannel;
use App\Notifications\Channels\SlackChannel;
use App\Notifications\Channels\TelegramChannel;
2024-12-11 14:54:11 +00:00
use App\Notifications\Channels\PushoverChannel;
2024-09-30 08:06:50 +00:00
use App\Notifications\Dto\DiscordMessage;
2024-12-11 14:54:11 +00:00
use App\Notifications\Dto\PushoverMessage;
2024-11-12 21:37:55 +00:00
use App\Notifications\Dto\SlackMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Queue\Middleware\RateLimited;
2023-07-28 08:55:26 +00:00
class Test extends Notification implements ShouldQueue
{
use Queueable;
2023-09-08 14:53:19 +00:00
public $tries = 5;
2024-06-10 20:43:34 +00:00
public function __construct(public ?string $emails = null, public ?string $channel = null)
2024-11-12 21:37:55 +00:00
{
$this->onQueue('high');
2024-11-12 21:37:55 +00:00
}
2023-07-28 08:55:26 +00:00
public function via(object $notifiable): array
{
if ($this->channel) {
$channels = match ($this->channel) {
'email' => [EmailChannel::class],
'discord' => [DiscordChannel::class],
'telegram' => [TelegramChannel::class],
'slack' => [SlackChannel::class],
2024-12-11 14:54:11 +00:00
'pushover' => [PushoverChannel::class],
default => [],
};
} else {
$channels = $notifiable->getEnabledChannels('test');
}
return $channels;
}
public function middleware(object $notifiable, string $channel)
{
return match ($channel) {
2024-12-09 18:44:43 +00:00
EmailChannel::class => [new RateLimited('email')],
default => [],
};
}
2023-06-12 10:00:01 +00:00
public function toMail(): MailMessage
{
2024-07-24 12:27:21 +00:00
$mail = new MailMessage;
2024-06-10 20:43:34 +00:00
$mail->subject('Coolify: Test Email');
2023-06-19 12:31:42 +00:00
$mail->view('emails.test');
2024-06-10 20:43:34 +00:00
2023-06-19 12:31:42 +00:00
return $mail;
}
2024-09-29 22:43:35 +00:00
public function toDiscord(): DiscordMessage
{
2024-09-29 22:43:35 +00:00
$message = new DiscordMessage(
2024-10-21 20:40:43 +00:00
title: ':white_check_mark: Test Success',
description: 'This is a test Discord notification from Coolify. :cross_mark: :warning: :information_source:',
2024-09-29 22:43:35 +00:00
color: DiscordMessage::successColor(),
);
2024-12-06 13:33:22 +00:00
$message->addField(name: 'Dashboard', value: '[Link]('.base_url().')', inline: true);
2024-06-10 20:43:34 +00:00
2023-06-21 08:48:43 +00:00
return $message;
}
2024-06-10 20:43:34 +00:00
2023-09-06 12:31:38 +00:00
public function toTelegram(): array
{
return [
2024-06-10 20:43:34 +00:00
'message' => 'Coolify: This is a test Telegram notification from Coolify.',
'buttons' => [
2023-09-06 12:31:38 +00:00
[
2024-06-10 20:43:34 +00:00
'text' => 'Go to your dashboard',
'url' => base_url(),
],
2023-09-06 12:31:38 +00:00
],
];
}
2024-11-12 21:37:55 +00:00
2024-12-11 14:54:11 +00:00
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Test Pushover Notification',
message: 'This is a test Pushover notification from Coolify.',
buttons: [
[
'text' => 'Go to your dashboard',
'url' => base_url(),
],
],
);
}
2024-11-12 21:37:55 +00:00
public function toSlack(): SlackMessage
{
return new SlackMessage(
title: 'Test Slack Notification',
description: 'This is a test Slack notification from Coolify.'
);
}
}