> ## 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 WhatsApp, SMS and OTP Package: Installation

> Install the Hypersender package for Laravel Rust with cargo add, register its service provider, and send WhatsApp, SMS and OTP messages from your Rust app.

## Getting started

`hypersender-laravel` is the Hypersender package for [Laravel Rust](https://laravel.com/rust). It gives your app three services, `Whatsapp`, `Sms` and `Otp`, and two webhook routes that turn every Hypersender webhook into a Laravel event.

It is the Rust version of the [Laravel (PHP) package](https://docs.hypersender.com/v2/packages-and-sdks/laravel/installation.md) and reads the same environment variables.

## Prerequisites

* **Rust 1.99 or higher**, the version Laravel Rust needs.
* **A Laravel Rust app.** Create one with `laravel new example-app --rust`.
* **A Hypersender account.** Sign up at [Hypersender](https://app.hypersender.com) to get your API key and Instance ID.

> [!TIP]
>
> You can find your API key and Instance ID in the Hypersender dashboard

![Hypersender Dashboard API Key](https://mintcdn.com/hypersender/oXq9uVgBJOXaL1p2/images/docs/whatsapp/img/api-key-and-instance-id.jpeg?fit=max\&auto=format\&n=oXq9uVgBJOXaL1p2\&q=85\&s=addd172bddcb335eeb1eb029473bac71)

## Installation

**1. Add the crate**

From your app's root directory:

```bash theme={null}
cargo add hypersender-laravel
```

**2. Register the service provider**

Laravel Rust packages are wired in through a service provider. Add it to `with_providers` in `src/app.rs`:

```rust src/app.rs theme={null}
use laravel::Application;

Application::configure()
    .with_providers(|providers| {
        providers.add(hypersender_laravel::HypersenderServiceProvider);
    })
```

**3. Add your keys to .env**

Set only the products you use:

```ini .env theme={null}
HYPERSENDER_WHATSAPP_API_KEY=
HYPERSENDER_WHATSAPP_INSTANCE_ID=

HYPERSENDER_SMS_API_KEY=
HYPERSENDER_SMS_INSTANCE_ID=

HYPERSENDER_OTP_API_KEY=
HYPERSENDER_OTP_INSTANCE_ID=
```

## Send your first message

Inject `Whatsapp` into any handler, listener, job or command:

```rust theme={null}
use hypersender_laravel::Whatsapp;
use laravel::container::Inject;

pub async fn send(whatsapp: Inject<Whatsapp>) -> laravel::Result<String> {
    let response = whatsapp
        .send_text("20123456789@c.us", "Hello from Laravel Rust")
        .await?;

    Ok(response.text().into_owned())
}
```

Register it like any route, for example `route.get("/send", send);` in `src/routes/web.rs`.

Every method returns the Laravel HTTP client's `Response`. When Hypersender answers with a non-2xx status, the method returns an error, so `?` stops on it. Read the body with `response.json::<serde_json::Value>()?` or `response.text()`.

If an instance ID is missing, resolving that service fails with a message naming the variable to set, for example `HYPERSENDER_WHATSAPP_INSTANCE_ID`.

## Configuration

All settings live in the `HypersenderConfig` section:

| Variable | Default |
| - | - |
| `HYPERSENDER_WHATSAPP_API_KEY`, `HYPERSENDER_WHATSAPP_INSTANCE_ID` | None |
| `HYPERSENDER_SMS_API_KEY`, `HYPERSENDER_SMS_INSTANCE_ID` | None |
| `HYPERSENDER_OTP_API_KEY`, `HYPERSENDER_OTP_INSTANCE_ID` | None |
| `HYPERSENDER_WHATSAPP_WEBHOOK_AUTHORIZATION_SECRET` | None (no check) |
| `HYPERSENDER_SMS_WEBHOOK_AUTHORIZATION_SECRET` | None (no check) |
| `HYPERSENDER_WHATSAPP_WEBHOOK_ROUTE` | `/whatsapp/webhook` (served under `/api`) |
| `HYPERSENDER_SMS_WEBHOOK_ROUTE` | `/sms/webhook` (served under `/api`) |
| `HYPERSENDER_WHATSAPP_BASE_URL` | `https://app.hypersender.com/api/whatsapp/v2` |
| `HYPERSENDER_SMS_BASE_URL` | `https://app.hypersender.com/api/sms/v1` |
| `HYPERSENDER_OTP_BASE_URL` | `https://app.hypersender.com/api/otp/v2` |

To change a value in code, edit the section in `with_config`. Your app's callbacks run after the package's, so they win:

```rust src/app.rs theme={null}
use hypersender_laravel::HypersenderConfig;

Application::configure()
    .with_config(|config, _| {
        config.section_mut::<HypersenderConfig>().whatsapp_webhook_route = "/hooks/whatsapp".into();
    })
```

## Testing your app

The package sends requests through Laravel's HTTP client, so `client::fake()` intercepts them and your tests never reach Hypersender:

```rust theme={null}
use laravel::http::client;
use laravel::testing::prelude::*;
use serde_json::json;

#[laravel::test]
async fn shipping_an_order_sends_a_whatsapp_message(app: Application) {
    let http = client::fake().with("app.hypersender.com/*", json!({ "id": "msg-1" }));

    app.get("/send").await.assert_ok();

    http.assert_sent(|request| request.url().ends_with("/send-text"));
}
```

## Next steps

> [card] [Send WhatsApp messages](https://docs.hypersender.com/v2/packages-and-sdks/laravel-rust/whatsapp/send-messages.md)
>
> Text, images, files, video, voice, locations and polls.

> [card] [WhatsApp webhooks](https://docs.hypersender.com/v2/packages-and-sdks/laravel-rust/whatsapp/whatsapp-webhooks.md)
>
> Incoming messages as Laravel events.

> [card] [Send SMS](https://docs.hypersender.com/v2/packages-and-sdks/laravel-rust/sms/send-sms.md)
>
> SMS from your own Android phone.

> [card] [OTP](https://docs.hypersender.com/v2/packages-and-sdks/laravel-rust/otp/otp.md)
>
> Send and check one-time codes, or send a login link.


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