Save 44% with yearly billing, 5 months free.View Plans
textbee Logotextbee.dev
Send SMS from Laravel Rust: Notification Channel, Queues and Tests

Send SMS from Laravel Rust: Notification Channel, Queues and Tests

Send SMS from a Laravel Rust app through your own Android phone. A textbee notification channel, queued sends, a scheduled text and tests, built and run on laravel-rust 0.1.5.

TT

textbee team

11 min read
Share

Laravel Rust can send SMS out of the box, but its built-in sender in version 0.1.5 is Telnyx (or a log writer for development). To send from your own Android phone and SIM instead, add textbee as a notification channel. It is about 80 lines of Rust: one config section, one send function that calls POST /api/v1/gateway/send-sms, and a #[notification::channel] impl. Your notifications then use #[via(Textbee)], and notification::to(&user).queue(...) works like any built-in channel.

We built every snippet below in a new laravel new --rust app with SQLite on 3 December 2026 (laravel-rust 0.1.5, Rust 1.100.1). The tests pass, and the direct send and the queued notification both sent real texts from a phone.

TL;DR

  • No crate to install. Laravel Rust has an HTTP client (laravel::http::client) and documented custom notification channels. That is all textbee needs.
  • One send function posts recipients and message with an x-api-key header and returns the smsBatchId.
  • A Textbee channel wraps that function, so notifications get a #[via(Textbee)] method next to mail and sms.
  • Queue it: notification::to(&user).queue(OrderShipped { .. }). The worker tries a failed delivery up to 3 times. It does not retry most 4xx errors, such as a wrong API key.
  • Test it with client::fake() and notification::fake(). No network, no real texts.
  • Cost: textbee Free covers 300 messages a month. Pro is $14.99 a month for up to 5,000. You pay your SIM plan, not a per-message fee.

What does Laravel Rust ship for SMS?

Laravel released Laravel Rust as a beta on 1 December 2026 (announcement). It has an sms module with sms::to(number).send(text), and an Sms notification channel. In 0.1.5 every sender is one of two kinds: Telnyx for production, or a log writer for development (SMS docs). add_sender takes only those kinds, so textbee cannot be a sender.

What you can add is a notification channel. The notifications guide calls these "package channels" and shows a Discord channel as the example. A textbee channel follows the same pattern. Your app keeps the built-in Sms channel for Telnyx if you use it, and adds Textbee for texts from your own number.

Laravel says releases before 1.0 may include breaking changes. If a future version changes the channel API, the send function in step 2 stays the same: it is a plain HTTP call.

Before you start

  • The textbee app on an Android phone: download it and follow the quickstart.
  • An API key from the textbee dashboard. See API keys.
  • Rust 1.99 or later and the Laravel CLI. Create an app with laravel new my-app --rust.
  • A database for users and queued jobs. New apps use Postgres. SQLite works too (database docs).

Step 1: Add the credentials

Add the key to .env:

TEXTBEE_API_KEY=your-api-key
# Optional. Without it, your default device sends.
TEXTBEE_DEVICE_ID=

Then add a config section next to the Sentry one in src/config/services.rs:

#[derive(Debug, Clone, Section)]
pub struct Textbee {
    #[env("TEXTBEE_API_KEY", required)]
    pub api_key: String,
    #[env("TEXTBEE_DEVICE_ID")]
    pub device_id: Option<String>,
    #[env("TEXTBEE_URL", default = "https://api.textbee.dev/api/v1")]
    pub url: String,
}

You do not register the section. Laravel reads it when the app starts, and because the key is required, the app does not start without it. TEXTBEE_URL lets a self-hosted textbee server use the same code.

Step 2: Write the send function

Create src/textbee.rs and add pub mod textbee; to src/lib.rs:

use laravel::http::client;
use laravel::notification;
use serde::{Deserialize, Serialize};
use serde_json::json;

use crate::config::services::Textbee as TextbeeConfig;

/// Send one text to one or more numbers from your Android phone.
/// Returns textbee's batch id, which you can use to follow delivery.
pub async fn send(recipients: &[&str], text: &str) -> laravel::Result<String> {
    let config = laravel::config();
    let textbee = config.section::<TextbeeConfig>();

    let mut body = json!({ "recipients": recipients, "message": text });
    if let Some(device_id) = &textbee.device_id {
        body["deviceId"] = json!(device_id);
    }

    let response = client::post(format!("{}/gateway/send-sms", textbee.url))
        .header("x-api-key", &textbee.api_key)
        .json(body)
        .ensure_successful()
        .await?;

    let sent: Sent = response.json()?;

    Ok(sent.data.sms_batch_id)
}

#[derive(Deserialize)]
struct Sent {
    data: SentData,
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct SentData {
    sms_batch_id: String,
}

Two details:

