infobip-sms-sdk 0.1.0

Async Rust SDK for the Infobip SMS API: send messages, manage scheduled bulks, query delivery reports and logs, fetch inbound SMS, and parse webhook payloads.
Documentation
use reqwest::Method;

use crate::api::{decode_response, ErrorKind};
use crate::client::Client;
use crate::error::Error;
use crate::models::inbox::{InboundQuery, InboundSmsResponse};

impl Client {
    /// Fetches inbound (mobile-originated) SMS.
    ///
    /// Wraps `GET /sms/1/inbox/reports`. Use this when you can't
    /// expose a real-time webhook for inbound messages. **Each
    /// message is returned only once** per call; the response also
    /// reports
    /// [`pending_message_count`](crate::models::inbox::InboundSmsResponse::pending_message_count)
    /// so you know whether to poll again.
    ///
    /// Receiving inbound SMS at all requires a phone number / short
    /// code purchased through Infobip with a configured forwarding
    /// endpoint.
    ///
    /// # Errors
    ///
    /// On non-2xx responses, returns
    /// [`Error::Exception`].
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use infobip_sms::Client;
    /// use infobip_sms::models::inbox::InboundQuery;
    ///
    /// # async fn run(client: Client) -> Result<(), infobip_sms::Error> {
    /// let inbox = client
    ///     .get_inbound_messages(&InboundQuery {
    ///         limit: Some(100),
    ///         ..Default::default()
    ///     })
    ///     .await?;
    /// for msg in inbox.results {
    ///     println!("{:?}: {:?}", msg.from, msg.text);
    /// }
    /// # Ok(()) }
    /// ```
    pub async fn get_inbound_messages(
        &self,
        query: &InboundQuery,
    ) -> Result<InboundSmsResponse, Error> {
        let response = self
            .request(Method::GET, "sms/1/inbox/reports")?
            .query(query)
            .send()
            .await?;
        decode_response(response, ErrorKind::Legacy).await
    }
}