babelforce_manager_sdk/resources/
campaigns.rs1use std::sync::Arc;
2
3use crate::error::{map_manager_err, ManagerError};
4use crate::gen::manager::apis::configuration::Configuration;
5use crate::gen::manager::apis::manager_api as api;
6use crate::gen::manager::apis::outbound_api;
7use crate::gen::manager::models;
8use crate::retry::{with_retry, RetryPolicy};
9
10pub struct CampaignsResource {
12 pub(crate) cfg: Arc<Configuration>,
13 pub(crate) retry: RetryPolicy,
14}
15
16impl CampaignsResource {
17 pub async fn list(&self) -> Result<Vec<models::OutboundCampaign>, ManagerError> {
19 let resp = with_retry(&self.retry, true, || api::list_campaigns(self.cfg.as_ref()))
20 .await
21 .map_err(map_manager_err)?;
22 Ok(resp.items)
23 }
24
25 pub async fn create(
27 &self,
28 body: models::CreateCampaignRequest,
29 ) -> Result<models::OutboundCampaignItemResponse, ManagerError> {
30 with_retry(&self.retry, false, || {
31 api::create_campaign(self.cfg.as_ref(), Some(body.clone()))
32 })
33 .await
34 .map_err(map_manager_err)
35 }
36
37 pub async fn get(
39 &self,
40 id: &str,
41 ) -> Result<models::OutboundCampaignItemResponse, ManagerError> {
42 with_retry(&self.retry, true, || {
43 api::get_campaign(self.cfg.as_ref(), id)
44 })
45 .await
46 .map_err(map_manager_err)
47 }
48
49 pub async fn update(
51 &self,
52 id: &str,
53 body: models::UpdateCampaignRequest,
54 ) -> Result<models::OutboundCampaignItemResponse, ManagerError> {
55 with_retry(&self.retry, false, || {
56 api::update_campaign(self.cfg.as_ref(), id, Some(body.clone()))
57 })
58 .await
59 .map_err(map_manager_err)
60 }
61
62 pub async fn delete(&self, id: &str) -> Result<(), ManagerError> {
64 with_retry(&self.retry, false, || {
65 api::delete_campaign(self.cfg.as_ref(), id)
66 })
67 .await
68 .map_err(map_manager_err)?;
69 Ok(())
70 }
71
72 pub async fn attempts(
74 &self,
75 id: &str,
76 number: Option<&str>,
77 ) -> Result<models::PaginatedAttemptResponse, ManagerError> {
78 with_retry(&self.retry, true, || {
79 outbound_api::list_campaign_attempts(self.cfg.as_ref(), id, number)
80 })
81 .await
82 .map_err(map_manager_err)
83 }
84
85 pub async fn hopper(&self, id: &str) -> Result<models::CampaignHopperResponse, ManagerError> {
87 with_retry(&self.retry, true, || {
88 outbound_api::get_campaign_hopper(self.cfg.as_ref(), id)
89 })
90 .await
91 .map_err(map_manager_err)
92 }
93
94 pub async fn leads(&self, id: &str) -> Result<models::PaginatedLeadResponse, ManagerError> {
96 with_retry(&self.retry, true, || {
97 outbound_api::list_campaign_leads(self.cfg.as_ref(), id)
98 })
99 .await
100 .map_err(map_manager_err)
101 }
102
103 pub async fn processed_leads(
105 &self,
106 id: &str,
107 ) -> Result<models::PaginatedLeadResponse, ManagerError> {
108 with_retry(&self.retry, true, || {
109 outbound_api::list_campaign_processed_leads(self.cfg.as_ref(), id)
110 })
111 .await
112 .map_err(map_manager_err)
113 }
114
115 pub async fn get_list(&self, id: &str) -> Result<models::LeadListItemResponse, ManagerError> {
117 with_retry(&self.retry, true, || {
118 outbound_api::get_campaign_list(self.cfg.as_ref(), id)
119 })
120 .await
121 .map_err(map_manager_err)
122 }
123
124 pub async fn set_list(
126 &self,
127 id: &str,
128 body: models::SetCampaignListRequest,
129 ) -> Result<models::CampaignItemResponse, ManagerError> {
130 with_retry(&self.retry, false, || {
131 outbound_api::set_campaign_list(self.cfg.as_ref(), id, body.clone())
132 })
133 .await
134 .map_err(map_manager_err)
135 }
136
137 pub async fn unset_list(&self, id: &str) -> Result<models::CampaignItemResponse, ManagerError> {
139 with_retry(&self.retry, false, || {
140 outbound_api::unset_campaign_list(self.cfg.as_ref(), id)
141 })
142 .await
143 .map_err(map_manager_err)
144 }
145
146 pub async fn set_list_by_id(
148 &self,
149 id: &str,
150 list_id: &str,
151 ) -> Result<models::CampaignItemResponse, ManagerError> {
152 with_retry(&self.retry, false, || {
153 outbound_api::set_campaign_list_by_id(self.cfg.as_ref(), id, list_id)
154 })
155 .await
156 .map_err(map_manager_err)
157 }
158
159 pub async fn logout_all_agents(
161 &self,
162 id: &str,
163 ) -> Result<models::DefaultV2MessageResponse, ManagerError> {
164 with_retry(&self.retry, false, || {
165 outbound_api::logout_all_campaign_agents(self.cfg.as_ref(), id)
166 })
167 .await
168 .map_err(map_manager_err)
169 }
170
171 pub async fn statistics(
173 &self,
174 id: &str,
175 from: Option<i32>,
176 to: Option<i32>,
177 ) -> Result<models::CampaignStatisticsResponse, ManagerError> {
178 with_retry(&self.retry, true, || {
179 outbound_api::get_campaign_statistics(self.cfg.as_ref(), id, from, to)
180 })
181 .await
182 .map_err(map_manager_err)
183 }
184
185 pub async fn status(
187 &self,
188 id: &str,
189 ) -> Result<models::CampaignRealtimeStatusResponse, ManagerError> {
190 with_retry(&self.retry, true, || {
191 outbound_api::get_campaign_status(self.cfg.as_ref(), id)
192 })
193 .await
194 .map_err(map_manager_err)
195 }
196}