> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hypersender.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel Rust SMS Webhooks and Events

> Receive SMS webhooks in Laravel Rust as events: delivery reports, failed and expired messages, incoming SMS and phone heartbeats.

## Overview

The service provider adds this route to your app's `api` group:

```
POST /api/sms/webhook
```

Add it as the webhook URL of your SMS instance in the [Hypersender dashboard](https://app.hypersender.com). The URL must be public, so use a tunnel such as ngrok in development.

If you set an **Authorization Secret** on the webhook, put the same value in `.env`, and requests without it get a `401`:

```ini .env theme={null}
HYPERSENDER_SMS_WEBHOOK_AUTHORIZATION_SECRET=your-secret
```

To change the path, set `HYPERSENDER_SMS_WEBHOOK_ROUTE`. It stays under `/api`.

## Events

Each webhook becomes an event in `hypersender_laravel_rust::events`. The `payload` field holds the full body: `event` and `data`.

| Webhook | Event |
| - | - |
| `message.notification.scheduled` | `MessageNotificationScheduled` |
| `message.notification.failed` | `MessageNotificationFailed` |
| `message.phone.sent` | `MessagePhoneSent` |
| `message.phone.delivered` | `MessagePhoneDelivered` |
| `message.phone.received` | `MessagePhoneReceived` |
| `message.phone.ussd` | `MessagePhoneUssd` |
| `message.send.failed` | `MessageSendFailed` |
| `message.send.expired` | `MessageSendExpired` |
| `message.call.missed` | `MessageCallMissed` |
| `phone.heartbeat.received` | `PhoneHeartbeatReceived` |
| `phone.heartbeat.online` | `PhoneHeartbeatOnline` |
| `phone.heartbeat.offline` | `PhoneHeartbeatOffline` |
| `phone.heartbeat.missed` | `PhoneHeartbeatMissed` |
| `phone.heartbeat.disabled` | `PhoneHeartbeatDisabled` |
| `phone.logout` | `PhoneLogout` |

Each event's fields are in the [SMS webhooks reference](https://docs.hypersender.com/v2/api-reference/sms-webhooks/sms-webhooks-introduction.md).

## Handle incoming SMS

```rust src/listeners/incoming_sms.rs theme={null}
use hypersender_laravel_rust::events::MessagePhoneReceived;
use laravel::event::{Event, listener};

#[listener]
pub async fn incoming_sms(event: Event<MessagePhoneReceived>) {
    let message = &event.payload["data"];

    tracing::info!(
        from = message["from_phone_number"].as_str(),
        text = message["content"].as_str(),
        "SMS received",
    );
}
```

## Track delivery

`request_id` in `data` is the ID you passed to `send_message`, so you can match a report to your own record:

```rust theme={null}
use hypersender_laravel_rust::events::{MessagePhoneDelivered, MessageSendFailed};
use laravel::event::{Event, listener};

#[listener]
pub async fn delivered(event: Event<MessagePhoneDelivered>) {
    let request_id = event.payload["data"]["request_id"].as_str().unwrap_or_default();
    tracing::info!(request_id, "SMS delivered");
}

#[listener]
pub async fn failed(event: Event<MessageSendFailed>) {
    let data = &event.payload["data"];
    tracing::warn!(request_id = data["request_id"].as_str(), reason = data["failure_reason"].as_str(), "SMS failed");
}
```

## Queued listeners

The webhook answers Hypersender right away and runs listeners in a background task, which isn't retried. Use `#[listener(queued)]` for work that must finish. Every event derives `Queueable`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.