agentmail/client/
threads.rs1use crate::client::NoBody;
2use crate::{Client, Error, Page, types::*, util::urlish};
3
4impl Client {
5 pub async fn list_threads(&self, inbox_id: &str) -> Result<ThreadList, Error> {
8 self.list_threads_page(inbox_id, Page::default()).await
9 }
10
11 pub async fn list_threads_page(&self, inbox_id: &str, page: Page) -> Result<ThreadList, Error> {
15 self.request(
16 reqwest::Method::GET,
17 &format!("/v0/inboxes/{}/threads", urlish(inbox_id)),
18 &page.query(),
19 None::<&NoBody>,
20 )
21 .await
22 }
23
24 pub async fn list_threads_filtered(
27 &self,
28 inbox_id: &str,
29 filters: ThreadListFilters,
30 ) -> Result<ThreadList, Error> {
31 self.request(
32 reqwest::Method::GET,
33 &format!("/v0/inboxes/{}/threads", urlish(inbox_id)),
34 &filters.query(),
35 None::<&NoBody>,
36 )
37 .await
38 }
39
40 pub async fn search_threads(&self, inbox_id: &str, query: &str) -> Result<ThreadList, Error> {
44 self.search_threads_page(inbox_id, query, ThreadListFilters::default())
45 .await
46 }
47
48 pub async fn search_threads_page(
50 &self,
51 inbox_id: &str,
52 query: &str,
53 filters: ThreadListFilters,
54 ) -> Result<ThreadList, Error> {
55 let mut q = filters.query();
56 q.push(("q", query.to_string()));
57 self.request(
58 reqwest::Method::GET,
59 &format!("/v0/inboxes/{}/threads/search", urlish(inbox_id)),
60 &q,
61 None::<&NoBody>,
62 )
63 .await
64 }
65
66 pub async fn get_thread(&self, inbox_id: &str, thread_id: &str) -> Result<Thread, Error> {
69 self.request(
70 reqwest::Method::GET,
71 &format!(
72 "/v0/inboxes/{}/threads/{}",
73 urlish(inbox_id),
74 urlish(thread_id),
75 ),
76 &[],
77 None::<&NoBody>,
78 )
79 .await
80 }
81
82 pub async fn update_thread(
86 &self,
87 inbox_id: &str,
88 thread_id: &str,
89 update: UpdateThread,
90 ) -> Result<UpdatedThread, Error> {
91 self.request(
92 reqwest::Method::PATCH,
93 &format!(
94 "/v0/inboxes/{}/threads/{}",
95 urlish(inbox_id),
96 urlish(thread_id),
97 ),
98 &[],
99 Some(&update),
100 )
101 .await
102 }
103
104 pub async fn delete_thread(&self, inbox_id: &str, thread_id: &str) -> Result<(), Error> {
106 self.request(
107 reqwest::Method::DELETE,
108 &format!(
109 "/v0/inboxes/{}/threads/{}",
110 urlish(inbox_id),
111 urlish(thread_id),
112 ),
113 &[],
114 None::<&NoBody>,
115 )
116 .await
117 }
118}