Skip to content

Commit

Permalink
send to all users at once
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Sep 28, 2021
1 parent 9e13e81 commit c24aa58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Http/Controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -53,7 +54,7 @@ private function handleAlert($notificationClass, $payload)
return response()->noContent();
}

Notification::send($users, new $notificationClass($payload));
(new AnonymousNotifiable)->notify(new $notificationClass($payload, $users));

return response('Webhook handled');
}
Expand Down
4 changes: 3 additions & 1 deletion src/Notifications/AbstractAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class AbstractAlert extends Notification
protected string $event;
protected string $subject;

public function __construct(protected $alert = [])
public function __construct(protected $alert, protected $users)
{
}

Expand All @@ -39,11 +39,13 @@ public function toArray(): array
return [
'event' => $this->event,
'date' => Arr::get($this->alert, 'date'),
'id' => Arr::get($this->alert, 'service.id'),
'is_up' => Arr::get($this->alert, 'alert.is_up'),
'output' => Arr::get($this->alert, 'alert.short_output'),
'subject' => $this->subject,
'test' => Arr::get($this->alert, 'service.name'),
'type' => Arr::get($this->alert, 'service.monitoring_service_type'),
'users' => $this->users,
];
}
}

0 comments on commit c24aa58

Please sign in to comment.