fix: test notifications to only send it to the right channel

This commit is contained in:
Andras Bacsai
2024-12-11 11:57:56 +01:00
parent c08423395c
commit b442965976
7 changed files with 99 additions and 73 deletions

View File

@@ -2,7 +2,10 @@
namespace App\Notifications;
use App\Notifications\Channels\DiscordChannel;
use App\Notifications\Channels\EmailChannel;
use App\Notifications\Channels\SlackChannel;
use App\Notifications\Channels\TelegramChannel;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Bus\Queueable;
@@ -17,14 +20,26 @@ class Test extends Notification implements ShouldQueue
public $tries = 5;
public function __construct(public ?string $emails = null)
public function __construct(public ?string $emails = null, public ?string $channel = null)
{
$this->onQueue('high');
}
public function via(object $notifiable): array
{
return $notifiable->getEnabledChannels('test');
if ($this->channel) {
$channels = match ($this->channel) {
'email' => [EmailChannel::class],
'discord' => [DiscordChannel::class],
'telegram' => [TelegramChannel::class],
'slack' => [SlackChannel::class],
default => [],
};
} else {
$channels = $notifiable->getEnabledChannels('test');
}
return $channels;
}
public function middleware(object $notifiable, string $channel)