  • laravel::config() returns a guard. Keep it in a variable (config) before you call section, so the guard lives as long as the section. In our build, let textbee = laravel::config().section::<TextbeeConfig>(); failed to compile because the guard was dropped too early.
  • ensure_successful() turns any non-2xx response into an error. The error keeps the response, which matters for retries in step 5.

notification and Serialize are for step 3. Until then, the compiler warns that they are unused.

You can call this function from a handler, a job or a command. For example, textbee::send(&["+15555550123"], "Your table is ready.").await?.

What number format do recipients need?

Any number your phone could text. A local number works when it is in the same country as the SIM that sends. Use the international format (+15555550123) to reach a number in another country. Short codes work too. See phone number format.

Step 3: Add the textbee channel

Add this to the end of src/textbee.rs:

/// The textbee notification channel.
#[derive(Clone, Copy)]
pub struct Textbee;

/// A text message for the textbee channel.
#[derive(Serialize, Deserialize)]
pub struct TextbeeMessage {
    pub text: String,
}

impl TextbeeMessage {
    pub fn new(text: impl Into<String>) -> Self {
        Self { text: text.into() }
    }
}

#[notification::channel(name = "textbee")]
impl Textbee {
    async fn send(phone: String, message: TextbeeMessage) -> laravel::Result<()> {
        send(&[&phone], &message.text).await?;

        Ok(())
    }

    fn check(message: &TextbeeMessage) -> laravel::Result<()> {
        if message.text.trim().is_empty() {
            return Err(laravel::abort_with(500, "a text message can't be empty"));
        }

        Ok(())
    }
}

The argument types of send set the channel's route (String, the phone number) and its message (TextbeeMessage). Both are serializable, because a queued job stores them. check runs when the notification builds the message, so an empty text fails in your handler and in your tests, not later on the queue worker.

Keep name = "textbee". Queued jobs store this name. If you move or rename the struct later, jobs that are already in the queue still find the channel.

Step 4: Write a notification

Users need a phone number. Create a migration with laravel make:migration add_phone_to_users_table and add a nullable column:

use laravel::db::AnyTransaction;

pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> {
    tx.schema()
        .alter("users", |table| {
            table.string("phone").nullable();
        })
        .await
}

Add pub phone: Option<String>, to the User model in src/models/user.rs and run laravel migrate.

Now create src/notifications/mod.rs (and add pub mod notifications; to src/lib.rs):

use laravel::notification;
use laravel::notification::Receives;

use crate::models::User;
use crate::textbee::{Textbee, TextbeeMessage};

pub struct OrderShipped {
    pub order_number: String,
}

#[notification]
impl OrderShipped {
    #[via(Textbee)]
    fn textbee(&self, user: &User) -> TextbeeMessage {
        TextbeeMessage::new(format!("Hi {}, order #{} is on its way.", user.name, self.order_number))
    }
}

impl Receives<Textbee> for User {
    fn route(&self) -> Option<String> {
        self.phone.clone()
    }
}

Receives<Textbee> tells the channel where a user gets texts. When route returns None, the send skips the textbee channel for that user without an error. A notification can have a mail method in the same impl, so users without a phone number still get the email.

Step 5: Queue it from a handler

Texts are network calls, so queue them and let the HTTP response return at once. This handler texts a user when an order ships (src/http/handlers/order_shipped.rs):

use laravel::notification;
use laravel::prelude::*;

use crate::models::User;
use crate::notifications::OrderShipped;

pub async fn store(Params((user_id, order)): Params<(u64, String)>) -> laravel::Result<Json<serde_json::Value>> {
    let user = User::find_or_fail(user_id).await?;

    notification::to(&user)
        .queue(OrderShipped { order_number: order })
        .await?;

    Ok(Json(serde_json::json!({ "queued": true })))
}

Add pub mod order_shipped; to src/http/handlers/mod.rs, then register the route in src/routes/api.rs:

use crate::http::handlers::order_shipped;

// Inside `routes`:
route.post("/users/{user}/orders/{order}/shipped", order_shipped::store);

A worker sends the queued texts. laravel dev starts one for you on your machine. In production, run:

Shell
laravel queue:work

In our run the worker took the job and the text left the phone a few seconds later. To send at once and wait for textbee to accept the text, use .send(...) instead of .queue(...).

What happens when a send fails?

In 0.1.5, Laravel Rust runs a queued channel delivery up to 3 times: the second try 10 seconds after the first, the third a minute later. It does not retry a 4xx response, except 408, 409 and 429. For textbee that means:

