Skip to main content

Crate opensms

Crate opensms 

Source
Expand description

Async Rust SDK for the OpenSMS prepaid SMS API.

Send SMS and OTPs, run batches, look up numbers, manage contacts, templates, webhooks, numbers and sender IDs, and read the wallet and analytics. Built on reqwest and serde, with one transport layer that owns bearer auth, Idempotency-Keys, retries on 429/5xx/network errors (honouring Retry-After), and error mapping to OpensmsError.

§Quickstart

use opensms::{Client, SendMessage};

#[tokio::main]
async fn main() -> Result<(), opensms::OpensmsError> {
    let client = Client::new(std::env::var("OPENSMS_API_KEY").unwrap())?;
    let message = client
        .messages()
        .send(&SendMessage::new("+254700000012", "Your order has shipped"))
        .await?;
    println!("{} {:?}", message.id, message.status);
    Ok(())
}

Re-exports§

pub use webhook::construct_event;
pub use webhook::verify_signature;
pub use webhook::VerifyOptions;

Modules§

webhook
Webhook signature verification.

Structs§

Analytics
Accessed as client.analytics().
AnalyticsOverview
Headline analytics.
AnalyticsPoint
One time-series bucket.
AnalyticsQuery
Query shared by the analytics methods. range (Nd) cannot be combined with from/to.
AnalyticsRow
One row of a dimension breakdown (by_country, by_carrier, by_sender_id).
Attempt
One delivery attempt of a message.
Batch
A message batch.
BatchItemInput
One row of a batch create request.
BatchReport
Validation report of a batch.
BatchReportRow
One row of a BatchReport.
BatchStopResult
Result of batches.stop.
Batches
Accessed as client.batches().
Carrier
A carrier in a country.
CheckSenderId
Query for sender_ids.check.
Client
OpenSMS API client. Cheap to clone; clones share one connection pool.
ClientBuilder
Builder for Client. Construct with Client::builder.
Compliance
Accessed as client.compliance().
Contact
A contact.
ContactGroup
A contact group.
ContactGroups
Accessed as client.contact_groups().
Contacts
Accessed as client.contacts().
ContentRule
A workspace-visible content rule.
Countries
Accessed as client.countries().
Country
A destination country in the public catalog.
CountryContentRule
A content rule inside CountryRules.
CountryRules
Compliance rules for a country.
CreateBatch
Body of batches.create.
CreateContact
Body of contacts.create.
CreateContactGroup
Body of contact_groups.create.
CreateLookup
Body of lookups.create.
CreateSenderId
Body of sender_ids.create.
CreateSenderIdDraft
Body of sender_ids.create_draft.
CreateSuppression
Body of suppressions.create and one row of suppressions.import.
CreateTemplate
Body of templates.create.
CreateTopup
Body of wallet.create_topup.
CreateWebhook
Body of webhooks.create.
HttpRequest
One HTTP request as handed to a Transport.
HttpResponse
One HTTP response as returned by a Transport.
Inbound
Accessed as client.inbound().
InboundMessage
An inbound SMS.
LedgerEntry
A wallet ledger entry.
LedgerParams
Query for wallet.ledger (pages by before, not by cursor).
ListBatchItems
Query for batches.list_items.
ListMessages
Query for messages.list.
ListParams
limit + cursor for cursor-paginated lists.
Lookup
A number lookup.
Lookups
Accessed as client.lookups().
Message
An SMS message. Also used for batch items, which carry fewer fields.
Messages
Accessed as client.messages().
Money
An { amount, currency } money value.
Number
A virtual number.
NumberQuery
Query for numbers.available and body of numbers.assign.
NumberRule
An inbound routing rule on a number.
NumberRuleInput
Body of numbers.create_rule and numbers.update_rule.
Numbers
Accessed as client.numbers().
OpensmsError
Returned for every non-2xx response, for transport failures that survive all retries, for invalid arguments, and for webhook signature failures.
Otp
Accessed as client.otp().
OtpSendResult
Result of otp.send.
OtpVerifyResult
Result of otp.verify.
Page
A cursor page: { items, next_cursor }.
Paginator
Lazily walks every page of a cursor list. Create with crate::Client::paginate or paginate.
PriceEntry
One price-list row.
PriceList
A workspace price list.
Pricing
Accessed as client.pricing().
PricingParams
Query for pricing.get.
QuietHours
A quiet-hours window.
QuoteSenderId
Query for sender_ids.quote.
ReplayDelivery
Body of webhooks.replay_delivery.
ReplyInbound
Body of inbound.reply.
RequestOptions
Per-call options for methods that send an Idempotency-Key.
ReqwestTransport
The default Transport, backed by reqwest.
Route
A public routable route in a country.
Sandbox
Accessed as client.sandbox().
SandboxMessage
A sandbox message with its rendered text (including OTP codes).
SendMessage
Body of messages.send.
SendOtp
Body of otp.send.
SendToGroup
Body of contact_groups.send: set text or template_id.
SenderDocument
A sender registration document (metadata only).
SenderId
A sender ID.
SenderIdCheck
Result of sender_ids.check.
SenderIdDraft
A sender ID application draft.
SenderIdQuote
Result of sender_ids.quote.
SenderIdQuoteEntry
One fee line of a SenderIdQuote.
SenderIds
Accessed as client.sender_ids().
StatusResult
A { status } acknowledgement (webhook test and replay).
Suppression
A suppressed destination.
SuppressionImportResult
Result of suppressions.import.
Suppressions
Accessed as client.suppressions().
Template
A message template.
Templates
Accessed as client.templates().
TokioSleeper
The default Sleeper, backed by tokio::time::sleep.
Topup
An initialized top-up.
UpdateContact
Body of contacts.update (PATCH; unset fields are kept).
UpdateContactGroup
Body of contact_groups.update.
UpdateSenderId
Body of sender_ids.update (amend a rejected sender ID).
UpdateSenderIdDraft
Body of sender_ids.update_draft; version must be the current one.
UpdateTemplate
Body of templates.update.
UpdateWebhook
Body of webhooks.update: a full replacement, every field required.
VerifyOtp
Body of otp.verify.
Wallet
Accessed as client.wallet().
WalletBalance
A wallet balance.
WebhookDelivery
One webhook delivery.
WebhookEndpoint
A webhook endpoint.
WebhookEvent
A verified webhook event envelope.
Webhooks
Accessed as client.webhooks().

Enums§

ErrorKind
What kind of failure an OpensmsError describes.

Constants§

USER_AGENT
The User-Agent sent on every request.

Traits§

Sleeper
Waits between retry attempts. Tests inject one that returns immediately.
Transport
Sends one HTTP request. Return Err for network failures and timeouts (anything with no HTTP response); every HTTP status is an Ok.

Functions§

paginate
Build a Paginator from a closure that fetches one page given the cursor (None for the first page).
rfc3339
Format a time as an RFC 3339 UTC string with second precision, for example 2026-09-24T12:00:00Z. Use it for scheduled_at and analytics from/to.
uuid_v4
A random (version 4) UUID, 36 characters.

Type Aliases§

BoxFuture
A boxed, Send future, used by the Transport and Sleeper traits.
Result
Convenience alias for results returned by the SDK.