Events | laravel-webhook-server-rust | Spatie       

 SPATIE  

laravel-webhook-server-rust
===========================

spatie.be/open-source

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

 Version   v1      

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

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

 Events
======

###  On this page 

1. [ Replace event types ](#content-replace-event-types)
2. [ Replace the job ](#content-replace-the-job)

The package publishes native Laravel events:

- `DispatchingWebhookCallEvent` before queued dispatch, but not synchronous dispatch.
- `WebhookCallSucceededEvent` after a 2xx response.
- `WebhookCallFailedEvent` for every unsuccessful attempt.
- `FinalWebhookCallFailedEvent` when no further attempts will follow.

Each event wraps `EventData` in its public `.0` field. It contains the prepared webhook, attempt number, optional response, error category/message and elapsed duration. Dispatching uses attempt zero; delivery attempts start at one. The webhook contains method, URL, original payload, signed bytes, headers, local metadata, tags and stable UUID.

Response snapshots preserve status, final URL, every header value and binary body. Raw request bytes and response bytes serialize as byte arrays, so queued listeners do not lose non-UTF-8 content. These values are not encrypted. Check queue message limits before including large payloads or responses.

Register listeners with Laravel's normal `with_events` configuration. Events derive `Event` and `Queueable`, so Laravel queued listeners can consume them too. Listener errors propagate; a failed listener can cause a worker attempt to fail independently of HTTP delivery. Receivers should process delivery IDs idempotently.

Replace event types
-----------------------------------------------------------------------------------------------------------------

Implement `WebhookEvents::dispatch` and set `Config.events` to an `Arc` of your implementation. The hook receives `EventKind` and `EventData`, and returns `WebhookFuture<laravel::Result<()>>`. It may dispatch your application's own Laravel event types instead of, or alongside, the defaults. Register it on every worker as well as the dispatching application.

Replace the job
-----------------------------------------------------------------------------------------------------

```
use std::sync::Arc;
use laravel::queue::{Attempt, Queueable, job};
use spatie_laravel_webhook_server::{CallWebhookJob, Config, LaravelDispatcher, PreparedWebhook};

#[derive(Queueable)]
struct ApplicationWebhookJob { webhook: PreparedWebhook }

#[job(tries = 4294967295)]
impl ApplicationWebhookJob {
    async fn handle(self, attempt: &Attempt) -> laravel::Result<()> {
        // Add application-specific behavior, or replace delivery entirely.
        CallWebhookJob::from(self.webhook).run(attempt).await
    }
}

let config = Config {
    dispatcher: Arc::new(LaravelDispatcher::new(|webhook| ApplicationWebhookJob { webhook })),
    ..Config::default()
};
```

Set the same dispatcher per call with `use_job`. The dispatcher constructs the custom job for both queued and synchronous calls and preserves the selected queue/connection. A custom job can wrap the default handler, change middleware, implement cancellation, or provide an entirely different handler. If it delegates retry handling, its static job tries must not truncate the webhook's per-call limit.

The server does not own a database model. Applications can add persistence through their own model types in custom jobs or event listeners without replacing a package-owned model.

 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)
