> ## 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: Send Messages

> Send WhatsApp messages from Laravel Rust with the Hypersender package: text, replies, images, files, video, voice notes, locations and polls.

Before you start, install the package and set your keys as described in the [installation guide](https://docs.hypersender.com/v2/packages-and-sdks/laravel-rust/installation.md). To receive and answer messages, see [WhatsApp webhooks](https://docs.hypersender.com/v2/packages-and-sdks/laravel-rust/whatsapp/whatsapp-webhooks.md).

## Overview

Inject `Whatsapp` with `Inject<Whatsapp>` in a handler, listener, job or command. Every method sends one request to your instance and returns the HTTP client's `Response`. Non-2xx answers come back as errors.

Chat IDs are the phone number with country code and no `+`, followed by `@c.us`, for example `20123456789@c.us`. Group chat IDs end in `@g.us`. [What is a chat ID?](https://docs.hypersender.com/v2/api-reference/whatsapp/what-is-chatid.md)

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

pub async fn notify(whatsapp: Inject<Whatsapp>) -> laravel::Result<()> {
    whatsapp.send_text("20123456789@c.us", "Your order has shipped").await?;

    Ok(())
}
```

## Text

```rust theme={null}
// Plain text.
whatsapp.send_text("20123456789@c.us", "Hello from Laravel Rust").await?;

// Reply to a message, quoting it.
whatsapp
    .reply_text("20123456789@c.us", "Yes, it ships today", "false_20123456789@c.us_3EB0C767D26A1D3E")
    .await?;
```

`safe_send_text` sends the same message, but Hypersender shows typing and waits a moment first, so the message looks typed by a person. Use it for messages to people who haven't written to you recently. [(learn more)](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-text-safe.md)

```rust theme={null}
whatsapp.safe_send_text("20123456789@c.us", "Hi Sara, your table is ready").await?;
```

## Images, files, video and voice

Each media type has a URL method and an upload method. Upload methods take a Laravel `Attachment`.

```rust theme={null}
use laravel::http::client::Attachment;

// From a URL, with an optional caption.
whatsapp
    .send_image_url("20123456789@c.us", "https://example.com/menu.png", Some("Today's menu"))
    .await?;

// From disk. Relative paths resolve against your app's base path.
whatsapp
    .send_image_file("20123456789@c.us", Attachment::from_path("storage/app/menu.png"), None)
    .await?;
```

| Method | Arguments |
| - | - |
| `send_image_url` | `chat_id`, `url`, `caption: Option<&str>` |
| `send_image_file` | `chat_id`, `file: Attachment`, `caption: Option<&str>` |
| `send_file_url` | `chat_id`, `url`, `file_name: Option<&str>`, `caption: Option<&str>` |
| `send_file` | `chat_id`, `file: Attachment`, `caption: Option<&str>` |
| `send_video_url` | `chat_id`, `url`, `as_note: bool`, `caption: Option<&str>` |
| `send_video_file` | `chat_id`, `file: Attachment`, `as_note: bool`, `caption: Option<&str>` |
| `send_voice_url` | `chat_id`, `url` |
| `send_voice_file` | `chat_id`, `file: Attachment` |

`as_note: true` sends the video as a round video note.

Send a PDF invoice with its own file name:

```rust theme={null}
whatsapp
    .send_file_url(
        "20123456789@c.us",
        "https://example.com/invoices/1042.pdf",
        Some("invoice-1042.pdf"),
        Some("Your invoice"),
    )
    .await?;
```

To send a file the user just uploaded, use `Attachment::from_data(bytes, "name.pdf")`, or attach it inside the request handler. Laravel deletes temporary uploads once the request ends, so don't pass an upload to a queued job.

## Location

```rust theme={null}
whatsapp
    .send_location("20123456789@c.us", 30.0444, 31.2357, "Our Cairo office")
    .await?;
```

## Poll

```rust theme={null}
use serde_json::json;

whatsapp
    .send_poll(
        "20123456789@c.us",
        json!({
            "name": "Which day works for the call?",
            "options": ["Monday", "Tuesday", "Wednesday"],
            "multipleAnswers": false,
        }),
    )
    .await?;
```

Votes arrive as `PollVote` events. See [WhatsApp webhooks](https://docs.hypersender.com/v2/packages-and-sdks/laravel-rust/whatsapp/whatsapp-webhooks.md).

## Read the response

```rust theme={null}
let response = whatsapp.send_text("20123456789@c.us", "Hello").await?;
let body: serde_json::Value = response.json()?;
```

For long sends Hypersender may queue the request and answer with a queued request ID. Check it later with [`get_queued_request`](https://docs.hypersender.com/v2/packages-and-sdks/laravel-rust/whatsapp/chats-and-contacts#queued-requests).

## Next steps

> [card] [Chats and contacts](https://docs.hypersender.com/v2/packages-and-sdks/laravel-rust/whatsapp/chats-and-contacts.md)
>
> Seen, typing, reactions, deletes, contact checks and any other endpoint.

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


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