babelforce-manager-sdk 0.42.3

Rust SDK for the babelforce manager APIs — auth, user & agent management, call reporting, metrics, and task automations.
Documentation
use std::sync::Arc;

use crate::error::{map_manager_err, ManagerError};
use crate::gen::manager::apis::configuration::Configuration;
use crate::gen::manager::apis::{dialer_api, outbound_api, reporting_call_api};
use crate::gen::manager::models;
use crate::http::collect_all;
use crate::retry::{with_retry, RetryPolicy};

/// Dialer runtime & reporting — `/api/v2/dialer`, with a nested `behaviours` sub-resource.
pub struct DialerResource {
    pub(crate) cfg: Arc<Configuration>,
    pub(crate) retry: RetryPolicy,
    /// Dialer behaviours — `/api/v2/outbound/dialer-behaviours`.
    pub behaviours: DialerBehavioursResource,
}

impl DialerResource {
    /// Get inbound dialer runtime information — `/api/v2/dialer`.
    pub async fn info(&self) -> Result<models::GenericItemResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            dialer_api::get_dialer_info(self.cfg.as_ref())
        })
        .await
        .map_err(map_manager_err)
    }

    /// Flush dialer tasks — by `id`, or `all`.
    pub async fn flush(
        &self,
        id: Option<&str>,
        all: Option<bool>,
    ) -> Result<models::DefaultV2MessageResponse, ManagerError> {
        with_retry(&self.retry, false, || {
            dialer_api::flush_dialer(self.cfg.as_ref(), id, all)
        })
        .await
        .map_err(map_manager_err)
    }

    /// List all dialer simple reporting calls (auto-paginated).
    pub async fn simple_reporting(&self) -> Result<Vec<models::ReportingCall>, ManagerError> {
        collect_all(&self.retry, map_manager_err, |page| async move {
            let r = reporting_call_api::list_dialer_simple_reporting_calls(
                self.cfg.as_ref(),
                Some(page),
                None,
            )
            .await?;
            Ok((r.items, r.pagination.pages, r.pagination.current))
        })
        .await
    }
}

/// Dialer behaviours — `/api/v2/outbound/dialer-behaviours`.
pub struct DialerBehavioursResource {
    pub(crate) cfg: Arc<Configuration>,
    pub(crate) retry: RetryPolicy,
}

impl DialerBehavioursResource {
    /// List all dialer behaviours (auto-paginated).
    pub async fn list_all(&self) -> Result<Vec<models::DialerBehaviour>, ManagerError> {
        collect_all(&self.retry, map_manager_err, |page| async move {
            let r =
                outbound_api::list_dialer_behaviours(self.cfg.as_ref(), Some(page), None).await?;
            Ok((r.items, r.pagination.pages, r.pagination.current))
        })
        .await
    }

    /// Create a dialer behaviour.
    pub async fn create(
        &self,
        body: models::DialerBehaviourWriteBody,
    ) -> Result<models::DialerBehaviourItemResponse, ManagerError> {
        with_retry(&self.retry, false, || {
            outbound_api::create_dialer_behaviour(self.cfg.as_ref(), body.clone())
        })
        .await
        .map_err(map_manager_err)
    }

    /// Get a dialer behaviour by id.
    pub async fn get(&self, id: &str) -> Result<models::DialerBehaviourItemResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            outbound_api::get_dialer_behaviour(self.cfg.as_ref(), id)
        })
        .await
        .map_err(map_manager_err)
    }

    /// Update a dialer behaviour.
    pub async fn update(
        &self,
        id: &str,
        body: models::DialerBehaviourWriteBody,
    ) -> Result<models::DialerBehaviourItemResponse, ManagerError> {
        with_retry(&self.retry, false, || {
            outbound_api::update_dialer_behaviour(self.cfg.as_ref(), id, body.clone())
        })
        .await
        .map_err(map_manager_err)
    }

    /// Delete a dialer behaviour.
    pub async fn delete(&self, id: &str) -> Result<(), ManagerError> {
        with_retry(&self.retry, false, || {
            outbound_api::delete_dialer_behaviour(self.cfg.as_ref(), id)
        })
        .await
        .map_err(map_manager_err)?;
        Ok(())
    }
}