Skip to content

Commit e92e18b

Browse files
authored
[CHore] Refactored discord webhooks to use WebhookCall (alexjustesen#1221)
1 parent b78db8c commit e92e18b

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

app/Actions/Notifications/SendDiscordTestNotification.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace App\Actions\Notifications;
44

55
use Filament\Notifications\Notification;
6-
use Illuminate\Support\Facades\Http;
76
use Lorisleiva\Actions\Concerns\AsAction;
7+
use Spatie\WebhookServer\WebhookCall;
88

99
class SendDiscordTestNotification
1010
{
@@ -14,20 +14,19 @@ public function handle(array $webhooks)
1414
{
1515
if (! count($webhooks)) {
1616
Notification::make()
17-
->title('You need to add webhook urls!')
17+
->title('You need to add Discord urls!')
1818
->warning()
1919
->send();
2020

2121
return;
2222
}
2323

2424
foreach ($webhooks as $webhook) {
25-
$payload = [
26-
'content' => '👋 Testing the Discord notification channel.',
27-
];
28-
29-
// Send the request using Laravel's HTTP client
30-
$response = Http::post($webhook['discord_webhook_url'], $payload);
25+
WebhookCall::create()
26+
->url($webhook['url'])
27+
->payload(['content' => '👋 Testing the Discord notification channel.'])
28+
->doNotSign()
29+
->dispatch();
3130
}
3231

3332
Notification::make()

app/Actions/Notifications/SendWebhookTestNotification.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class SendWebhookTestNotification
1010
{
1111
use AsAction;
1212

13-
public function handle(array $urls)
13+
public function handle(array $webhooks)
1414
{
15-
if (! count($urls)) {
15+
if (! count($webhooks)) {
1616
Notification::make()
1717
->title('You need to add webhook urls!')
1818
->warning()
@@ -21,9 +21,9 @@ public function handle(array $urls)
2121
return;
2222
}
2323

24-
foreach ($urls as $url) {
24+
foreach ($webhooks as $webhook) {
2525
WebhookCall::create()
26-
->url($url['url'])
26+
->url($webhook['url'])
2727
->payload(['message' => '👋 Testing the Webhook notification channel.'])
2828
->doNotSign()
2929
->dispatch();

app/Filament/Pages/Settings/NotificationPage.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ public function form(Form $form): Form
109109
Forms\Components\Repeater::make('discord_webhooks')
110110
->label('Webhooks')
111111
->schema([
112-
Forms\Components\TextInput::make('discord_webhook_url')
113-
->label('Webhook URL')
114-
->required(),
112+
Forms\Components\TextInput::make('url')
113+
->maxLength(2000)
114+
->required()
115+
->url(),
115116
])
116117
->columnSpanFull(),
117118
Forms\Components\Actions::make([
@@ -251,7 +252,7 @@ public function form(Form $form): Form
251252
Forms\Components\Actions::make([
252253
Forms\Components\Actions\Action::make('test webhook')
253254
->label('Test webhook channel')
254-
->action(fn (Forms\Get $get) => SendWebhookTestNotification::run(urls: $get('webhook_urls')))
255+
->action(fn (Forms\Get $get) => SendWebhookTestNotification::run(webhooks: $get('webhook_urls')))
255256
->hidden(fn (Forms\Get $get) => ! count($get('webhook_urls'))),
256257
]),
257258
]),

0 commit comments

Comments
 (0)