coolify/app/Notifications/Test.php

80 lines
2.1 KiB
PHP
Raw Normal View History

<?php
2023-07-28 08:55:26 +00:00
namespace App\Notifications;
2024-09-30 08:06:50 +00:00
use App\Notifications\Dto\DiscordMessage;
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
2024-11-12 21:37:55 +00:00
public function __construct(public ?string $emails = null)
{
$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
{
2023-09-06 12:31:38 +00:00
return setNotificationChannels($notifiable, 'test');
}
public function middleware(object $notifiable, string $channel)
{
return match ($channel) {
2024-10-28 13:56:13 +00:00
\App\Notifications\Channels\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-11-12 21:37:55 +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
public function toSlack(): SlackMessage
{
return new SlackMessage(
title: 'Test Slack Notification',
description: 'This is a test Slack notification from Coolify.'
);
}
}