babelforce_manager_sdk/resources/
settings.rs1use crate::error::{map_manager_err, ManagerError};
2use crate::gen::manager::apis::configuration::Configuration;
3use crate::gen::manager::apis::settings_api as api;
4use crate::gen::manager::models;
5use crate::retry::{with_retry, RetryPolicy};
6use crate::token::SharedCfg;
7
8pub struct SettingsResource {
12 pub(crate) cfg: SharedCfg<Configuration>,
13 pub(crate) retry: RetryPolicy,
14}
15
16macro_rules! section {
18 ($get:ident, $set:ident, $gen_get:ident, $gen_set:ident, $resp:ident, $req:ident, $label:literal) => {
19 #[doc = concat!("Read the ", $label, " settings.")]
20 pub async fn $get(&self) -> Result<models::$resp, ManagerError> {
21 let cfg = self.cfg.get().await?;
22 let cfg = cfg.as_ref();
23 with_retry(&self.retry, true, || api::$gen_get(cfg))
24 .await
25 .map_err(map_manager_err)
26 }
27
28 #[doc = concat!("Update the ", $label, " settings.")]
29 pub async fn $set(&self, body: models::$req) -> Result<models::$resp, ManagerError> {
30 let cfg = self.cfg.get().await?;
31 let cfg = cfg.as_ref();
32 with_retry(&self.retry, false, || {
33 api::$gen_set(cfg, Some(body.clone()))
34 })
35 .await
36 .map_err(map_manager_err)
37 }
38 };
39}
40
41impl SettingsResource {
42 section!(
43 app_customer_logging,
44 set_app_customer_logging,
45 get_settings_for_app_customer_logging,
46 update_settings_for_app_customer_logging,
47 SettingsAppCustomerLoggingResponse,
48 SettingsAppCustomerLoggingRequest,
49 "app customer-logging"
50 );
51 section!(
52 app_conversations,
53 set_app_conversations,
54 get_settings_for_app_conversations,
55 update_settings_for_app_conversations,
56 SettingsAppConversationsResponse,
57 SettingsAppConversationsRequest,
58 "app conversations"
59 );
60 section!(
61 app_integrations,
62 set_app_integrations,
63 get_settings_for_app_integrations,
64 update_settings_for_app_integrations,
65 SettingsAppIntegrationsResponse,
66 SettingsAppIntegrationsRequest,
67 "app integrations"
68 );
69 section!(
70 app_agent_status,
71 set_app_agent_status,
72 get_settings_for_app_agent_status,
73 update_settings_for_app_agent_status,
74 SettingsAppAgentStatusResponse,
75 SettingsAppAgentStatusRequest,
76 "app agent-status"
77 );
78 section!(
79 telephony_agent_inbound,
80 set_telephony_agent_inbound,
81 get_settings_for_telephony_agent_inbound,
82 update_settings_for_telephony_agent_inbound,
83 SettingsTelephonyAgentInboundResponse,
84 SettingsTelephonyAgentInboundRequest,
85 "telephony agent-inbound"
86 );
87 section!(
88 telephony_agent_outbound,
89 set_telephony_agent_outbound,
90 get_settings_for_telephony_agent_outbound,
91 update_settings_for_telephony_agent_outbound,
92 SettingsTelephonyAgentOutboundResponse,
93 SettingsTelephonyAgentOutboundRequest,
94 "telephony agent-outbound"
95 );
96 section!(
97 telephony_agent_recording,
98 set_telephony_agent_recording,
99 get_settings_for_telephony_agent_recording,
100 update_settings_for_telephony_agent_recording,
101 SettingsTelephonyAgentRecordingResponse,
102 SettingsTelephonyAgentRecordingRequest,
103 "telephony agent-recording"
104 );
105 section!(
106 telephony_agent_wrapup,
107 set_telephony_agent_wrapup,
108 get_settings_for_telephony_agent_wrapup,
109 update_settings_for_telephony_agent_wrapup,
110 SettingsTelephonyAgentWrapupResponse,
111 SettingsTelephonyAgentWrapupRequest,
112 "telephony agent-wrapup"
113 );
114 section!(
115 telephony_post_call,
116 set_telephony_post_call,
117 get_settings_for_telephony_post_call,
118 update_settings_for_telephony_post_call,
119 SettingsTelephonyPostCallResponse,
120 SettingsTelephonyPostCallRequest,
121 "telephony post-call"
122 );
123 section!(
124 audit_default,
125 set_audit_default,
126 get_settings_for_audit_default,
127 update_settings_for_audit_default,
128 SettingsAuditDefaultResponse,
129 SettingsAuditDefaultRequest,
130 "audit default"
131 );
132 section!(
133 ui_i18n,
134 set_ui_i18n,
135 get_settings_for_ui_i18n,
136 update_settings_for_ui_i18n,
137 SettingsUiI18nResponse,
138 SettingsUiI18nRequest,
139 "UI i18n"
140 );
141 section!(
142 retention_periods,
143 set_retention_periods,
144 get_settings_for_retention_periods,
145 update_settings_for_retention_periods,
146 SettingsRetentionPeriodsResponse,
147 SettingsRetentionPeriodsRequest,
148 "retention periods"
149 );
150
151 pub async fn list_all(&self) -> Result<models::SettingsListResponse, ManagerError> {
153 let cfg = self.cfg.get().await?;
154 let cfg = cfg.as_ref();
155 with_retry(&self.retry, true, || api::list_all_settings(cfg))
156 .await
157 .map_err(map_manager_err)
158 }
159
160 pub async fn list_in_scope(
162 &self,
163 scope: &str,
164 ) -> Result<models::SettingsListResponse, ManagerError> {
165 let cfg = self.cfg.get().await?;
166 let cfg = cfg.as_ref();
167 with_retry(&self.retry, true, || {
168 api::list_settings_in_scope(cfg, scope)
169 })
170 .await
171 .map_err(map_manager_err)
172 }
173
174 pub async fn clear(
176 &self,
177 scope: &str,
178 key: &str,
179 ) -> Result<models::SettingItemResponse, ManagerError> {
180 let cfg = self.cfg.get().await?;
181 let cfg = cfg.as_ref();
182 with_retry(&self.retry, false, || api::clear_setting(cfg, scope, key))
183 .await
184 .map_err(map_manager_err)
185 }
186
187 pub async fn clear_in_scope(
189 &self,
190 scope: &str,
191 ) -> Result<models::SettingsListResponse, ManagerError> {
192 let cfg = self.cfg.get().await?;
193 let cfg = cfg.as_ref();
194 with_retry(&self.retry, false, || {
195 api::clear_settings_in_scope(cfg, scope)
196 })
197 .await
198 .map_err(map_manager_err)
199 }
200
201 pub async fn clear_all(&self) -> Result<models::SettingsListResponse, ManagerError> {
203 let cfg = self.cfg.get().await?;
204 let cfg = cfg.as_ref();
205 with_retry(&self.retry, false, || api::clear_all_settings(cfg))
206 .await
207 .map_err(map_manager_err)
208 }
209}