Implement generic webhook delivery
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace App\Actions\Notifications;
|
||||
|
||||
use App\Enums\NotificationChannel;
|
||||
use App\Enums\NotificationDeliveryStatus;
|
||||
use App\Models\NotificationAction;
|
||||
use App\Models\NotificationDeliveryLog;
|
||||
|
||||
class QueueTicketStatusChangedNotificationDeliveries
|
||||
{
|
||||
@@ -12,11 +15,28 @@ class QueueTicketStatusChangedNotificationDeliveries
|
||||
->enabled()
|
||||
->where('project_id', $event->payload->projectId)
|
||||
->where('event_type', $event->payload->eventType->value)
|
||||
->get(['id'])
|
||||
->get(['channel', 'id'])
|
||||
->each(function (NotificationAction $notificationAction) use ($event): void {
|
||||
$notificationDeliveryLogId = null;
|
||||
|
||||
if ($notificationAction->channel === NotificationChannel::Webhook) {
|
||||
$notificationDeliveryLogId = NotificationDeliveryLog::query()->create([
|
||||
'attempt_count' => 0,
|
||||
'channel' => $notificationAction->channel,
|
||||
'delivery_status' => NotificationDeliveryStatus::Pending,
|
||||
'event_type' => $event->payload->eventType,
|
||||
'notification_action_id' => $notificationAction->id,
|
||||
'payload_metadata' => [
|
||||
'project_key' => $event->payload->projectKey,
|
||||
'ticket_key' => $event->payload->ticketKey,
|
||||
],
|
||||
])->id;
|
||||
}
|
||||
|
||||
DeliverNotificationAction::dispatch(
|
||||
$notificationAction->id,
|
||||
$event->payload,
|
||||
notificationActionId: $notificationAction->id,
|
||||
payload: $event->payload,
|
||||
notificationDeliveryLogId: $notificationDeliveryLogId,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user