Events | laravel-webhook-server-go | Spatie       

 SPATIE  

laravel-webhook-server-go
=========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-webhook-server-go](https://spatie.be/docs/laravel-webhook-server-go/v1)  Events

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-webhook-server-go/v1) 

  Events    
- [ Introduction ](https://spatie.be/docs/laravel-webhook-server-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-webhook-server-go/v1/installation-and-setup)
- [ Sending webhooks ](https://spatie.be/docs/laravel-webhook-server-go/v1/sending-webhooks)
- [ Signing requests ](https://spatie.be/docs/laravel-webhook-server-go/v1/signing-requests)
- [ Retrying failed webhooks ](https://spatie.be/docs/laravel-webhook-server-go/v1/retrying-failed-webhooks)
- [ Transport options ](https://spatie.be/docs/laravel-webhook-server-go/v1/transport-options)
- [ Events ](https://spatie.be/docs/laravel-webhook-server-go/v1/events)
- [ Testing webhooks ](https://spatie.be/docs/laravel-webhook-server-go/v1/testing-webhooks)
- [ Differences from PHP ](https://spatie.be/docs/laravel-webhook-server-go/v1/upgrading)
- [ Testing ](https://spatie.be/docs/laravel-webhook-server-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-webhook-server-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-webhook-server-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-webhook-server-go/v1/support-us)

 Events
======

###  On this page 

1. [ Queued listeners ](#content-queued-listeners)
2. [ Handling delivery failures ](#content-handling-delivery-failures)

The package fires these native Laravel events in the `webhookserver` package:

- `DispatchingWebhookCallEvent` before dispatching the webhook to the queue. Synchronous dispatch does not fire it.
- `WebhookCallSucceededEvent` when the receiver returned a final `2xx` response.
- `WebhookCallFailedEvent` when an attempt failed, whether or not another attempt will follow.
- `FinalWebhookCallFailedEvent` when no further delivery attempts will be made.

All events expose `Delivery`, containing `Method`, `URL`, `Payload`, `Body`, `Headers`, `Meta`, `Tags` and `ID`. The ID stays the same across attempts. Headers include the signature when signing is enabled. Raw payloads are byte slices. JSON payloads and metadata are JSON-encoded byte slices. Decode them into your application's typed values when needed.

Result events embed `Result`, which also exposes:

- `Attempt`, the attempt number starting at one.
- `Response`, a buffered snapshot or nil when no response was received.
- `ErrorType` and `ErrorMessage`, empty for a successful attempt.
- `Elapsed`, the measured attempt duration.

`Response` contains `Status`, `Header`, `Body` and the final `URL`. Bodies are readable repeatedly without consuming a stream. HTTP failures report `*httpclient.StatusError`. Connection failures report `*httpclient.ConnectionError`. Go uses buffered results and elapsed time rather than Guzzle cookies, PSR streams or handler-specific transfer statistics. A custom `Config.Client` can install native HTTP tracing for more detailed metrics.

Register listeners explicitly:

```
Listeners: []laravel.Listener{
    laravel.Listen(func(ctx context.Context, e webhookserver.FinalWebhookCallFailedEvent) error {
        slog.WarnContext(ctx, "Webhook delivery failed", "id", e.Delivery.ID, "attempt", e.Attempt)
        return nil
    }),
},
```

Queued listeners
--------------------------------------------------------------------------------------------------------

Use `laravel.ListenQueued` with a constructor that copies the event into your own serializable job. Laravel registers the listener job type automatically:

```
type RecordDelivery struct {
    Event webhookserver.WebhookCallSucceededEvent
}

func (j RecordDelivery) Handle(ctx context.Context) error {
    slog.InfoContext(ctx, "Webhook delivered", "id", j.Event.Delivery.ID, "status", j.Event.Response.Status)
    return nil
}

// In laravel.Options.Listeners:
laravel.ListenQueued(func(e webhookserver.WebhookCallSucceededEvent) RecordDelivery {
    return RecordDelivery{Event: e}
})
```

Jobs and events preserve binary bodies as base64 JSON values. Durations are encoded as integer nanoseconds and nil retry policies retain their meaning. Metadata must be JSON-serializable. Store binary metadata as Go byte slices so JSON encodes it as base64. HTTP header strings must be valid HTTP values.

Encoding is not encryption. Queue messages contain signed bodies, headers, metadata and responses. Check queue size limits and protect access to sensitive data. The signing secret is not part of the prepared delivery.

Handling delivery failures
--------------------------------------------------------------------------------------------------------------------------------------

Listen to `WebhookCallFailedEvent` for every failed attempt, or `FinalWebhookCallFailedEvent` to act only when delivery has stopped. Enable `ThrowOnFailure` to mark the native queue job as failed and return its error on final failure.

Laravel event transaction timing applies. Listener errors propagate, and a failing listener may cause native queue error handling rather than the package's response-aware policy. Keep listeners reliable and use queued listeners for slow work.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
