Skip to main content

zoom_api/
im_chat.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct ImChat {
5    pub client: Client,
6}
7
8impl ImChat {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        ImChat { client }
12    }
13
14    /**
15     * Get IM chat sessions.
16     *
17     * This function performs a `GET` to the `/im/chat/sessions` endpoint.
18     *
19     * Retrieve IM Chat sessions for a specified period of time. This API only supports Oauth2.<br>
20     *
21     * **Scopes:** `imchat:read, imchat:read:admin`<br>
22     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Heavy`
23     *  <br><br>
24     *   <p style="background-color:#e1f5fe; color:#000000; padding:8px"><b>Deprecated:</b> By end of 2021, Zoom is deprecating this API in favor of a consolidated set of APIs. The API will still be available for you to use, though Zoom will no longer provide support for it. For further information, see <a href="https://marketplace.zoom.us/docs/guides/stay-up-to-date/announcements#im-api-notice">Announcements: IM APIs Deprecation</a>.</p>
25     *  
26     *
27     *
28     * **Parameters:**
29     *
30     * * `from: chrono::NaiveDate` -- Start date in 'yyyy-mm-dd' format. The date range defined by the "from" and "to" parameters should only be one month as the report includes only one month worth of data at once.
31     * * `to: chrono::NaiveDate` -- Start Date.
32     * * `page_size: i64` -- The number of records returned within a single API call.
33     * * `next_page_token: &str` -- The next page token is used to paginate through large result sets. A next page token will be returned whenever the set of available results exceeds the current page size. The expiration period for this token is 15 minutes.
34     */
35    pub async fn session(
36        &self,
37        from: chrono::NaiveDate,
38        to: chrono::NaiveDate,
39        page_size: i64,
40        next_page_token: &str,
41    ) -> ClientResult<crate::Response<crate::types::ImChatSessionsResponseAllOf>> {
42        let mut query_args: Vec<(String, String)> = Default::default();
43        if !from.to_string().is_empty() {
44            query_args.push(("from".to_string(), from.to_string()));
45        }
46        if !next_page_token.is_empty() {
47            query_args.push(("next_page_token".to_string(), next_page_token.to_string()));
48        }
49        if page_size > 0 {
50            query_args.push(("page_size".to_string(), page_size.to_string()));
51        }
52        if !to.to_string().is_empty() {
53            query_args.push(("to".to_string(), to.to_string()));
54        }
55        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
56        let url = self
57            .client
58            .url(&format!("/im/chat/sessions?{}", query_), None);
59        self.client
60            .get(
61                &url,
62                crate::Message {
63                    body: None,
64                    content_type: None,
65                },
66            )
67            .await
68    }
69    /**
70     * Get IM chat messages.
71     *
72     * This function performs a `GET` to the `/im/chat/sessions/{sessionId}` endpoint.
73     *
74     * Retrieve IM chat messages for a specified period of time. This API only supports oauth2.<br>
75     *
76     * **Scopes:** `imchat:read`<br>
77     *
78     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`<br>
79     *  
80     *  <br>
81     *  
82     *  <p style="background-color:#e1f5fe; color:#000000; padding:8px"><b>Deprecated:</b> By end of 2021, Zoom is deprecating this API in favor of a consolidated set of APIs. The API will still be available for you to use, though Zoom will no longer provide support for it. For further information, see <a href="https://marketplace.zoom.us/docs/guides/stay-up-to-date/announcements#im-api-notice">Announcements: IM APIs Deprecation</a>.</p>
83     *
84     *
85     *
86     *
87     * **Parameters:**
88     *
89     * * `session_id: &str` -- User's first name.
90     * * `from: chrono::NaiveDate` -- Start date in 'yyyy-mm-dd' format. The date range defined by the "from" and "to" parameters should only be one month as the report includes only one month worth of data at once.
91     * * `to: chrono::NaiveDate` -- Start Date.
92     * * `page_size: i64` -- The number of records returned within a single API call.
93     * * `next_page_token: &str` -- The next page token is used to paginate through large result sets. A next page token will be returned whenever the set of available results exceeds the current page size. The expiration period for this token is 15 minutes.
94     */
95    pub async fn message(
96        &self,
97        session_id: &str,
98        from: chrono::NaiveDate,
99        to: chrono::NaiveDate,
100        page_size: i64,
101        next_page_token: &str,
102    ) -> ClientResult<crate::Response<crate::types::ImChatMessagesResponseAllOf>> {
103        let mut query_args: Vec<(String, String)> = Default::default();
104        if !from.to_string().is_empty() {
105            query_args.push(("from".to_string(), from.to_string()));
106        }
107        if !next_page_token.is_empty() {
108            query_args.push(("next_page_token".to_string(), next_page_token.to_string()));
109        }
110        if page_size > 0 {
111            query_args.push(("page_size".to_string(), page_size.to_string()));
112        }
113        if !to.to_string().is_empty() {
114            query_args.push(("to".to_string(), to.to_string()));
115        }
116        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
117        let url = self.client.url(
118            &format!(
119                "/im/chat/sessions/{}?{}",
120                crate::progenitor_support::encode_path(session_id),
121                query_
122            ),
123            None,
124        );
125        self.client
126            .get(
127                &url,
128                crate::Message {
129                    body: None,
130                    content_type: None,
131                },
132            )
133            .await
134    }
135    /**
136     * Get user’s IM messages.
137     *
138     * This function performs a `GET` to the `/im/users/{userId}/chat/messages` endpoint.
139     *
140     * Get IM Chat messages for a specified period of time. This API only supports Oauth2.<br>
141     * **Scopes:** `imchat:read`<br>
142     * **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
143     * <br><br>
144     *   <p style="background-color:#e1f5fe; color:#000000; padding:8px"><b>Deprecated:</b> By end of 2021, Zoom is deprecating this API in favor of a consolidated set of APIs. The API will still be available for you to use, though Zoom will no longer provide support for it. For further information, see <a href="https://marketplace.zoom.us/docs/guides/stay-up-to-date/announcements#im-api-notice">Announcements: IM APIs Deprecation</a>.</p>
145     *
146     *
147     * **Parameters:**
148     *
149     * * `user_id: &str` -- The user ID or email address.
150     * * `chat_user: &str` -- Chat user's ID or email address.
151     * * `channel: &str` -- User's first name.
152     * * `date: &str` -- IM message's query date time, format as yyyy-MM-dd.
153     * * `page_size: i64` -- The number of records returned within a single API call.
154     * * `next_page_token: &str` -- The next page token is used to paginate through large result sets. A next page token will be returned whenever the set of available results exceeds the current page size. The expiration period for this token is 15 minutes.
155     */
156    pub async fn list_im_messages(
157        &self,
158        user_id: &str,
159        chat_user: &str,
160        channel: &str,
161        date: &str,
162        page_size: i64,
163        next_page_token: &str,
164    ) -> ClientResult<crate::Response<Vec<crate::types::ListimmessagesResponseMessages>>> {
165        let mut query_args: Vec<(String, String)> = Default::default();
166        if !channel.is_empty() {
167            query_args.push(("channel".to_string(), channel.to_string()));
168        }
169        if !chat_user.is_empty() {
170            query_args.push(("chat_user".to_string(), chat_user.to_string()));
171        }
172        if !date.is_empty() {
173            query_args.push(("date".to_string(), date.to_string()));
174        }
175        if !next_page_token.is_empty() {
176            query_args.push(("next_page_token".to_string(), next_page_token.to_string()));
177        }
178        if page_size > 0 {
179            query_args.push(("page_size".to_string(), page_size.to_string()));
180        }
181        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
182        let url = self.client.url(
183            &format!(
184                "/im/users/{}/chat/messages?{}",
185                crate::progenitor_support::encode_path(user_id),
186                query_
187            ),
188            None,
189        );
190        let resp: crate::Response<crate::types::ListimmessagesResponse> = self
191            .client
192            .get(
193                &url,
194                crate::Message {
195                    body: None,
196                    content_type: None,
197                },
198            )
199            .await?;
200
201        // Return our response data.
202        Ok(crate::Response::new(
203            resp.status,
204            resp.headers,
205            resp.body.messages.to_vec(),
206        ))
207    }
208    /**
209     * Get user’s IM messages.
210     *
211     * This function performs a `GET` to the `/im/users/{userId}/chat/messages` endpoint.
212     *
213     * As opposed to `list_im_messages`, this function returns all the pages of the request at once.
214     *
215     * Get IM Chat messages for a specified period of time. This API only supports Oauth2.<br>
216     * **Scopes:** `imchat:read`<br>
217     * **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
218     * <br><br>
219     *   <p style="background-color:#e1f5fe; color:#000000; padding:8px"><b>Deprecated:</b> By end of 2021, Zoom is deprecating this API in favor of a consolidated set of APIs. The API will still be available for you to use, though Zoom will no longer provide support for it. For further information, see <a href="https://marketplace.zoom.us/docs/guides/stay-up-to-date/announcements#im-api-notice">Announcements: IM APIs Deprecation</a>.</p>
220     *
221     */
222    pub async fn list_all_im_messages(
223        &self,
224        user_id: &str,
225        chat_user: &str,
226        channel: &str,
227        date: &str,
228    ) -> ClientResult<crate::Response<Vec<crate::types::ListimmessagesResponseMessages>>> {
229        let mut query_args: Vec<(String, String)> = Default::default();
230        if !channel.is_empty() {
231            query_args.push(("channel".to_string(), channel.to_string()));
232        }
233        if !chat_user.is_empty() {
234            query_args.push(("chat_user".to_string(), chat_user.to_string()));
235        }
236        if !date.is_empty() {
237            query_args.push(("date".to_string(), date.to_string()));
238        }
239        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
240        let url = self.client.url(
241            &format!(
242                "/im/users/{}/chat/messages?{}",
243                crate::progenitor_support::encode_path(user_id),
244                query_
245            ),
246            None,
247        );
248        let crate::Response::<crate::types::ListimmessagesResponse> {
249            mut status,
250            mut headers,
251            mut body,
252        } = self
253            .client
254            .get(
255                &url,
256                crate::Message {
257                    body: None,
258                    content_type: None,
259                },
260            )
261            .await?;
262
263        let mut messages = body.messages;
264        let mut page = body.next_page_token;
265
266        // Paginate if we should.
267        while !page.is_empty() {
268            // Check if we already have URL params and need to concat the token.
269            if !url.contains('?') {
270                crate::Response::<crate::types::ListimmessagesResponse> {
271                    status,
272                    headers,
273                    body,
274                } = self
275                    .client
276                    .get(
277                        &format!("{}?next_page_token={}", url, page),
278                        crate::Message {
279                            body: None,
280                            content_type: None,
281                        },
282                    )
283                    .await?;
284            } else {
285                crate::Response::<crate::types::ListimmessagesResponse> {
286                    status,
287                    headers,
288                    body,
289                } = self
290                    .client
291                    .get(
292                        &format!("{}&next_page_token={}", url, page),
293                        crate::Message {
294                            body: None,
295                            content_type: None,
296                        },
297                    )
298                    .await?;
299            }
300
301            messages.append(&mut body.messages);
302
303            if !body.next_page_token.is_empty() && body.next_page_token != page {
304                page = body.next_page_token.to_string();
305            } else {
306                page = "".to_string();
307            }
308        }
309
310        // Return our response data.
311        Ok(crate::Response::new(status, headers, messages))
312    }
313    /**
314     * Send IM messages.
315     *
316     * This function performs a `POST` to the `/im/users/me/chat/messages` endpoint.
317     *
318     * Send chat message to a user. <aside>Note: This API only supports OAuth 2.0.</aside><br><br>**Scope:** `imchat:write`
319     *  
320     *  **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
321     *
322     * **Parameters:**
323     *
324     * * `chat_user: &str` -- The email address (registered with Zoom) or the userId of the chat user.
325     */
326    pub async fn send_im_messages(
327        &self,
328        chat_user: &str,
329        body: &crate::types::SendimmessagesRequest,
330    ) -> ClientResult<crate::Response<crate::types::Groups>> {
331        let mut query_args: Vec<(String, String)> = Default::default();
332        if !chat_user.is_empty() {
333            query_args.push(("chat_user".to_string(), chat_user.to_string()));
334        }
335        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
336        let url = self
337            .client
338            .url(&format!("/im/users/me/chat/messages?{}", query_), None);
339        self.client
340            .post(
341                &url,
342                crate::Message {
343                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
344                    content_type: Some("application/json".to_string()),
345                },
346            )
347            .await
348    }
349}