1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct MessageTemplates {
6 pub client: Client,
7}
8
9impl MessageTemplates {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "Get child templates\n\nFetch the child message templates of a message template folder.\n\n**Parameters:**\n\n- `message_template_folder_id: &'astr`: The message template folder ID (required)\n\n```rust,no_run\nasync fn example_message_templates_get_child_templates() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::GetChildTemplatesResponse = client\n .message_templates()\n .get_child_templates(\"some-string\")\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
16 #[tracing::instrument]
17 pub async fn get_child_templates<'a>(
18 &'a self,
19 message_template_folder_id: &'a str,
20 ) -> Result<crate::types::GetChildTemplatesResponse, crate::types::error::Error> {
21 let mut req = self.client.client.request(
22 http::Method::GET,
23 &format!(
24 "{}/{}",
25 self.client.base_url,
26 "message_template_folders/{message_template_folder_id}/message_templates"
27 .replace("{message_template_folder_id}", message_template_folder_id)
28 ),
29 );
30 req = req.bearer_auth(&self.client.token);
31 let resp = req.send().await?;
32 let status = resp.status();
33 if status.is_success() {
34 let text = resp.text().await.unwrap_or_default();
35 serde_json::from_str(&text).map_err(|err| {
36 crate::types::error::Error::from_serde_error(
37 format_serde_error::SerdeError::new(text.to_string(), err),
38 status,
39 )
40 })
41 } else {
42 Err(crate::types::error::Error::UnexpectedResponse(resp))
43 }
44 }
45
46 #[doc = "Create child template\n\nCreate a new message template as a child of the given folder\n\n**Parameters:**\n\n- `message_template_folder_id: &'astr`: The parent message template folder ID (required)\n\n```rust,no_run\nasync fn example_message_templates_create_child_template() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::MessageTemplateResponse = client\n .message_templates()\n .create_child_template(\n \"some-string\",\n &front_api::types::CreateMessageTemplateAsChild {\n name: \"some-string\".to_string(),\n subject: Some(\"some-string\".to_string()),\n body: \"some-string\".to_string(),\n inbox_ids: Some(vec![\"some-string\".to_string()]),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
47 #[tracing::instrument]
48 pub async fn create_child_template<'a>(
49 &'a self,
50 message_template_folder_id: &'a str,
51 body: &crate::types::CreateMessageTemplateAsChild,
52 ) -> Result<crate::types::MessageTemplateResponse, crate::types::error::Error> {
53 let mut req = self.client.client.request(
54 http::Method::POST,
55 &format!(
56 "{}/{}",
57 self.client.base_url,
58 "message_template_folders/{message_template_folder_id}/message_templates"
59 .replace("{message_template_folder_id}", message_template_folder_id)
60 ),
61 );
62 req = req.bearer_auth(&self.client.token);
63 req = req.json(body);
64 let resp = req.send().await?;
65 let status = resp.status();
66 if status.is_success() {
67 let text = resp.text().await.unwrap_or_default();
68 serde_json::from_str(&text).map_err(|err| {
69 crate::types::error::Error::from_serde_error(
70 format_serde_error::SerdeError::new(text.to_string(), err),
71 status,
72 )
73 })
74 } else {
75 Err(crate::types::error::Error::UnexpectedResponse(resp))
76 }
77 }
78
79 #[doc = "List message templates\n\nList the message templates.\n\n```rust,no_run\nasync fn \
80 example_message_templates_list() -> anyhow::Result<()> {\n let client = \
81 front_api::Client::new_from_env();\n let result: \
82 front_api::types::ListMessageTemplatesResponse =\n \
83 client.message_templates().list().await?;\n println!(\"{:?}\", result);\n \
84 Ok(())\n}\n```"]
85 #[tracing::instrument]
86 pub async fn list<'a>(
87 &'a self,
88 ) -> Result<crate::types::ListMessageTemplatesResponse, crate::types::error::Error> {
89 let mut req = self.client.client.request(
90 http::Method::GET,
91 &format!("{}/{}", self.client.base_url, "message_templates"),
92 );
93 req = req.bearer_auth(&self.client.token);
94 let resp = req.send().await?;
95 let status = resp.status();
96 if status.is_success() {
97 let text = resp.text().await.unwrap_or_default();
98 serde_json::from_str(&text).map_err(|err| {
99 crate::types::error::Error::from_serde_error(
100 format_serde_error::SerdeError::new(text.to_string(), err),
101 status,
102 )
103 })
104 } else {
105 Err(crate::types::error::Error::UnexpectedResponse(resp))
106 }
107 }
108
109 #[doc = "Create message template\n\nCreate a new message template.\n\n```rust,no_run\nasync fn example_message_templates_create() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::MessageTemplateResponse = client\n .message_templates()\n .create(&front_api::types::CreateSharedMessageTemplate {\n name: \"some-string\".to_string(),\n subject: Some(\"some-string\".to_string()),\n body: \"some-string\".to_string(),\n folder_id: Some(\"some-string\".to_string()),\n inbox_ids: Some(vec![\"some-string\".to_string()]),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
110 #[tracing::instrument]
111 pub async fn create<'a>(
112 &'a self,
113 body: &crate::types::CreateSharedMessageTemplate,
114 ) -> Result<crate::types::MessageTemplateResponse, crate::types::error::Error> {
115 let mut req = self.client.client.request(
116 http::Method::POST,
117 &format!("{}/{}", self.client.base_url, "message_templates"),
118 );
119 req = req.bearer_auth(&self.client.token);
120 req = req.json(body);
121 let resp = req.send().await?;
122 let status = resp.status();
123 if status.is_success() {
124 let text = resp.text().await.unwrap_or_default();
125 serde_json::from_str(&text).map_err(|err| {
126 crate::types::error::Error::from_serde_error(
127 format_serde_error::SerdeError::new(text.to_string(), err),
128 status,
129 )
130 })
131 } else {
132 Err(crate::types::error::Error::UnexpectedResponse(resp))
133 }
134 }
135
136 #[doc = "List team message templates\n\nList the message templates belonging to the requested \
137 team.\n\n**Parameters:**\n\n- `team_id: &'astr`: The team ID \
138 (required)\n\n```rust,no_run\nasync fn example_message_templates_list_team() -> \
139 anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let \
140 result: front_api::types::ListTeamMessageTemplatesResponse =\n \
141 client.message_templates().list_team(\"some-string\").await?;\n println!(\"{:?}\", \
142 result);\n Ok(())\n}\n```"]
143 #[tracing::instrument]
144 pub async fn list_team<'a>(
145 &'a self,
146 team_id: &'a str,
147 ) -> Result<crate::types::ListTeamMessageTemplatesResponse, crate::types::error::Error> {
148 let mut req = self.client.client.request(
149 http::Method::GET,
150 &format!(
151 "{}/{}",
152 self.client.base_url,
153 "teams/{team_id}/message_templates".replace("{team_id}", team_id)
154 ),
155 );
156 req = req.bearer_auth(&self.client.token);
157 let resp = req.send().await?;
158 let status = resp.status();
159 if status.is_success() {
160 let text = resp.text().await.unwrap_or_default();
161 serde_json::from_str(&text).map_err(|err| {
162 crate::types::error::Error::from_serde_error(
163 format_serde_error::SerdeError::new(text.to_string(), err),
164 status,
165 )
166 })
167 } else {
168 Err(crate::types::error::Error::UnexpectedResponse(resp))
169 }
170 }
171
172 #[doc = "Create team message template\n\nCreate a new message template for the given team\n\n**Parameters:**\n\n- `team_id: &'astr`: The team ID (required)\n\n```rust,no_run\nasync fn example_message_templates_create_team() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::MessageTemplateResponse = client\n .message_templates()\n .create_team(\n \"some-string\",\n &front_api::types::CreateSharedMessageTemplate {\n name: \"some-string\".to_string(),\n subject: Some(\"some-string\".to_string()),\n body: \"some-string\".to_string(),\n folder_id: Some(\"some-string\".to_string()),\n inbox_ids: Some(vec![\"some-string\".to_string()]),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
173 #[tracing::instrument]
174 pub async fn create_team<'a>(
175 &'a self,
176 team_id: &'a str,
177 body: &crate::types::CreateSharedMessageTemplate,
178 ) -> Result<crate::types::MessageTemplateResponse, crate::types::error::Error> {
179 let mut req = self.client.client.request(
180 http::Method::POST,
181 &format!(
182 "{}/{}",
183 self.client.base_url,
184 "teams/{team_id}/message_templates".replace("{team_id}", team_id)
185 ),
186 );
187 req = req.bearer_auth(&self.client.token);
188 req = req.json(body);
189 let resp = req.send().await?;
190 let status = resp.status();
191 if status.is_success() {
192 let text = resp.text().await.unwrap_or_default();
193 serde_json::from_str(&text).map_err(|err| {
194 crate::types::error::Error::from_serde_error(
195 format_serde_error::SerdeError::new(text.to_string(), err),
196 status,
197 )
198 })
199 } else {
200 Err(crate::types::error::Error::UnexpectedResponse(resp))
201 }
202 }
203
204 #[doc = "List teammate message templates\n\nList the message templates belonging to the \
205 requested teammate.\n\n**Parameters:**\n\n- `teammate_id: &'astr`: The teammate ID \
206 (required)\n\n```rust,no_run\nasync fn example_message_templates_list_teammate() -> \
207 anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let \
208 result: front_api::types::ListTeammateMessageTemplatesResponse = client\n \
209 .message_templates()\n .list_teammate(\"some-string\")\n .await?;\n \
210 println!(\"{:?}\", result);\n Ok(())\n}\n```"]
211 #[tracing::instrument]
212 pub async fn list_teammate<'a>(
213 &'a self,
214 teammate_id: &'a str,
215 ) -> Result<crate::types::ListTeammateMessageTemplatesResponse, crate::types::error::Error>
216 {
217 let mut req = self.client.client.request(
218 http::Method::GET,
219 &format!(
220 "{}/{}",
221 self.client.base_url,
222 "teammates/{teammate_id}/message_templates".replace("{teammate_id}", teammate_id)
223 ),
224 );
225 req = req.bearer_auth(&self.client.token);
226 let resp = req.send().await?;
227 let status = resp.status();
228 if status.is_success() {
229 let text = resp.text().await.unwrap_or_default();
230 serde_json::from_str(&text).map_err(|err| {
231 crate::types::error::Error::from_serde_error(
232 format_serde_error::SerdeError::new(text.to_string(), err),
233 status,
234 )
235 })
236 } else {
237 Err(crate::types::error::Error::UnexpectedResponse(resp))
238 }
239 }
240
241 #[doc = "Create teammate message template\n\nCreate a new message template for the given teammate\n\n**Parameters:**\n\n- `teammate_id: &'astr`: The teammate ID (required)\n\n```rust,no_run\nasync fn example_message_templates_create_teammate() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::MessageTemplateResponse = client\n .message_templates()\n .create_teammate(\n \"some-string\",\n &front_api::types::CreatePrivateMessageTemplate {\n name: \"some-string\".to_string(),\n subject: Some(\"some-string\".to_string()),\n body: \"some-string\".to_string(),\n folder_id: Some(\"some-string\".to_string()),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
242 #[tracing::instrument]
243 pub async fn create_teammate<'a>(
244 &'a self,
245 teammate_id: &'a str,
246 body: &crate::types::CreatePrivateMessageTemplate,
247 ) -> Result<crate::types::MessageTemplateResponse, crate::types::error::Error> {
248 let mut req = self.client.client.request(
249 http::Method::POST,
250 &format!(
251 "{}/{}",
252 self.client.base_url,
253 "teammates/{teammate_id}/message_templates".replace("{teammate_id}", teammate_id)
254 ),
255 );
256 req = req.bearer_auth(&self.client.token);
257 req = req.json(body);
258 let resp = req.send().await?;
259 let status = resp.status();
260 if status.is_success() {
261 let text = resp.text().await.unwrap_or_default();
262 serde_json::from_str(&text).map_err(|err| {
263 crate::types::error::Error::from_serde_error(
264 format_serde_error::SerdeError::new(text.to_string(), err),
265 status,
266 )
267 })
268 } else {
269 Err(crate::types::error::Error::UnexpectedResponse(resp))
270 }
271 }
272
273 #[doc = "Get message template\n\nFetch a message template.\n\n**Parameters:**\n\n- \
274 `message_template_id: &'astr`: The message template ID \
275 (required)\n\n```rust,no_run\nasync fn example_message_templates_get() -> \
276 anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let \
277 result: front_api::types::MessageTemplateResponse =\n \
278 client.message_templates().get(\"some-string\").await?;\n println!(\"{:?}\", \
279 result);\n Ok(())\n}\n```"]
280 #[tracing::instrument]
281 pub async fn get<'a>(
282 &'a self,
283 message_template_id: &'a str,
284 ) -> Result<crate::types::MessageTemplateResponse, crate::types::error::Error> {
285 let mut req = self.client.client.request(
286 http::Method::GET,
287 &format!(
288 "{}/{}",
289 self.client.base_url,
290 "message_templates/{message_template_id}"
291 .replace("{message_template_id}", message_template_id)
292 ),
293 );
294 req = req.bearer_auth(&self.client.token);
295 let resp = req.send().await?;
296 let status = resp.status();
297 if status.is_success() {
298 let text = resp.text().await.unwrap_or_default();
299 serde_json::from_str(&text).map_err(|err| {
300 crate::types::error::Error::from_serde_error(
301 format_serde_error::SerdeError::new(text.to_string(), err),
302 status,
303 )
304 })
305 } else {
306 Err(crate::types::error::Error::UnexpectedResponse(resp))
307 }
308 }
309
310 #[doc = "Delete message template\n\nDelete a message template\n\n**Parameters:**\n\n- \
311 `message_template_id: &'astr`: The message template ID \
312 (required)\n\n```rust,no_run\nasync fn example_message_templates_delete() -> \
313 anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n \
314 client.message_templates().delete(\"some-string\").await?;\n Ok(())\n}\n```"]
315 #[tracing::instrument]
316 pub async fn delete<'a>(
317 &'a self,
318 message_template_id: &'a str,
319 ) -> Result<(), crate::types::error::Error> {
320 let mut req = self.client.client.request(
321 http::Method::DELETE,
322 &format!(
323 "{}/{}",
324 self.client.base_url,
325 "message_templates/{message_template_id}"
326 .replace("{message_template_id}", message_template_id)
327 ),
328 );
329 req = req.bearer_auth(&self.client.token);
330 let resp = req.send().await?;
331 let status = resp.status();
332 if status.is_success() {
333 Ok(())
334 } else {
335 Err(crate::types::error::Error::UnexpectedResponse(resp))
336 }
337 }
338
339 #[doc = "Update message template\n\nUpdate message template\n\n**Parameters:**\n\n- \
340 `message_template_id: &'astr`: The message template ID \
341 (required)\n\n```rust,no_run\nasync fn example_message_templates_update() -> \
342 anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let \
343 result: front_api::types::MessageTemplateResponse = client\n \
344 .message_templates()\n .update(\n \"some-string\",\n \
345 &serde_json::Value::String(\"some-string\".to_string()),\n )\n \
346 .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
347 #[tracing::instrument]
348 pub async fn update<'a>(
349 &'a self,
350 message_template_id: &'a str,
351 body: &crate::types::UpdateMessageTemplate,
352 ) -> Result<crate::types::MessageTemplateResponse, crate::types::error::Error> {
353 let mut req = self.client.client.request(
354 http::Method::PATCH,
355 &format!(
356 "{}/{}",
357 self.client.base_url,
358 "message_templates/{message_template_id}"
359 .replace("{message_template_id}", message_template_id)
360 ),
361 );
362 req = req.bearer_auth(&self.client.token);
363 req = req.json(body);
364 let resp = req.send().await?;
365 let status = resp.status();
366 if status.is_success() {
367 let text = resp.text().await.unwrap_or_default();
368 serde_json::from_str(&text).map_err(|err| {
369 crate::types::error::Error::from_serde_error(
370 format_serde_error::SerdeError::new(text.to_string(), err),
371 status,
372 )
373 })
374 } else {
375 Err(crate::types::error::Error::UnexpectedResponse(resp))
376 }
377 }
378}