babelforce-manager-sdk 0.44.0

Rust SDK for the babelforce manager APIs — auth, user & agent management, call reporting, metrics, and task automations.
Documentation
use crate::error::{map_manager_err, ManagerError};
use crate::gen::manager::apis::configuration::Configuration;
use crate::gen::manager::apis::manager_api as api;
use crate::gen::manager::models;
use crate::retry::{with_retry, RetryPolicy};
use crate::token::SharedCfg;

/// Call/automation sessions — `/api/v2/sessions`.
pub struct SessionsResource {
    pub(crate) cfg: SharedCfg<Configuration>,
    pub(crate) retry: RetryPolicy,
}

impl SessionsResource {
    /// Create a new session.
    pub async fn create(&self) -> Result<models::SessionResponse, ManagerError> {
        let cfg = self.cfg.get().await?;
        let cfg = cfg.as_ref();
        with_retry(&self.retry, false, || api::create_session(cfg))
            .await
            .map_err(map_manager_err)
    }

    /// Get a session (its variables) by id.
    pub async fn get(&self, id: &str) -> Result<models::SessionResponse, ManagerError> {
        let cfg = self.cfg.get().await?;
        let cfg = cfg.as_ref();
        with_retry(&self.retry, true, || api::get_session_variables(cfg, id))
            .await
            .map_err(map_manager_err)
    }

    /// Update a session's variables.
    pub async fn update_variables(
        &self,
        id: &str,
        variables: std::collections::HashMap<String, serde_json::Value>,
    ) -> Result<models::SessionResponse, ManagerError> {
        let cfg = self.cfg.get().await?;
        let cfg = cfg.as_ref();
        with_retry(&self.retry, false, || {
            api::update_session_variables(cfg, id, Some(variables.clone()))
        })
        .await
        .map_err(map_manager_err)
    }
}