Skip to main content

babelforce_manager_sdk/resources/
dialer.rs

1use std::sync::Arc;
2
3use crate::error::{map_manager_err, ManagerError};
4use crate::gen::manager::apis::configuration::Configuration;
5use crate::gen::manager::apis::{dialer_api, outbound_api, reporting_call_api};
6use crate::gen::manager::models;
7use crate::http::collect_all;
8use crate::retry::{with_retry, RetryPolicy};
9
10/// Dialer runtime & reporting — `/api/v2/dialer`, with a nested `behaviours` sub-resource.
11pub struct DialerResource {
12    pub(crate) cfg: Arc<Configuration>,
13    pub(crate) retry: RetryPolicy,
14    /// Dialer behaviours — `/api/v2/outbound/dialer-behaviours`.
15    pub behaviours: DialerBehavioursResource,
16}
17
18impl DialerResource {
19    /// Get inbound dialer runtime information — `/api/v2/dialer`.
20    pub async fn info(&self) -> Result<models::GenericItemResponse, ManagerError> {
21        with_retry(&self.retry, true, || {
22            dialer_api::get_dialer_info(self.cfg.as_ref())
23        })
24        .await
25        .map_err(map_manager_err)
26    }
27
28    /// Flush dialer tasks — by `id`, or `all`.
29    pub async fn flush(
30        &self,
31        id: Option<&str>,
32        all: Option<bool>,
33    ) -> Result<models::DefaultV2MessageResponse, ManagerError> {
34        with_retry(&self.retry, false, || {
35            dialer_api::flush_dialer(self.cfg.as_ref(), id, all)
36        })
37        .await
38        .map_err(map_manager_err)
39    }
40
41    /// List all dialer simple reporting calls (auto-paginated).
42    pub async fn simple_reporting(&self) -> Result<Vec<models::ReportingCall>, ManagerError> {
43        collect_all(&self.retry, map_manager_err, |page| async move {
44            let r = reporting_call_api::list_dialer_simple_reporting_calls(
45                self.cfg.as_ref(),
46                Some(page),
47                None,
48            )
49            .await?;
50            Ok((r.items, r.pagination.pages, r.pagination.current))
51        })
52        .await
53    }
54}
55
56/// Dialer behaviours — `/api/v2/outbound/dialer-behaviours`.
57pub struct DialerBehavioursResource {
58    pub(crate) cfg: Arc<Configuration>,
59    pub(crate) retry: RetryPolicy,
60}
61
62impl DialerBehavioursResource {
63    /// List all dialer behaviours (auto-paginated).
64    pub async fn list_all(&self) -> Result<Vec<models::DialerBehaviour>, ManagerError> {
65        collect_all(&self.retry, map_manager_err, |page| async move {
66            let r =
67                outbound_api::list_dialer_behaviours(self.cfg.as_ref(), Some(page), None).await?;
68            Ok((r.items, r.pagination.pages, r.pagination.current))
69        })
70        .await
71    }
72
73    /// Create a dialer behaviour.
74    pub async fn create(
75        &self,
76        body: models::DialerBehaviourWriteBody,
77    ) -> Result<models::DialerBehaviourItemResponse, ManagerError> {
78        with_retry(&self.retry, false, || {
79            outbound_api::create_dialer_behaviour(self.cfg.as_ref(), body.clone())
80        })
81        .await
82        .map_err(map_manager_err)
83    }
84
85    /// Get a dialer behaviour by id.
86    pub async fn get(&self, id: &str) -> Result<models::DialerBehaviourItemResponse, ManagerError> {
87        with_retry(&self.retry, true, || {
88            outbound_api::get_dialer_behaviour(self.cfg.as_ref(), id)
89        })
90        .await
91        .map_err(map_manager_err)
92    }
93
94    /// Update a dialer behaviour.
95    pub async fn update(
96        &self,
97        id: &str,
98        body: models::DialerBehaviourWriteBody,
99    ) -> Result<models::DialerBehaviourItemResponse, ManagerError> {
100        with_retry(&self.retry, false, || {
101            outbound_api::update_dialer_behaviour(self.cfg.as_ref(), id, body.clone())
102        })
103        .await
104        .map_err(map_manager_err)
105    }
106
107    /// Delete a dialer behaviour.
108    pub async fn delete(&self, id: &str) -> Result<(), ManagerError> {
109        with_retry(&self.retry, false, || {
110            outbound_api::delete_dialer_behaviour(self.cfg.as_ref(), id)
111        })
112        .await
113        .map_err(map_manager_err)?;
114        Ok(())
115    }
116}