fix notifications (#109)

This commit is contained in:
Saeed Vaziry 2024-02-16 21:54:51 +01:00 committed by GitHub
parent f70963d6bb
commit 9db310a06b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 20 additions and 12 deletions

View File

@ -8,7 +8,7 @@ interface Notification
{ {
public function rawText(): string; public function rawText(): string;
public function toMail(object $notifiable): MailMessage; public function toEmail(object $notifiable): MailMessage;
public function toSlack(object $notifiable): string; public function toSlack(object $notifiable): string;

View File

@ -3,6 +3,7 @@
namespace App\NotificationChannels; namespace App\NotificationChannels;
use App\Contracts\Notification; use App\Contracts\Notification;
use App\Models\NotificationChannel;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
class Discord extends AbstractNotificationChannel class Discord extends AbstractNotificationChannel
@ -60,6 +61,8 @@ private function checkConnection(string $subject, string $text): bool
public function send(object $notifiable, Notification $notification): void public function send(object $notifiable, Notification $notification): void
{ {
/** @var NotificationChannel $notifiable */
$this->notificationChannel = $notifiable;
$data = $this->notificationChannel->data; $data = $this->notificationChannel->data;
Http::post($data['webhook_url'], [ Http::post($data['webhook_url'], [
'content' => $notification->toSlack($notifiable), 'content' => $notification->toSlack($notifiable),

View File

@ -51,8 +51,7 @@ public function send(object $notifiable, Notification $notification): void
{ {
/** @var NotificationChannel $notifiable */ /** @var NotificationChannel $notifiable */
$this->notificationChannel = $notifiable; $this->notificationChannel = $notifiable;
$message = $notification->toMail($notifiable); $message = $notification->toEmail($notifiable);
Mail::to($this->data()['email'])->send( Mail::to($this->data()['email'])->send(
new NotificationMail($message->subject, $message->render()) new NotificationMail($message->subject, $message->render())
); );

View File

@ -3,6 +3,7 @@
namespace App\NotificationChannels; namespace App\NotificationChannels;
use App\Contracts\Notification; use App\Contracts\Notification;
use App\Models\NotificationChannel;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
class Slack extends AbstractNotificationChannel class Slack extends AbstractNotificationChannel
@ -60,6 +61,8 @@ private function checkConnection(string $subject, string $text): bool
public function send(object $notifiable, Notification $notification): void public function send(object $notifiable, Notification $notification): void
{ {
/** @var NotificationChannel $notifiable */
$this->notificationChannel = $notifiable;
$data = $this->notificationChannel->data; $data = $this->notificationChannel->data;
Http::post($data['webhook_url'], [ Http::post($data['webhook_url'], [
'text' => $notification->toSlack($notifiable), 'text' => $notification->toSlack($notifiable),

View File

@ -3,6 +3,7 @@
namespace App\NotificationChannels; namespace App\NotificationChannels;
use App\Contracts\Notification; use App\Contracts\Notification;
use App\Models\NotificationChannel;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Throwable; use Throwable;
@ -47,6 +48,8 @@ public function connect(): bool
public function send(object $notifiable, Notification $notification): void public function send(object $notifiable, Notification $notification): void
{ {
/** @var NotificationChannel $notifiable */
$this->notificationChannel = $notifiable;
$this->sendToTelegram($notification->toTelegram($notifiable)); $this->sendToTelegram($notification->toTelegram($notifiable));
} }

View File

@ -20,7 +20,7 @@ public function via(object $notifiable): string
return get_class($notifiable->provider()); return get_class($notifiable->provider());
} }
public function toMail(object $notifiable): MailMessage public function toEmail(object $notifiable): MailMessage
{ {
return (new MailMessage()) return (new MailMessage())
->subject('Notification') ->subject('Notification')

View File

@ -25,7 +25,7 @@ public function rawText(): string
]); ]);
} }
public function toMail(object $notifiable): MailMessage public function toEmail(object $notifiable): MailMessage
{ {
return (new MailMessage) return (new MailMessage)
->subject(__('Failed to delete the server from the provider!')) ->subject(__('Failed to delete the server from the provider!'))

View File

@ -21,7 +21,7 @@ public function rawText(): string
]); ]);
} }
public function toMail(object $notifiable): MailMessage public function toEmail(object $notifiable): MailMessage
{ {
return (new MailMessage) return (new MailMessage)
->subject(__('Server disconnected!')) ->subject(__('Server disconnected!'))

View File

@ -22,7 +22,7 @@ public function rawText(): string
]); ]);
} }
public function toMail(object $notifiable): MailMessage public function toEmail(object $notifiable): MailMessage
{ {
return (new MailMessage) return (new MailMessage)
->subject(__('Server installation failed!')) ->subject(__('Server installation failed!'))

View File

@ -22,7 +22,7 @@ public function rawText(): string
]); ]);
} }
public function toMail(object $notifiable): MailMessage public function toEmail(object $notifiable): MailMessage
{ {
return (new MailMessage) return (new MailMessage)
->subject(__('Server installation started!')) ->subject(__('Server installation started!'))

View File

@ -32,7 +32,7 @@ public function rawText(): string
]); ]);
} }
public function toMail(object $notifiable): MailMessage public function toEmail(object $notifiable): MailMessage
{ {
$this->server->refresh(); $this->server->refresh();

View File

@ -19,7 +19,7 @@ public function rawText(): string
]); ]);
} }
public function toMail(object $notifiable): MailMessage public function toEmail(object $notifiable): MailMessage
{ {
return (new MailMessage) return (new MailMessage)
->subject(__('Site installation failed!')) ->subject(__('Site installation failed!'))

View File

@ -18,7 +18,7 @@ public function rawText(): string
]); ]);
} }
public function toMail(object $notifiable): MailMessage public function toEmail(object $notifiable): MailMessage
{ {
return (new MailMessage) return (new MailMessage)
->subject(__('Site installation succeed!')) ->subject(__('Site installation succeed!'))

View File

@ -18,7 +18,7 @@ public function rawText(): string
]); ]);
} }
public function toMail(object $notifiable): MailMessage public function toEmail(object $notifiable): MailMessage
{ {
return (new MailMessage) return (new MailMessage)
->subject(__('Source control disconnected!')) ->subject(__('Source control disconnected!'))