diff --git a/app/Filament/Pages/Settings/NotificationPage.php b/app/Filament/Pages/Settings/NotificationPage.php index bd7df5902..bfdaaac2b 100755 --- a/app/Filament/Pages/Settings/NotificationPage.php +++ b/app/Filament/Pages/Settings/NotificationPage.php @@ -152,9 +152,7 @@ public function form(Form $form): Form ->label('Enable Discord webhook notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ - 'default' => 1, - ]) + Forms\Components\Grid::make(['default' => 1]) ->hidden(fn (Forms\Get $get) => $get('discord_enabled') !== true) ->schema([ Forms\Components\Fieldset::make('Triggers') @@ -164,6 +162,7 @@ public function form(Form $form): Form ->columnSpanFull(), Forms\Components\Toggle::make('discord_on_threshold_failure') ->label('Notify on threshold failures') + ->reactive() ->columnSpanFull(), ]), Forms\Components\Repeater::make('discord_webhooks') @@ -176,6 +175,17 @@ public function form(Form $form): Form ->url(), ]) ->columnSpanFull(), + Forms\Components\Fieldset::make('discord_user_mention') + ->label('Discord User Mention') + ->hidden(fn (Forms\Get $get) => $get('discord_on_threshold_failure') !== true) + ->schema([ + Forms\Components\TextInput::make('discord_user_mention') + ->label('User ID') + ->placeholder('Enter the Discord User ID') + ->maxLength(18) + ->helperText('This should be the numeric User ID from Discord (e.g., 123456789012345678)'), + ]) + ->columnSpanFull(), Forms\Components\Actions::make([ Forms\Components\Actions\Action::make('test discord') ->label('Test Discord webhook') @@ -189,7 +199,6 @@ public function form(Form $form): Form 'default' => 1, 'md' => 2, ]), - Forms\Components\Section::make('Gotify') ->schema([ Forms\Components\Toggle::make('gotify_enabled') diff --git a/app/Listeners/Discord/SendSpeedtestThresholdNotification.php b/app/Listeners/Discord/SendSpeedtestThresholdNotification.php index 50dd18411..3ba099671 100644 --- a/app/Listeners/Discord/SendSpeedtestThresholdNotification.php +++ b/app/Listeners/Discord/SendSpeedtestThresholdNotification.php @@ -71,6 +71,7 @@ public function handle(SpeedtestCompleted $event): void 'metrics' => $failed, 'speedtest_url' => $event->result->result_url, 'url' => url('/admin/results'), + 'mentionUser' => $notificationSettings->discord_user_mention, ])->render(), ]; diff --git a/app/Settings/NotificationSettings.php b/app/Settings/NotificationSettings.php index 0796be61a..dc7b3a201 100644 --- a/app/Settings/NotificationSettings.php +++ b/app/Settings/NotificationSettings.php @@ -46,6 +46,8 @@ class NotificationSettings extends Settings public ?array $discord_webhooks; + public ?string $discord_user_mention; + public bool $ntfy_enabled; public bool $ntfy_on_speedtest_run; diff --git a/database/settings/2024_12_06_222700_add_discord_user_mention.php b/database/settings/2024_12_06_222700_add_discord_user_mention.php new file mode 100644 index 000000000..7bb151ca2 --- /dev/null +++ b/database/settings/2024_12_06_222700_add_discord_user_mention.php @@ -0,0 +1,16 @@ +migrator->add('notification.discord_user_mention', null); + } + + public function down(): void + { + $this->migrator->delete('notification.discord_user_mention'); + } +}; diff --git a/resources/views/discord/speedtest-threshold.blade.php b/resources/views/discord/speedtest-threshold.blade.php index 95dc4bf01..bdba874a9 100644 --- a/resources/views/discord/speedtest-threshold.blade.php +++ b/resources/views/discord/speedtest-threshold.blade.php @@ -1,5 +1,9 @@ **Speedtest Threshold Breached - #{{ $id }}** +@if (!empty($mentionUser)) +{!! "<@{$mentionUser}>" !!} +@endif + A new speedtest on **{{ config('app.name') }}** was completed using **{{ $service }}** on **{{ $isp }}** but a threshold was breached. @foreach ($metrics as $item)