Struct sendblue::SendblueClient

source ·
pub struct SendblueClient {
    pub api_key: String,
    pub api_secret: String,
    pub client: Client,
    /* private fields */
}
Expand description

Client for the Sendblue API

The SendblueClient struct provides methods for interacting with the Sendblue API.

§Examples

use sendblue::SendblueClient;

let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());

Fields§

§api_key: String§api_secret: String§client: Client

Implementations§

source§

impl SendblueClient

source

pub fn new(api_key: String, api_secret: String) -> Self

Creates a new Sendblue client with the default reqwest client

§Arguments
  • api_key - The API key for authentication
  • api_secret - The API secret for authentication
§Returns
  • SendblueClient - A new Sendblue client instance
§Examples
use sendblue::SendblueClient;

let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
source

pub fn new_with_url( api_key: String, api_secret: String, base_url: String, ) -> Self

Creates a new Sendblue client with a custom base URL

§Arguments
  • api_key - The API key for authentication
  • api_secret - The API secret for authentication
  • base_url - The base URL for the API
§Returns
  • SendblueClient - A new Sendblue client instance

This is a private function and not intended for public use.

source

pub async fn send<T: SendableMessage>( &self, message: &T, ) -> Result<T::ResponseType, SendblueError>

Sends a message using the Sendblue API

§Arguments
  • message - The message to be sent
§Returns
  • MessageResponse - The response from the Sendblue API
  • SendblueError - An error that occurred during the request
§Examples

Sending a normal message:

use sendblue::SendblueClient;
use sendblue::models::MessageBuilder;

#[tokio::main]
async fn main() {
    let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());

    let message = MessageBuilder::new(phonenumber::parse(None, "+10722971673").unwrap())
        .content("Hello, world!".into())
        .build()
        .unwrap();

    match client.send(&message).await {
        Ok(response) => println!("Message sent: {:?}", response),
        Err(e) => eprintln!("Error sending message: {:?}", e),
    }
}

Sending a group message:

use sendblue::SendblueClient;
use sendblue::models::{MessageBuilder, GroupMessage};

#[tokio::main]
async fn main() {
    let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());

    let group_message = MessageBuilder::<GroupMessage>::new_group()
        .numbers(vec![phonenumber::parse(None, "+10722971673").unwrap(), phonenumber::parse(None, "+10722971673").unwrap()])
        .content("Hello, group!".into())
        .build()
        .unwrap();

    match client.send::<>(&group_message).await {
        Ok(response) => println!("Group message sent: {:?}", response),
        Err(e) => eprintln!("Error sending group message: {:?}", e),
    }
}
source

pub async fn get_messages( &self, params: GetMessagesParams, ) -> Result<GetMessagesResponse, SendblueError>

Retrieves messages using the Sendblue API

§Arguments
  • params - The parameters for filtering and paginating messages
§Returns
  • GetMessagesResponse - The response containing the retrieved messages
  • SendblueError - An error that occurred during the request
§Examples
use sendblue::SendblueClient;
use sendblue::models::{GetMessagesParamsBuilder};

#[tokio::main]
async fn main() {
    let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());

    let params = GetMessagesParamsBuilder::new()
        .limit(Some(50))
        .offset(Some(0))
        .number(Some(phonenumber::parse(None, "+10722971673").unwrap()))
        .from_date(Some("2023-06-15 12:00:00".into()))
        .cid(None)
        .build();

    match client.get_messages(params).await {
        Ok(response) => println!("Messages retrieved: {:?}", response.messages),
        Err(e) => eprintln!("Error retrieving messages: {:?}", e),
    }
}
source

pub async fn evaluate_service( &self, evaluate_service: &EvaluateService, ) -> Result<EvaluateServiceResponse, SendblueError>

Evaluates if a number can send/receive iMessages using the Sendblue API

§Arguments
  • evaluate_service - The evaluation request containing the phone number in E.164 format
§Returns
  • EvaluateServiceResponse - The response containing the evaluation result
  • SendblueError - An error that occurred during the request
§Examples
use sendblue::SendblueClient;
use sendblue::models::{EvaluateServiceBuilder};

#[tokio::main]
async fn main() {
    let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());

let evaluate_service = EvaluateServiceBuilder::new()
    .number(phonenumber::parse(None, "+10722971673").unwrap())
    .build();

    match client.evaluate_service(&evaluate_service).await {
        Ok(response) => println!("Evaluation result: {:?}", response),
        Err(e) => eprintln!("Error evaluating number: {:?}", e),
    }
}
source

pub async fn send_typing_indicator( &self, number: &PhoneNumber, ) -> Result<TypingIndicatorResponse, SendblueError>

Sends a typing indicator to a recipient using the Sendblue API

§Arguments
  • number - The recipient’s phone number in E.164 format
§Returns
  • TypingIndicatorResponse - The response from the Sendblue API
  • SendblueError - An error that occurred during the request
§Examples
use sendblue::SendblueClient;

#[tokio::main]
async fn main() {
    let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());

    let number = phonenumber::parse(None, "+10722971673").unwrap();

    match client.send_typing_indicator(&number).await {
        Ok(response) => println!("Typing indicator sent: {:?}", response),
        Err(e) => eprintln!("Error sending typing indicator: {:?}", e),
    }
}

Auto Trait Implementations§

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

§

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>,

§

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