  • 400 (no enabled device, or a message over 9,000 bytes), 401 (wrong API key) and 404 (TEXTBEE_DEVICE_ID is not a device on your account): the job fails at once. Retrying cannot fix them.
  • 429 (a plan limit is used up): retried, and the retries fail too until the limit resets.
  • 5xx or no connection: retried.

A 200 response means textbee accepted the text, not that the recipient got it. The phone still has to send it over the cellular network. Use the smsBatchId with delivery status or a webhook to follow it.

Step 6: Send from the terminal

A console command is useful for a first test and for scripts. Create src/console/sms.rs and add mod sms; to src/console/mod.rs:

use laravel::console::{Console, command};

use crate::textbee;

/// Send a text message through textbee.
#[command("sms:send")]
pub async fn send_sms(
    /// The recipient's number, such as +15555550123.
    to: String,
    /// The text to send.
    text: String,
    console: &mut Console,
) -> laravel::Result<()> {
    let batch_id = textbee::send(&[&to], &text).await?;

    console.success(format!("Sent. Batch {batch_id}"));

    Ok(())
}

Laravel finds the command by itself:

Shell
laravel sms:send +15555550123 "Hello from Laravel Rust"
# Sent. Batch 64f2c0a1b2c3d4e5f6a7b8c9

Step 7: Send a text on a schedule

The scheduler can text you a daily number. A new app already has a schedule function in src/console/mod.rs. Add these imports at the top of that file:

use laravel::prelude::*;

use crate::models::User;
use crate::textbee;

Add one line inside the existing schedule function:

schedule.call(text_signups).daily_at("08:00");

Then add the task at the end of the file:

async fn text_signups() -> laravel::Result<()> {
    let since = laravel::now().minus(1.days());
    let count = User::query().filter(User::created_at.ge(since)).count().await?;

    textbee::send(&["+15555550123"], &format!("{count} new signups in the last 24 hours.")).await?;

    Ok(())
}

laravel schedule:list shows the task with its next run. The scheduler uses UTC, so 08:00 is 8am UTC. On your machine, laravel schedule:work runs the scheduler. On the server, run schedule:run once a minute from cron, as the scheduling docs describe.

How do I test SMS sends without sending texts?

Use the fakes. client::fake() answers the HTTP call, and notification::fake() records notifications. Put this in tests/textbee.rs:

use app::models::User;
use app::notifications::OrderShipped;
use app::textbee::Textbee;
use laravel::http::client;
use laravel::model::create;
use laravel::notification;
use laravel::testing::prelude::*;

#[laravel::test]
async fn it_posts_the_text_to_textbee(_app: Application) -> laravel::Result<()> {
    let http = client::fake().with(
        "api.textbee.dev/*",
        json!({ "data": { "success": true, "smsBatchId": "batch-1", "recipientCount": 1 } }),
    );

    let batch_id = app::textbee::send(&["+15555550123"], "Your order shipped.").await?;

    assert_eq!(batch_id, "batch-1");
    http.assert_sent(|request| {
        request.url() == "https://api.textbee.dev/api/v1/gateway/send-sms"
            && request.has_header("x-api-key", "test-key")
            && request.data()["recipients"][0] == "+15555550123"
            && request.data()["message"] == "Your order shipped."
    });

    Ok(())
}

#[laravel::test]
async fn the_shipped_route_queues_the_text(app: Application) -> laravel::Result<()> {
    let user = create!(User {
        name: "Ada",
        email: "[email protected]",
        password: "password",
        phone: "+15555550123",
    })
    .await?;
    let notifications = notification::fake();

    app.post(format!("/api/users/{}/orders/1042/shipped", user.id))
        .await
        .assert_ok();

    notifications.assert_sent_to_where::<OrderShipped>(&user, |sent| {
        sent.queued()
            && sent
                .message::<Textbee>()
                .is_some_and(|m| m.text == "Hi Ada, order #1042 is on its way.")
    });

    Ok(())
}

The tests need a key, because the config section requires one. Add it to the overrides in src/testing.rs. The URL override keeps the tests on the fake even when your .env points at a self-hosted server:

("TEXTBEE_API_KEY", "test-key"),
("TEXTBEE_URL", "https://api.textbee.dev/api/v1"),

Then run cargo test.

Frequently asked questions

Can I set textbee as the SMS_SENDER?

Not in laravel-rust 0.1.5. Every SMS sender is a Telnyx sender or a log writer, and you cannot add another kind. Use the textbee channel for notifications and textbee::send for direct sends. Both work next to the built-in SMS module.

Do I need a Telnyx account?

No. The textbee channel does not use the built-in SMS module. Your texts go out from the SIM in your Android phone, from your own number. You do not rent a number. In the US you also skip 10DLC registration (why).

Can I send one text to many numbers?

Yes. textbee::send takes a slice: textbee::send(&["+15555550123", "+15555550124"], "Store closes at 6pm."). Each recipient counts as one message on your plan. For many different texts in one call, use the bulk endpoint.

Can my Laravel Rust app receive texts?

Yes. Turn on receiving in the textbee app, then set a webhook URL in the dashboard. textbee posts each received SMS to that URL. Add a route for it in src/routes/api.rs. See receive SMS with webhooks.

What does it cost?

textbee Free covers 300 messages a month. Pro is $14.99 a month for up to 5,000 messages, and Scale is $29.99 a month for up to 25,000. Texts go out on your SIM plan, so there is no per-message fee. See pricing.

I use Laravel with PHP. Is there a guide?

Yes: Send SMS from Laravel (PHP) covers the Http facade, a custom notification channel and queued jobs.

Keep going

Download textbee and send your first text from Laravel Rust.

Get more textbee in Google Search

Add textbee.dev as a preferred source. Our posts show up more often in your Google results.

Add as a preferred source