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

/// Global settings — `/api/v2/settings`, grouped by scope (`app`, `telephony`, `audit`, `ui`,
/// `retention`). Each section has a read accessor and a `set_*` writer that return the section's
/// typed response.
pub struct SettingsResource {
    pub(crate) cfg: SharedCfg<Configuration>,
    pub(crate) retry: RetryPolicy,
}

/// Generate a read/write method pair for one settings section.
macro_rules! section {
    ($get:ident, $set:ident, $gen_get:ident, $gen_set:ident, $resp:ident, $req:ident, $label:literal) => {
        #[doc = concat!("Read the ", $label, " settings.")]
        pub async fn $get(&self) -> Result<models::$resp, ManagerError> {
            let cfg = self.cfg.get().await?;
            let cfg = cfg.as_ref();
            with_retry(&self.retry, true, || api::$gen_get(cfg))
                .await
                .map_err(map_manager_err)
        }

        #[doc = concat!("Update the ", $label, " settings.")]
        pub async fn $set(&self, body: models::$req) -> Result<models::$resp, ManagerError> {
            let cfg = self.cfg.get().await?;
            let cfg = cfg.as_ref();
            with_retry(&self.retry, false, || {
                api::$gen_set(cfg, Some(body.clone()))
            })
            .await
            .map_err(map_manager_err)
        }
    };
}

impl SettingsResource {
    section!(
        app_customer_logging,
        set_app_customer_logging,
        get_settings_for_app_customer_logging,
        update_settings_for_app_customer_logging,
        SettingsAppCustomerLoggingResponse,
        SettingsAppCustomerLoggingRequest,
        "app customer-logging"
    );
    section!(
        app_conversations,
        set_app_conversations,
        get_settings_for_app_conversations,
        update_settings_for_app_conversations,
        SettingsAppConversationsResponse,
        SettingsAppConversationsRequest,
        "app conversations"
    );
    section!(
        app_integrations,
        set_app_integrations,
        get_settings_for_app_integrations,
        update_settings_for_app_integrations,
        SettingsAppIntegrationsResponse,
        SettingsAppIntegrationsRequest,
        "app integrations"
    );
    section!(
        app_agent_status,
        set_app_agent_status,
        get_settings_for_app_agent_status,
        update_settings_for_app_agent_status,
        SettingsAppAgentStatusResponse,
        SettingsAppAgentStatusRequest,
        "app agent-status"
    );
    section!(
        telephony_agent_inbound,
        set_telephony_agent_inbound,
        get_settings_for_telephony_agent_inbound,
        update_settings_for_telephony_agent_inbound,
        SettingsTelephonyAgentInboundResponse,
        SettingsTelephonyAgentInboundRequest,
        "telephony agent-inbound"
    );
    section!(
        telephony_agent_outbound,
        set_telephony_agent_outbound,
        get_settings_for_telephony_agent_outbound,
        update_settings_for_telephony_agent_outbound,
        SettingsTelephonyAgentOutboundResponse,
        SettingsTelephonyAgentOutboundRequest,
        "telephony agent-outbound"
    );
    section!(
        telephony_agent_recording,
        set_telephony_agent_recording,
        get_settings_for_telephony_agent_recording,
        update_settings_for_telephony_agent_recording,
        SettingsTelephonyAgentRecordingResponse,
        SettingsTelephonyAgentRecordingRequest,
        "telephony agent-recording"
    );
    section!(
        telephony_agent_wrapup,
        set_telephony_agent_wrapup,
        get_settings_for_telephony_agent_wrapup,
        update_settings_for_telephony_agent_wrapup,
        SettingsTelephonyAgentWrapupResponse,
        SettingsTelephonyAgentWrapupRequest,
        "telephony agent-wrapup"
    );
    section!(
        telephony_post_call,
        set_telephony_post_call,
        get_settings_for_telephony_post_call,
        update_settings_for_telephony_post_call,
        SettingsTelephonyPostCallResponse,
        SettingsTelephonyPostCallRequest,
        "telephony post-call"
    );
    section!(
        audit_default,
        set_audit_default,
        get_settings_for_audit_default,
        update_settings_for_audit_default,
        SettingsAuditDefaultResponse,
        SettingsAuditDefaultRequest,
        "audit default"
    );
    section!(
        ui_i18n,
        set_ui_i18n,
        get_settings_for_ui_i18n,
        update_settings_for_ui_i18n,
        SettingsUiI18nResponse,
        SettingsUiI18nRequest,
        "UI i18n"
    );
    section!(
        retention_periods,
        set_retention_periods,
        get_settings_for_retention_periods,
        update_settings_for_retention_periods,
        SettingsRetentionPeriodsResponse,
        SettingsRetentionPeriodsRequest,
        "retention periods"
    );

    /// List every customer setting across all scopes.
    pub async fn list_all(&self) -> Result<models::SettingsListResponse, ManagerError> {
        let cfg = self.cfg.get().await?;
        let cfg = cfg.as_ref();
        with_retry(&self.retry, true, || api::list_all_settings(cfg))
            .await
            .map_err(map_manager_err)
    }

    /// List all customer settings in a scope.
    pub async fn list_in_scope(
        &self,
        scope: &str,
    ) -> Result<models::SettingsListResponse, ManagerError> {
        let cfg = self.cfg.get().await?;
        let cfg = cfg.as_ref();
        with_retry(&self.retry, true, || {
            api::list_settings_in_scope(cfg, scope)
        })
        .await
        .map_err(map_manager_err)
    }

    /// Reset a single setting to its default.
    pub async fn clear(
        &self,
        scope: &str,
        key: &str,
    ) -> Result<models::SettingItemResponse, ManagerError> {
        let cfg = self.cfg.get().await?;
        let cfg = cfg.as_ref();
        with_retry(&self.retry, false, || api::clear_setting(cfg, scope, key))
            .await
            .map_err(map_manager_err)
    }

    /// Reset all settings in a scope to their defaults.
    pub async fn clear_in_scope(
        &self,
        scope: &str,
    ) -> Result<models::SettingsListResponse, ManagerError> {
        let cfg = self.cfg.get().await?;
        let cfg = cfg.as_ref();
        with_retry(&self.retry, false, || {
            api::clear_settings_in_scope(cfg, scope)
        })
        .await
        .map_err(map_manager_err)
    }

    /// Reset every customer setting across all scopes to their defaults.
    pub async fn clear_all(&self) -> Result<models::SettingsListResponse, ManagerError> {
        let cfg = self.cfg.get().await?;
        let cfg = cfg.as_ref();
        with_retry(&self.retry, false, || api::clear_all_settings(cfg))
            .await
            .map_err(map_manager_err)
    }
}