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