Skip to main content

Crate sms_core

Crate sms_core 

Source
Expand description

§SMS Core

Core traits and types for the smskit multi-provider SMS abstraction.

This crate provides the fundamental building blocks for SMS operations:

  • SmsClient trait for sending SMS messages
  • InboundWebhook trait for processing incoming webhooks
  • SmsRouter for dispatching sends to named providers
  • FallbackClient for try-in-order provider chaining
  • Common types for requests, responses, and errors

§Sending a message

use sms_core::{SendRequest, SmsClient};

// Any SMS provider implements SmsClient
let response = client.send(SendRequest {
    to: "+1234567890",
    from: "+0987654321",
    text: "Hello world!"
}).await?;

§Owned requests for async contexts

When you need to hold a request across .await points, use OwnedSendRequest:

use sms_core::OwnedSendRequest;

let req = OwnedSendRequest::new("+1234567890", "+0987654321", "Hello!");
// Can be moved across .await boundaries freely
let response = client.send(req.as_ref()).await?;

§Routing to named providers

use sms_core::SmsRouter;

let router = SmsRouter::new()
    .with("plivo", plivo_client)
    .with("aws-sns", sns_client);

// Dispatch by name — callers don't need provider crate imports
let response = router.send_via("plivo", SendRequest { .. }).await?;

§Fallback chaining

use sms_core::FallbackClient;

let client = FallbackClient::new(vec![primary_client, backup_client]);
// Tries each provider in order; returns first success
let response = client.send(SendRequest { .. }).await?;

Structs§

FallbackClient
An SmsClient that tries a list of providers in order, returning the first successful response.
InboundMessage
A provider-normalized inbound SMS message (e.g. a reply or MO message).
InboundRegistry
A runtime registry that maps provider names to InboundWebhook implementations.
OwnedSendRequest
An owned variant of SendRequest for use in async contexts.
SendRequest
A borrowing SMS send request.
SendResponse
The response returned after a successful SMS send.
SmsRouter
Routes SMS sends to a named provider without requiring the caller to know about individual provider crate types.
WebhookResponse
A framework-agnostic webhook HTTP response.
WebhookResult
Result of webhook processing, containing both the message and response info.

Enums§

HttpStatus
Minimal HTTP status codes used by WebhookResponse.
SmsError
Errors that can occur during SMS send operations.
WebhookError
Errors specific to inbound webhook processing.

Traits§

InboundWebhook
Provider-agnostic interface for processing inbound SMS webhooks.
SmsClient
The primary trait for sending SMS messages.

Functions§

fallback_id
Generate a random UUID v4 string, useful as a fallback message ID when the provider does not return one.

Type Aliases§

Headers
Lightweight header representation (Vec<(name, value)>) that avoids coupling the core crate to any particular HTTP framework.