babelforce-manager-sdk 0.42.1

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::manager_api as api;
use crate::gen::manager::models;
use crate::retry::{with_retry, RetryPolicy};

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

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

    /// Get a session (its variables) by id.
    pub async fn get(&self, id: &str) -> Result<models::SessionResponse, ManagerError> {
        with_retry(&self.retry, true, || {
            api::get_session_variables(self.cfg.as_ref(), 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> {
        with_retry(&self.retry, false, || {
            api::update_session_variables(self.cfg.as_ref(), id, Some(variables.clone()))
        })
        .await
        .map_err(map_manager_err)
    }
}