forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendWebhookTestNotification.php
More file actions
52 lines (44 loc) · 1.54 KB
/
SendWebhookTestNotification.php
File metadata and controls
52 lines (44 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace App\Actions\Notifications;
use App\Models\Result;
use App\Services\SpeedtestFakeResultGenerator;
use Filament\Notifications\Notification;
use Lorisleiva\Actions\Concerns\AsAction;
use Spatie\WebhookServer\WebhookCall;
class SendWebhookTestNotification
{
use AsAction;
public function handle(array $webhooks)
{
if (! count($webhooks)) {
Notification::make()
->title('You need to add webhook URLs!')
->warning()
->send();
return;
}
// Generate a fake Result (NOT saved to database)
$fakeResult = SpeedtestFakeResultGenerator::completed();
foreach ($webhooks as $webhook) {
WebhookCall::create()
->url($webhook['url'])
->payload([
'result_id' => fake()->uuid(),
'site_name' => 'Webhook Notification Testing',
'isp' => $fakeResult->data['isp'],
'ping' => $fakeResult->ping,
'download' => $fakeResult->download,
'upload' => $fakeResult->upload,
'packetLoss' => $fakeResult->data['packetLoss'],
'speedtest_url' => $fakeResult->data['result']['url'],
'url' => url('/admin/results'),
])
->doNotSign()
->dispatch();
}
Notification::make()
->title('Test webhook notification sent.')
->success()
->send();
}
}