front_api/
inboxes.rs

1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Inboxes {
6    pub client: Client,
7}
8
9impl Inboxes {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Self { client }
13    }
14
15    #[doc = "List inbox channels\n\nList the channels in an inbox.\n\n**Parameters:**\n\n- \
16             `inbox_id: &'astr`: The Inbox ID (required)\n\n```rust,no_run\nasync fn \
17             example_inboxes_list_inbox_channels() -> anyhow::Result<()> {\n    let client = \
18             front_api::Client::new_from_env();\n    let result: \
19             front_api::types::ListInboxChannelsResponse =\n        \
20             client.inboxes().list_inbox_channels(\"some-string\").await?;\n    println!(\"{:?}\", \
21             result);\n    Ok(())\n}\n```"]
22    #[tracing::instrument]
23    pub async fn list_inbox_channels<'a>(
24        &'a self,
25        inbox_id: &'a str,
26    ) -> Result<crate::types::ListInboxChannelsResponse, crate::types::error::Error> {
27        let mut req = self.client.client.request(
28            http::Method::GET,
29            &format!(
30                "{}/{}",
31                self.client.base_url,
32                "inboxes/{inbox_id}/channels".replace("{inbox_id}", inbox_id)
33            ),
34        );
35        req = req.bearer_auth(&self.client.token);
36        let resp = req.send().await?;
37        let status = resp.status();
38        if status.is_success() {
39            let text = resp.text().await.unwrap_or_default();
40            serde_json::from_str(&text).map_err(|err| {
41                crate::types::error::Error::from_serde_error(
42                    format_serde_error::SerdeError::new(text.to_string(), err),
43                    status,
44                )
45            })
46        } else {
47            Err(crate::types::error::Error::UnexpectedResponse(resp))
48        }
49    }
50
51    #[doc = "List inboxes\n\nList the inboxes of the company.\n\n```rust,no_run\nasync fn \
52             example_inboxes_list() -> anyhow::Result<()> {\n    let client = \
53             front_api::Client::new_from_env();\n    let result: \
54             front_api::types::ListInboxesResponse = client.inboxes().list().await?;\n    \
55             println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
56    #[tracing::instrument]
57    pub async fn list<'a>(
58        &'a self,
59    ) -> Result<crate::types::ListInboxesResponse, crate::types::error::Error> {
60        let mut req = self.client.client.request(
61            http::Method::GET,
62            &format!("{}/{}", self.client.base_url, "inboxes"),
63        );
64        req = req.bearer_auth(&self.client.token);
65        let resp = req.send().await?;
66        let status = resp.status();
67        if status.is_success() {
68            let text = resp.text().await.unwrap_or_default();
69            serde_json::from_str(&text).map_err(|err| {
70                crate::types::error::Error::from_serde_error(
71                    format_serde_error::SerdeError::new(text.to_string(), err),
72                    status,
73                )
74            })
75        } else {
76            Err(crate::types::error::Error::UnexpectedResponse(resp))
77        }
78    }
79
80    #[doc = "Create inbox\n\nCreate an inbox in the default team.\n\n```rust,no_run\nasync fn \
81             example_inboxes_create_inbox() -> anyhow::Result<()> {\n    let client = \
82             front_api::Client::new_from_env();\n    client\n        .inboxes()\n        \
83             .create_inbox(&front_api::types::CreateInbox {\n            name: \
84             \"some-string\".to_string(),\n            teammate_ids: \
85             Some(vec![\"some-string\".to_string()]),\n        })\n        .await?;\n    \
86             Ok(())\n}\n```"]
87    #[tracing::instrument]
88    pub async fn create_inbox<'a>(
89        &'a self,
90        body: &crate::types::CreateInbox,
91    ) -> Result<(), crate::types::error::Error> {
92        let mut req = self.client.client.request(
93            http::Method::POST,
94            &format!("{}/{}", self.client.base_url, "inboxes"),
95        );
96        req = req.bearer_auth(&self.client.token);
97        req = req.json(body);
98        let resp = req.send().await?;
99        let status = resp.status();
100        if status.is_success() {
101            Ok(())
102        } else {
103            Err(crate::types::error::Error::UnexpectedResponse(resp))
104        }
105    }
106
107    #[doc = "List team inboxes\n\nList the inboxes belonging to a team.\n\n**Parameters:**\n\n- \
108             `team_id: &'astr`: The team ID (required)\n\n```rust,no_run\nasync fn \
109             example_inboxes_list_team() -> anyhow::Result<()> {\n    let client = \
110             front_api::Client::new_from_env();\n    let result: \
111             front_api::types::ListTeamInboxesResponse =\n        \
112             client.inboxes().list_team(\"some-string\").await?;\n    println!(\"{:?}\", \
113             result);\n    Ok(())\n}\n```"]
114    #[tracing::instrument]
115    pub async fn list_team<'a>(
116        &'a self,
117        team_id: &'a str,
118    ) -> Result<crate::types::ListTeamInboxesResponse, crate::types::error::Error> {
119        let mut req = self.client.client.request(
120            http::Method::GET,
121            &format!(
122                "{}/{}",
123                self.client.base_url,
124                "teams/{team_id}/inboxes".replace("{team_id}", team_id)
125            ),
126        );
127        req = req.bearer_auth(&self.client.token);
128        let resp = req.send().await?;
129        let status = resp.status();
130        if status.is_success() {
131            let text = resp.text().await.unwrap_or_default();
132            serde_json::from_str(&text).map_err(|err| {
133                crate::types::error::Error::from_serde_error(
134                    format_serde_error::SerdeError::new(text.to_string(), err),
135                    status,
136                )
137            })
138        } else {
139            Err(crate::types::error::Error::UnexpectedResponse(resp))
140        }
141    }
142
143    #[doc = "Create team inbox\n\nCreate an inbox for a team.\n\n**Parameters:**\n\n- `team_id: \
144             &'astr`: The tag ID (required)\n\n```rust,no_run\nasync fn \
145             example_inboxes_create_team_inbox() -> anyhow::Result<()> {\n    let client = \
146             front_api::Client::new_from_env();\n    client\n        .inboxes()\n        \
147             .create_team_inbox(\n            \"some-string\",\n            \
148             &front_api::types::CreateInbox {\n                name: \
149             \"some-string\".to_string(),\n                teammate_ids: \
150             Some(vec![\"some-string\".to_string()]),\n            },\n        )\n        \
151             .await?;\n    Ok(())\n}\n```"]
152    #[tracing::instrument]
153    pub async fn create_team_inbox<'a>(
154        &'a self,
155        team_id: &'a str,
156        body: &crate::types::CreateInbox,
157    ) -> Result<(), crate::types::error::Error> {
158        let mut req = self.client.client.request(
159            http::Method::POST,
160            &format!(
161                "{}/{}",
162                self.client.base_url,
163                "teams/{team_id}/inboxes".replace("{team_id}", team_id)
164            ),
165        );
166        req = req.bearer_auth(&self.client.token);
167        req = req.json(body);
168        let resp = req.send().await?;
169        let status = resp.status();
170        if status.is_success() {
171            Ok(())
172        } else {
173            Err(crate::types::error::Error::UnexpectedResponse(resp))
174        }
175    }
176
177    #[doc = "Get inbox\n\nFetch an inbox.\n\n**Parameters:**\n\n- `inbox_id: &'astr`: The Inbox ID \
178             (required)\n\n```rust,no_run\nasync fn example_inboxes_get_inbox() -> \
179             anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let \
180             result: front_api::types::InboxResponse = \
181             client.inboxes().get_inbox(\"some-string\").await?;\n    println!(\"{:?}\", \
182             result);\n    Ok(())\n}\n```"]
183    #[tracing::instrument]
184    pub async fn get_inbox<'a>(
185        &'a self,
186        inbox_id: &'a str,
187    ) -> Result<crate::types::InboxResponse, crate::types::error::Error> {
188        let mut req = self.client.client.request(
189            http::Method::GET,
190            &format!(
191                "{}/{}",
192                self.client.base_url,
193                "inboxes/{inbox_id}".replace("{inbox_id}", inbox_id)
194            ),
195        );
196        req = req.bearer_auth(&self.client.token);
197        let resp = req.send().await?;
198        let status = resp.status();
199        if status.is_success() {
200            let text = resp.text().await.unwrap_or_default();
201            serde_json::from_str(&text).map_err(|err| {
202                crate::types::error::Error::from_serde_error(
203                    format_serde_error::SerdeError::new(text.to_string(), err),
204                    status,
205                )
206            })
207        } else {
208            Err(crate::types::error::Error::UnexpectedResponse(resp))
209        }
210    }
211
212    #[doc = "List inbox conversations\n\nList the conversations in an inbox. For more advanced filtering, see the [search endpoint](https://dev.frontapp.com/reference/conversations#search-conversations).\n> ⚠\u{fe0f} Deprecated field included\n>\n> This endpoint returns a deprecated `last_message` field in the top-level conversation bodies listed. Please use the\n> `_links.related.last_message` field instead.\n\n\n**Parameters:**\n\n- `inbox_id: &'astr`: The Inbox ID (required)\n- `limit: Option<i64>`: Max number of results per page\n- `page_token: Option<String>`: Token to use to request the next page\n- `q: Option<String>`: Search query object with a property `statuses`, whose value should be a list of conversation statuses (`assigned`, `unassigned`, `archived`, or `deleted`).\n\n```rust,no_run\nasync fn example_inboxes_list_inbox_conversations() -> anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let result: front_api::types::ListInboxConversationsResponse = client\n        .inboxes()\n        .list_inbox_conversations(\n            \"some-string\",\n            Some(4 as i64),\n            Some(\"some-string\".to_string()),\n            Some(\"some-string\".to_string()),\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
213    #[tracing::instrument]
214    pub async fn list_inbox_conversations<'a>(
215        &'a self,
216        inbox_id: &'a str,
217        limit: Option<i64>,
218        page_token: Option<String>,
219        q: Option<String>,
220    ) -> Result<crate::types::ListInboxConversationsResponse, crate::types::error::Error> {
221        let mut req = self.client.client.request(
222            http::Method::GET,
223            &format!(
224                "{}/{}",
225                self.client.base_url,
226                "inboxes/{inbox_id}/conversations".replace("{inbox_id}", inbox_id)
227            ),
228        );
229        req = req.bearer_auth(&self.client.token);
230        let mut query_params = Vec::new();
231        if let Some(p) = limit {
232            query_params.push(("limit", format!("{}", p)));
233        }
234
235        if let Some(p) = page_token {
236            query_params.push(("page_token", p));
237        }
238
239        if let Some(p) = q {
240            query_params.push(("q", p));
241        }
242
243        req = req.query(&query_params);
244        let resp = req.send().await?;
245        let status = resp.status();
246        if status.is_success() {
247            let text = resp.text().await.unwrap_or_default();
248            serde_json::from_str(&text).map_err(|err| {
249                crate::types::error::Error::from_serde_error(
250                    format_serde_error::SerdeError::new(text.to_string(), err),
251                    status,
252                )
253            })
254        } else {
255            Err(crate::types::error::Error::UnexpectedResponse(resp))
256        }
257    }
258
259    #[doc = "List inbox access\n\nList the teammates with access to an \
260             inbox.\n\n**Parameters:**\n\n- `inbox_id: &'astr`: The Inbox ID \
261             (required)\n\n```rust,no_run\nasync fn example_inboxes_list_inbox_teammates() -> \
262             anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let \
263             result: front_api::types::ListInboxTeammatesResponse =\n        \
264             client.inboxes().list_inbox_teammates(\"some-string\").await?;\n    \
265             println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
266    #[tracing::instrument]
267    pub async fn list_inbox_teammates<'a>(
268        &'a self,
269        inbox_id: &'a str,
270    ) -> Result<crate::types::ListInboxTeammatesResponse, crate::types::error::Error> {
271        let mut req = self.client.client.request(
272            http::Method::GET,
273            &format!(
274                "{}/{}",
275                self.client.base_url,
276                "inboxes/{inbox_id}/teammates".replace("{inbox_id}", inbox_id)
277            ),
278        );
279        req = req.bearer_auth(&self.client.token);
280        let resp = req.send().await?;
281        let status = resp.status();
282        if status.is_success() {
283            let text = resp.text().await.unwrap_or_default();
284            serde_json::from_str(&text).map_err(|err| {
285                crate::types::error::Error::from_serde_error(
286                    format_serde_error::SerdeError::new(text.to_string(), err),
287                    status,
288                )
289            })
290        } else {
291            Err(crate::types::error::Error::UnexpectedResponse(resp))
292        }
293    }
294
295    #[doc = "Add inbox access\n\nGive access to one or more teammates to an \
296             inbox.\n\n**Parameters:**\n\n- `inbox_id: &'astr`: The Inbox ID \
297             (required)\n\n```rust,no_run\nasync fn example_inboxes_add_inbox_teammates() -> \
298             anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    \
299             client\n        .inboxes()\n        .add_inbox_teammates(\n            \
300             \"some-string\",\n            &front_api::types::TeammateIds {\n                \
301             teammate_ids: vec![\"some-string\".to_string()],\n            },\n        )\n        \
302             .await?;\n    Ok(())\n}\n```"]
303    #[tracing::instrument]
304    pub async fn add_inbox_teammates<'a>(
305        &'a self,
306        inbox_id: &'a str,
307        body: &crate::types::TeammateIds,
308    ) -> Result<(), crate::types::error::Error> {
309        let mut req = self.client.client.request(
310            http::Method::POST,
311            &format!(
312                "{}/{}",
313                self.client.base_url,
314                "inboxes/{inbox_id}/teammates".replace("{inbox_id}", inbox_id)
315            ),
316        );
317        req = req.bearer_auth(&self.client.token);
318        req = req.json(body);
319        let resp = req.send().await?;
320        let status = resp.status();
321        if status.is_success() {
322            Ok(())
323        } else {
324            Err(crate::types::error::Error::UnexpectedResponse(resp))
325        }
326    }
327
328    #[doc = "Removes inbox access\n\nRemove access of one or more teammates from an \
329             inbox.\n\n**Parameters:**\n\n- `inbox_id: &'astr`: The Inbox ID \
330             (required)\n\n```rust,no_run\nasync fn example_inboxes_remove_inbox_teammates() -> \
331             anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    \
332             client\n        .inboxes()\n        .remove_inbox_teammates(\n            \
333             \"some-string\",\n            &front_api::types::TeammateIds {\n                \
334             teammate_ids: vec![\"some-string\".to_string()],\n            },\n        )\n        \
335             .await?;\n    Ok(())\n}\n```"]
336    #[tracing::instrument]
337    pub async fn remove_inbox_teammates<'a>(
338        &'a self,
339        inbox_id: &'a str,
340        body: &crate::types::TeammateIds,
341    ) -> Result<(), crate::types::error::Error> {
342        let mut req = self.client.client.request(
343            http::Method::DELETE,
344            &format!(
345                "{}/{}",
346                self.client.base_url,
347                "inboxes/{inbox_id}/teammates".replace("{inbox_id}", inbox_id)
348            ),
349        );
350        req = req.bearer_auth(&self.client.token);
351        req = req.json(body);
352        let resp = req.send().await?;
353        let status = resp.status();
354        if status.is_success() {
355            Ok(())
356        } else {
357            Err(crate::types::error::Error::UnexpectedResponse(resp))
358        }
359    }
360}