Messages

Struct Messages 

Source
pub struct Messages<'a> { /* private fields */ }
Expand description

Messages resource for sending and managing SMS.

Implementations§

Source§

impl<'a> Messages<'a>

Source

pub async fn send(&self, request: SendMessageRequest) -> Result<Message>

Sends an SMS message.

§Arguments
  • request - The send message request
§Example
use sendly::{Sendly, SendMessageRequest};

let client = Sendly::new("sk_live_v1_xxx");

let message = client.messages().send(SendMessageRequest {
    to: "+15551234567".to_string(),
    text: "Hello from Sendly!".to_string(),
    message_type: None,
}).await?;

println!("Sent: {}", message.id);
Source

pub async fn send_to( &self, to: impl Into<String>, text: impl Into<String>, ) -> Result<Message>

Sends an SMS message with simple parameters.

§Arguments
  • to - Recipient phone number in E.164 format
  • text - Message content
§Example
use sendly::Sendly;

let client = Sendly::new("sk_live_v1_xxx");

let message = client.messages()
    .send_to("+15551234567", "Hello!")
    .await?;
Source

pub async fn list( &self, options: Option<ListMessagesOptions>, ) -> Result<MessageList>

Lists messages.

§Arguments
  • options - Optional query options
§Example
use sendly::{Sendly, ListMessagesOptions, MessageStatus};

let client = Sendly::new("sk_live_v1_xxx");

// List all
let messages = client.messages().list(None).await?;

// With options
let messages = client.messages().list(Some(
    ListMessagesOptions::new()
        .limit(50)
        .status(MessageStatus::Delivered)
)).await?;
Source

pub async fn get(&self, id: &str) -> Result<Message>

Gets a message by ID.

§Arguments
  • id - Message ID
§Example
use sendly::Sendly;

let client = Sendly::new("sk_live_v1_xxx");

let message = client.messages().get("msg_abc123").await?;
println!("Status: {}", message.status);
Source

pub fn iter( &self, options: Option<ListMessagesOptions>, ) -> impl Stream<Item = Result<Message>> + '_

Iterates over all messages with automatic pagination.

§Arguments
  • options - Optional query options
§Example
use sendly::Sendly;
use futures::StreamExt;
use tokio::pin;

let client = Sendly::new("sk_live_v1_xxx");
let messages = client.messages();
let stream = messages.iter(None);
pin!(stream);
while let Some(result) = stream.next().await {
    let message = result?;
    println!("{}: {}", message.id, message.to);
}
Source§

impl<'a> Messages<'a>

Source

pub async fn schedule( &self, request: ScheduleMessageRequest, ) -> Result<ScheduledMessage>

Schedules an SMS message for future delivery.

§Arguments
  • request - The schedule message request
§Example
use sendly::{Sendly, ScheduleMessageRequest};

let client = Sendly::new("sk_live_v1_xxx");

let scheduled = client.messages().schedule(ScheduleMessageRequest {
    to: "+15551234567".to_string(),
    text: "Reminder: Your appointment is tomorrow!".to_string(),
    scheduled_at: "2025-01-20T10:00:00Z".to_string(),
    from: None,
    message_type: None,
}).await?;

println!("Scheduled: {}", scheduled.id);
Source

pub async fn list_scheduled( &self, options: Option<ListScheduledMessagesOptions>, ) -> Result<ScheduledMessageList>

Lists scheduled messages.

§Arguments
  • options - Optional query options
§Example
use sendly::{Sendly, ListScheduledMessagesOptions};

let client = Sendly::new("sk_live_v1_xxx");

let scheduled = client.messages().list_scheduled(None).await?;
for msg in scheduled {
    println!("{}: {}", msg.id, msg.scheduled_at);
}
Source

pub async fn get_scheduled(&self, id: &str) -> Result<ScheduledMessage>

Gets a scheduled message by ID.

§Arguments
  • id - Scheduled message ID
§Example
use sendly::Sendly;

let client = Sendly::new("sk_live_v1_xxx");

let scheduled = client.messages().get_scheduled("sched_abc123").await?;
println!("Status: {:?}", scheduled.status);
Source

pub async fn cancel_scheduled( &self, id: &str, ) -> Result<CancelScheduledMessageResponse>

Cancels a scheduled message.

§Arguments
  • id - Scheduled message ID
§Example
use sendly::Sendly;

let client = Sendly::new("sk_live_v1_xxx");

let result = client.messages().cancel_scheduled("sched_abc123").await?;
println!("Refunded {} credits", result.credits_refunded);
Source

pub async fn send_batch( &self, request: SendBatchRequest, ) -> Result<BatchMessageResponse>

Sends multiple SMS messages in a batch.

§Arguments
  • request - The batch send request
§Example
use sendly::{Sendly, SendBatchRequest, BatchMessageItem};

let client = Sendly::new("sk_live_v1_xxx");

let result = client.messages().send_batch(SendBatchRequest {
    messages: vec![
        BatchMessageItem {
            to: "+15551234567".to_string(),
            text: "Hello Alice!".to_string(),
        },
        BatchMessageItem {
            to: "+15559876543".to_string(),
            text: "Hello Bob!".to_string(),
        },
    ],
    from: None,
    message_type: None,
}).await?;

println!("Batch {}: {} queued", result.batch_id, result.queued);
Source

pub async fn get_batch(&self, batch_id: &str) -> Result<BatchMessageResponse>

Gets batch status by ID.

§Arguments
  • batch_id - Batch ID
§Example
use sendly::Sendly;

let client = Sendly::new("sk_live_v1_xxx");

let batch = client.messages().get_batch("batch_abc123").await?;
println!("{}/{} sent", batch.sent, batch.total);
Source

pub async fn list_batches( &self, options: Option<ListBatchesOptions>, ) -> Result<BatchList>

Lists batches.

§Arguments
  • options - Optional query options
§Example
use sendly::{Sendly, ListBatchesOptions};

let client = Sendly::new("sk_live_v1_xxx");

let batches = client.messages().list_batches(None).await?;
for batch in batches {
    println!("{}: {:?}", batch.batch_id, batch.status);
}
Source

pub async fn preview_batch( &self, request: SendBatchRequest, ) -> Result<BatchPreviewResponse>

Previews a batch without sending (dry run).

§Arguments
  • request - The batch send request
§Example
use sendly::{Sendly, SendBatchRequest, BatchMessageItem};

let client = Sendly::new("sk_live_v1_xxx");

let preview = client.messages().preview_batch(SendBatchRequest {
    messages: vec![
        BatchMessageItem {
            to: "+15551234567".to_string(),
            text: "Hello Alice!".to_string(),
        },
        BatchMessageItem {
            to: "+15559876543".to_string(),
            text: "Hello Bob!".to_string(),
        },
    ],
    from: None,
    message_type: None,
}).await?;

println!("Can send: {}", preview.can_send);
println!("Credits needed: {}", preview.credits_needed);

Trait Implementations§

Source§

impl<'a> Clone for Messages<'a>

Source§

fn clone(&self) -> Messages<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Messages<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Messages<'a>

§

impl<'a> !RefUnwindSafe for Messages<'a>

§

impl<'a> Send for Messages<'a>

§

impl<'a> Sync for Messages<'a>

§

impl<'a> Unpin for Messages<'a>

§

impl<'a> !UnwindSafe for Messages<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more