Implement webhook inspector
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\WebhookEndpoint;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Contracts\Events\ShouldDispatchAfterCommit;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
|
||||
class WebhookRequestReceived implements ShouldBroadcast, ShouldDispatchAfterCommit
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets;
|
||||
|
||||
private ?bool $isPublic;
|
||||
|
||||
public function __construct(
|
||||
public readonly string $endpointId,
|
||||
public readonly string $requestId,
|
||||
?bool $isPublic = null,
|
||||
) {
|
||||
$this->isPublic = $isPublic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
$isPublic = $this->isPublic ?? WebhookEndpoint::query()
|
||||
->whereKey($this->endpointId)
|
||||
->value('is_public');
|
||||
|
||||
return [
|
||||
$isPublic
|
||||
? new Channel('webhooks.'.$this->endpointId)
|
||||
: new PrivateChannel('webhooks.'.$this->endpointId),
|
||||
];
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'webhook.request.received';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{endpointId: string, requestId: string}
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'endpointId' => $this->endpointId,
|
||||
'requestId' => $this->requestId,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user