mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
Adds three new push notification channels to reach feature parity with PriceGhost, following the existing channel pattern (app-level service config + per-user routing target): - Telegram: shared bot token (app) + per-user chat id, HTML messages - Discord: rich embed via webhook, app-level default + per-user override - ntfy: app-level server/auth (defaults to ntfy.sh) + per-user topic, optional basic auth for self-hosted servers Each channel is wired into NotificationMethods, exposes its config in the app settings and per-user profile forms, and Telegram/Discord get a Test action. Full unit coverage for settings merging, send payloads, routing guards and per-channel enable/disable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Actions\Notifications;
|
|
|
|
use App\Notifications\Channels\DiscordChannel;
|
|
use Closure;
|
|
use Exception;
|
|
use Filament\Forms\Components\Actions\Action;
|
|
use Filament\Notifications\Notification;
|
|
use Illuminate\Http\Client\RequestException;
|
|
|
|
class TestDiscordAction extends Action
|
|
{
|
|
public Closure $settingsCallback;
|
|
|
|
public static function getDefaultName(): ?string
|
|
{
|
|
return 'discord_test';
|
|
}
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->label(__('Test'));
|
|
|
|
$this->successNotificationTitle(__('Test notification sent successfully'));
|
|
|
|
$this->failureNotificationTitle(__('Error'));
|
|
|
|
$this->icon('heroicon-m-bell');
|
|
|
|
$this->color('gray');
|
|
|
|
$this->action(fn () => $this->testSendingNotification());
|
|
}
|
|
|
|
public function setSettings(Closure $settingsCallback): self
|
|
{
|
|
$this->settingsCallback = $settingsCallback;
|
|
|
|
return $this;
|
|
}
|
|
|
|
protected function testSendingNotification(): void
|
|
{
|
|
$settings = call_user_func($this->settingsCallback);
|
|
$webhookUrl = data_get($settings, 'webhook_url');
|
|
|
|
if (empty($webhookUrl)) {
|
|
Notification::make()
|
|
->title('Error')
|
|
->body('Please save a Discord webhook URL first')
|
|
->danger()
|
|
->send();
|
|
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$response = DiscordChannel::sendRequest(
|
|
$webhookUrl,
|
|
'Test PriceBuddy notification',
|
|
'This is a test notification from PriceBuddy',
|
|
url('/')
|
|
);
|
|
|
|
$response->throw();
|
|
$this->success();
|
|
} catch (RequestException|Exception $e) {
|
|
Notification::make()
|
|
->title('Failed to send test notification')
|
|
->body('Error: '.$e->getMessage())
|
|
->danger()
|
|
->send();
|
|
}
|
|
}
|
|
}
|