From 9db310a06b665a59c3a8414f2ec8f44b0d3b4c2a Mon Sep 17 00:00:00 2001 From: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:54:51 +0100 Subject: [PATCH] fix notifications (#109) --- app/Contracts/Notification.php | 2 +- app/NotificationChannels/Discord.php | 3 +++ app/NotificationChannels/Email.php | 3 +-- app/NotificationChannels/Slack.php | 3 +++ app/NotificationChannels/Telegram.php | 3 +++ app/Notifications/AbstractNotification.php | 2 +- app/Notifications/FailedToDeleteServerFromProvider.php | 2 +- app/Notifications/ServerDisconnected.php | 2 +- app/Notifications/ServerInstallationFailed.php | 2 +- app/Notifications/ServerInstallationStarted.php | 2 +- app/Notifications/ServerInstallationSucceed.php | 2 +- app/Notifications/SiteInstallationFailed.php | 2 +- app/Notifications/SiteInstallationSucceed.php | 2 +- app/Notifications/SourceControlDisconnected.php | 2 +- 14 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/Contracts/Notification.php b/app/Contracts/Notification.php index 3e761fc..62bae46 100644 --- a/app/Contracts/Notification.php +++ b/app/Contracts/Notification.php @@ -8,7 +8,7 @@ interface Notification { public function rawText(): string; - public function toMail(object $notifiable): MailMessage; + public function toEmail(object $notifiable): MailMessage; public function toSlack(object $notifiable): string; diff --git a/app/NotificationChannels/Discord.php b/app/NotificationChannels/Discord.php index ed9228d..069886a 100644 --- a/app/NotificationChannels/Discord.php +++ b/app/NotificationChannels/Discord.php @@ -3,6 +3,7 @@ namespace App\NotificationChannels; use App\Contracts\Notification; +use App\Models\NotificationChannel; use Illuminate\Support\Facades\Http; class Discord extends AbstractNotificationChannel @@ -60,6 +61,8 @@ private function checkConnection(string $subject, string $text): bool public function send(object $notifiable, Notification $notification): void { + /** @var NotificationChannel $notifiable */ + $this->notificationChannel = $notifiable; $data = $this->notificationChannel->data; Http::post($data['webhook_url'], [ 'content' => $notification->toSlack($notifiable), diff --git a/app/NotificationChannels/Email.php b/app/NotificationChannels/Email.php index 79c3a8b..440296b 100644 --- a/app/NotificationChannels/Email.php +++ b/app/NotificationChannels/Email.php @@ -51,8 +51,7 @@ public function send(object $notifiable, Notification $notification): void { /** @var NotificationChannel $notifiable */ $this->notificationChannel = $notifiable; - $message = $notification->toMail($notifiable); - + $message = $notification->toEmail($notifiable); Mail::to($this->data()['email'])->send( new NotificationMail($message->subject, $message->render()) ); diff --git a/app/NotificationChannels/Slack.php b/app/NotificationChannels/Slack.php index dc7f8f4..09f5b2d 100644 --- a/app/NotificationChannels/Slack.php +++ b/app/NotificationChannels/Slack.php @@ -3,6 +3,7 @@ namespace App\NotificationChannels; use App\Contracts\Notification; +use App\Models\NotificationChannel; use Illuminate\Support\Facades\Http; class Slack extends AbstractNotificationChannel @@ -60,6 +61,8 @@ private function checkConnection(string $subject, string $text): bool public function send(object $notifiable, Notification $notification): void { + /** @var NotificationChannel $notifiable */ + $this->notificationChannel = $notifiable; $data = $this->notificationChannel->data; Http::post($data['webhook_url'], [ 'text' => $notification->toSlack($notifiable), diff --git a/app/NotificationChannels/Telegram.php b/app/NotificationChannels/Telegram.php index d8ab492..d57e627 100644 --- a/app/NotificationChannels/Telegram.php +++ b/app/NotificationChannels/Telegram.php @@ -3,6 +3,7 @@ namespace App\NotificationChannels; use App\Contracts\Notification; +use App\Models\NotificationChannel; use Illuminate\Support\Facades\Http; use Throwable; @@ -47,6 +48,8 @@ public function connect(): bool public function send(object $notifiable, Notification $notification): void { + /** @var NotificationChannel $notifiable */ + $this->notificationChannel = $notifiable; $this->sendToTelegram($notification->toTelegram($notifiable)); } diff --git a/app/Notifications/AbstractNotification.php b/app/Notifications/AbstractNotification.php index 62ba544..9afd974 100644 --- a/app/Notifications/AbstractNotification.php +++ b/app/Notifications/AbstractNotification.php @@ -20,7 +20,7 @@ public function via(object $notifiable): string return get_class($notifiable->provider()); } - public function toMail(object $notifiable): MailMessage + public function toEmail(object $notifiable): MailMessage { return (new MailMessage()) ->subject('Notification') diff --git a/app/Notifications/FailedToDeleteServerFromProvider.php b/app/Notifications/FailedToDeleteServerFromProvider.php index 08d8a56..e8b2fa1 100644 --- a/app/Notifications/FailedToDeleteServerFromProvider.php +++ b/app/Notifications/FailedToDeleteServerFromProvider.php @@ -25,7 +25,7 @@ public function rawText(): string ]); } - public function toMail(object $notifiable): MailMessage + public function toEmail(object $notifiable): MailMessage { return (new MailMessage) ->subject(__('Failed to delete the server from the provider!')) diff --git a/app/Notifications/ServerDisconnected.php b/app/Notifications/ServerDisconnected.php index 813f8d7..029c9b7 100644 --- a/app/Notifications/ServerDisconnected.php +++ b/app/Notifications/ServerDisconnected.php @@ -21,7 +21,7 @@ public function rawText(): string ]); } - public function toMail(object $notifiable): MailMessage + public function toEmail(object $notifiable): MailMessage { return (new MailMessage) ->subject(__('Server disconnected!')) diff --git a/app/Notifications/ServerInstallationFailed.php b/app/Notifications/ServerInstallationFailed.php index e98731f..65856bb 100644 --- a/app/Notifications/ServerInstallationFailed.php +++ b/app/Notifications/ServerInstallationFailed.php @@ -22,7 +22,7 @@ public function rawText(): string ]); } - public function toMail(object $notifiable): MailMessage + public function toEmail(object $notifiable): MailMessage { return (new MailMessage) ->subject(__('Server installation failed!')) diff --git a/app/Notifications/ServerInstallationStarted.php b/app/Notifications/ServerInstallationStarted.php index a33511d..a96bb4b 100644 --- a/app/Notifications/ServerInstallationStarted.php +++ b/app/Notifications/ServerInstallationStarted.php @@ -22,7 +22,7 @@ public function rawText(): string ]); } - public function toMail(object $notifiable): MailMessage + public function toEmail(object $notifiable): MailMessage { return (new MailMessage) ->subject(__('Server installation started!')) diff --git a/app/Notifications/ServerInstallationSucceed.php b/app/Notifications/ServerInstallationSucceed.php index 7b21557..1a4654c 100644 --- a/app/Notifications/ServerInstallationSucceed.php +++ b/app/Notifications/ServerInstallationSucceed.php @@ -32,7 +32,7 @@ public function rawText(): string ]); } - public function toMail(object $notifiable): MailMessage + public function toEmail(object $notifiable): MailMessage { $this->server->refresh(); diff --git a/app/Notifications/SiteInstallationFailed.php b/app/Notifications/SiteInstallationFailed.php index 0c75518..ccf46b0 100644 --- a/app/Notifications/SiteInstallationFailed.php +++ b/app/Notifications/SiteInstallationFailed.php @@ -19,7 +19,7 @@ public function rawText(): string ]); } - public function toMail(object $notifiable): MailMessage + public function toEmail(object $notifiable): MailMessage { return (new MailMessage) ->subject(__('Site installation failed!')) diff --git a/app/Notifications/SiteInstallationSucceed.php b/app/Notifications/SiteInstallationSucceed.php index e4c353e..301b4a1 100644 --- a/app/Notifications/SiteInstallationSucceed.php +++ b/app/Notifications/SiteInstallationSucceed.php @@ -18,7 +18,7 @@ public function rawText(): string ]); } - public function toMail(object $notifiable): MailMessage + public function toEmail(object $notifiable): MailMessage { return (new MailMessage) ->subject(__('Site installation succeed!')) diff --git a/app/Notifications/SourceControlDisconnected.php b/app/Notifications/SourceControlDisconnected.php index ab732d5..8113875 100644 --- a/app/Notifications/SourceControlDisconnected.php +++ b/app/Notifications/SourceControlDisconnected.php @@ -18,7 +18,7 @@ public function rawText(): string ]); } - public function toMail(object $notifiable): MailMessage + public function toEmail(object $notifiable): MailMessage { return (new MailMessage) ->subject(__('Source control disconnected!'))