zoom_api/chat_messages.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct ChatMessages {
5 pub client: Client,
6}
7
8impl ChatMessages {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 ChatMessages { client }
12 }
13
14 /**
15 * List user's chat messages.
16 *
17 * This function performs a `GET` to the `/chat/users/{userId}/messages` endpoint.
18 *
19 * Use this API to list the current user's chat messages between the user and an individual contact or a chat channel. For user-level apps, pass [the `me` value](https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#mekeyword) instead of the `userId` parameter.
20 *
21 * In the query parameter, you must provide one of the following:
22 *
23 * * `to_contact`: The email address of the contact with whom the user conversed by sending or receiving messages.
24 * * `to_channel`: The channel ID of the channel to or from which the user has sent and/or received messages.
25 *
26 * <p style="background-color:#e1f5fe; color:#01579b; padding:8px"> <b>Note:</b> For an <b>account-level</b> <a href="https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app">OAuth app</a>, this API can only be used on behalf of a user who is assigned with a <a href="https://support.zoom.us/hc/en-us/articles/115001078646-Using-role-management#:~:text=Each%20user%20in%20a%20Zoom,owner%2C%20administrator%2C%20or%20member.&text=Role%2Dbased%20access%20control%20enables,needs%20to%20view%20or%20edit.">role</a> that has the <b>View</b> or <b>Edit</b> permission for <b>Chat Messages</b>.</p>
27 *
28 * **Scopes:** `chat_message:read`, `chat_message:read:admin`<br>**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
29 *
30 * **Parameters:**
31 *
32 * * `to_contact: &str` -- The email address of a chat contact with whom the current user chatted. Messages that were sent and/or received between the user and the contact is displayed.
33 *
34 * Note: You must provide either `contact` or `channel` as a query parameter to retrieve messages either from an individual or a chat channel. .
35 * * `to_channel: &str` -- The channel Id of a channel inside which the current user had chat conversations. Messages that were sent and/or received between the user and the channel is displayed.
36 *
37 * Note: You must provide either `contact` or `channel` as a query parameter to retrieve messages either from an individual or a chat channel. .
38 * * `date: chrono::NaiveDate` -- The query date for which you would like to get the chat messages. This value defaults to the current date.
39 * * `page_size: i64` -- The number of records returned with a single API call. .
40 * * `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.
41 * * `include_deleted_and_edited_message: &str` -- **Optional** <br>
42 * Set the value of this field to `true` to include edited and deleted messages in the response.
43 */
44 pub async fn get_page(
45 &self,
46 user_id: &str,
47 to_contact: &str,
48 to_channel: &str,
49 date: chrono::NaiveDate,
50 page_size: i64,
51 next_page_token: &str,
52 include_deleted_and_edited_message: &str,
53 ) -> ClientResult<crate::Response<Vec<crate::types::Messages>>> {
54 let mut query_args: Vec<(String, String)> = Default::default();
55 if !date.to_string().is_empty() {
56 query_args.push(("date".to_string(), date.to_string()));
57 }
58 if !include_deleted_and_edited_message.is_empty() {
59 query_args.push((
60 "include_deleted_and_edited_message".to_string(),
61 include_deleted_and_edited_message.to_string(),
62 ));
63 }
64 if !next_page_token.is_empty() {
65 query_args.push(("next_page_token".to_string(), next_page_token.to_string()));
66 }
67 if page_size > 0 {
68 query_args.push(("page_size".to_string(), page_size.to_string()));
69 }
70 if !to_channel.is_empty() {
71 query_args.push(("to_channel".to_string(), to_channel.to_string()));
72 }
73 if !to_contact.is_empty() {
74 query_args.push(("to_contact".to_string(), to_contact.to_string()));
75 }
76 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
77 let url = self.client.url(
78 &format!(
79 "/chat/users/{}/messages?{}",
80 crate::progenitor_support::encode_path(user_id),
81 query_
82 ),
83 None,
84 );
85 let resp: crate::Response<crate::types::GetChatMessagesResponse> = self
86 .client
87 .get(
88 &url,
89 crate::Message {
90 body: None,
91 content_type: None,
92 },
93 )
94 .await?;
95
96 // Return our response data.
97 Ok(crate::Response::new(
98 resp.status,
99 resp.headers,
100 resp.body.messages.to_vec(),
101 ))
102 }
103 /**
104 * List user's chat messages.
105 *
106 * This function performs a `GET` to the `/chat/users/{userId}/messages` endpoint.
107 *
108 * As opposed to `get`, this function returns all the pages of the request at once.
109 *
110 * Use this API to list the current user's chat messages between the user and an individual contact or a chat channel. For user-level apps, pass [the `me` value](https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#mekeyword) instead of the `userId` parameter.
111 *
112 * In the query parameter, you must provide one of the following:
113 *
114 * * `to_contact`: The email address of the contact with whom the user conversed by sending or receiving messages.
115 * * `to_channel`: The channel ID of the channel to or from which the user has sent and/or received messages.
116 *
117 * <p style="background-color:#e1f5fe; color:#01579b; padding:8px"> <b>Note:</b> For an <b>account-level</b> <a href="https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app">OAuth app</a>, this API can only be used on behalf of a user who is assigned with a <a href="https://support.zoom.us/hc/en-us/articles/115001078646-Using-role-management#:~:text=Each%20user%20in%20a%20Zoom,owner%2C%20administrator%2C%20or%20member.&text=Role%2Dbased%20access%20control%20enables,needs%20to%20view%20or%20edit.">role</a> that has the <b>View</b> or <b>Edit</b> permission for <b>Chat Messages</b>.</p>
118 *
119 * **Scopes:** `chat_message:read`, `chat_message:read:admin`<br>**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
120 */
121 pub async fn get_all(
122 &self,
123 user_id: &str,
124 to_contact: &str,
125 to_channel: &str,
126 date: chrono::NaiveDate,
127 include_deleted_and_edited_message: &str,
128 ) -> ClientResult<crate::Response<Vec<crate::types::Messages>>> {
129 let mut query_args: Vec<(String, String)> = Default::default();
130 if !date.to_string().is_empty() {
131 query_args.push(("date".to_string(), date.to_string()));
132 }
133 if !include_deleted_and_edited_message.is_empty() {
134 query_args.push((
135 "include_deleted_and_edited_message".to_string(),
136 include_deleted_and_edited_message.to_string(),
137 ));
138 }
139 if !to_channel.is_empty() {
140 query_args.push(("to_channel".to_string(), to_channel.to_string()));
141 }
142 if !to_contact.is_empty() {
143 query_args.push(("to_contact".to_string(), to_contact.to_string()));
144 }
145 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
146 let url = self.client.url(
147 &format!(
148 "/chat/users/{}/messages?{}",
149 crate::progenitor_support::encode_path(user_id),
150 query_
151 ),
152 None,
153 );
154 let crate::Response::<crate::types::GetChatMessagesResponse> {
155 mut status,
156 mut headers,
157 mut body,
158 } = self
159 .client
160 .get(
161 &url,
162 crate::Message {
163 body: None,
164 content_type: None,
165 },
166 )
167 .await?;
168
169 let mut messages = body.messages;
170 let mut page = body.next_page_token;
171
172 // Paginate if we should.
173 while !page.is_empty() {
174 // Check if we already have URL params and need to concat the token.
175 if !url.contains('?') {
176 crate::Response::<crate::types::GetChatMessagesResponse> {
177 status,
178 headers,
179 body,
180 } = self
181 .client
182 .get(
183 &format!("{}?next_page_token={}", url, page),
184 crate::Message {
185 body: None,
186 content_type: None,
187 },
188 )
189 .await?;
190 } else {
191 crate::Response::<crate::types::GetChatMessagesResponse> {
192 status,
193 headers,
194 body,
195 } = self
196 .client
197 .get(
198 &format!("{}&next_page_token={}", url, page),
199 crate::Message {
200 body: None,
201 content_type: None,
202 },
203 )
204 .await?;
205 }
206
207 messages.append(&mut body.messages);
208
209 if !body.next_page_token.is_empty() && body.next_page_token != page {
210 page = body.next_page_token.to_string();
211 } else {
212 page = "".to_string();
213 }
214 }
215
216 // Return our response data.
217 Ok(crate::Response::new(status, headers, messages))
218 }
219 /**
220 * Send a chat message.
221 *
222 * This function performs a `POST` to the `/chat/users/{userId}/messages` endpoint.
223 *
224 * Send chat messages on Zoom to either an individual user who is in your contact list or to a [channel](https://support.zoom.us/hc/en-us/articles/200912909-Getting-Started-With-Channels-Group-Messaging-) of which you are a member. For user-level apps, pass [the `me` value](https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#mekeyword) instead of the `userId` parameter.
225 *
226 * To send a message to a contact, provide the contact's email address in the `to_contact` field. To send a message to a channel, provide the channel's ID in `to_channel` parameter
227 *
228 * **Scopes:** `chat_message:write`, `chat_message:write:admin`<br>**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
229 *
230 * <p style="background-color:#e1f5fe; color:#01579b; padding:8px"> <b>Note:</b> For an <b>account-level</b> <a href="https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app">OAuth app</a>, this API can only be used on behalf of a user who is assigned with a <a href="https://support.zoom.us/hc/en-us/articles/115001078646-Using-role-management#:~:text=Each%20user%20in%20a%20Zoom,owner%2C%20administrator%2C%20or%20member.&text=Role%2Dbased%20access%20control%20enables,needs%20to%20view%20or%20edit."> role</a> that has the <b>Edit</b> permission for <b>Chat Messages</b>.</p>
231 */
232 pub async fn senda(
233 &self,
234 user_id: &str,
235 body: &crate::types::SendaChatMessageRequest,
236 ) -> ClientResult<crate::Response<crate::types::Groups>> {
237 let url = self.client.url(
238 &format!(
239 "/chat/users/{}/messages",
240 crate::progenitor_support::encode_path(user_id),
241 ),
242 None,
243 );
244 self.client
245 .post(
246 &url,
247 crate::Message {
248 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
249 content_type: Some("application/json".to_string()),
250 },
251 )
252 .await
253 }
254 /**
255 * Mark message read or unread.
256 *
257 * This function performs a `PATCH` to the `/chat/users/{userId}/messages/{messageId}/status` endpoint.
258 *
259 * Mark a message as read or unread. For user-level apps, pass [the `me` value](https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#mekeyword) instead of the `userId` parameter.
260 *
261 * <p style="background-color:#e1f5fe; color:#01579b; padding:8px"> <b>Note:</b> For an <b>account-level</b> <a href="https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app">OAuth app</a>, this API can only be used on behalf of a user who is assigned with a <a href="https://support.zoom.us/hc/en-us/articles/115001078646-Using-role-management#:~:text=Each%20user%20in%20a%20Zoom,owner%2C%20administrator%2C%20or%20member.&text=Role%2Dbased%20access%20control%20enables,needs%20to%20view%20or%20edit.">role</a> that has the <b>Edit</b> permission for <b>Chat Messages</b>.</p>
262 *
263 * **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
264 *
265 * **Parameters:**
266 *
267 * * `user_id: &str` -- Unique identifier of the user.
268 * * `message_id: &str` -- Unique identifier of the message.
269 */
270 pub async fn mark_message(
271 &self,
272 user_id: &str,
273 message_id: &str,
274 body: &crate::types::MarkMessageRequest,
275 ) -> ClientResult<crate::Response<()>> {
276 let url = self.client.url(
277 &format!(
278 "/chat/users/{}/messages/{}/status",
279 crate::progenitor_support::encode_path(user_id),
280 crate::progenitor_support::encode_path(message_id),
281 ),
282 None,
283 );
284 self.client
285 .patch(
286 &url,
287 crate::Message {
288 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
289 content_type: Some("application/json".to_string()),
290 },
291 )
292 .await
293 }
294 /**
295 * React to a chat message.
296 *
297 * This function performs a `PATCH` to the `/chat/users/{userId}/messages/{messageId}/emoji_reactions` endpoint.
298 *
299 * Use this API to react (add or remove) to a chat message with an emoji.
300 *
301 * For an **account-level** [OAuth app](https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app), this API can only be used on behalf of a user who is assigned with a [role](https://support.zoom.us/hc/en-us/articles/115001078646-Using-role-management#:~:text=Each%20user%20in%20a%20Zoom,owner%2C%20administrator%2C%20or%20member.&text=Role%2Dbased%20access%20control%20enables,needs%20to%20view%20or%20edit.) that has the **Edit** permission for **Chat Messages**.
302 *
303 * **Scopes:** `chat_message:write`, `chat_message:write:admin`<br>**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
304 *
305 * **Parameters:**
306 *
307 * * `user_id: &str` -- The user's unique ID.
308 * * `message_id: &str` -- The message's unique ID.
309 */
310 pub async fn react_message(
311 &self,
312 user_id: &str,
313 message_id: &str,
314 body: &crate::types::ReactMessageRequest,
315 ) -> ClientResult<crate::Response<()>> {
316 let url = self.client.url(
317 &format!(
318 "/chat/users/{}/messages/{}/emoji_reactions",
319 crate::progenitor_support::encode_path(user_id),
320 crate::progenitor_support::encode_path(message_id),
321 ),
322 None,
323 );
324 self.client
325 .patch(
326 &url,
327 crate::Message {
328 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
329 content_type: Some("application/json".to_string()),
330 },
331 )
332 .await
333 }
334 /**
335 * Get a message.
336 *
337 * This function performs a `GET` to the `/chat/users/{userId}/messages/{messageId}` endpoint.
338 *
339 * Get a chat message previously sent to a contact or a channel. For user-level apps, pass [the `me` value](https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#mekeyword) instead of the `userId` parameter.
340 *
341 * You must provide one of the following query parameters:<br>
342 * * `to_contact` — The email address of the Zoom contact to whom you sent the message.
343 * * `to_channel` — The ID of the Zoom channel where you sent the message.
344 *
345 * **Scopes:** `chat_message:read`, `chat_message:read:admin`<br>**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
346 *
347 * <p style="background-color:#e1f5fe; color:#01579b; padding:8px"> <b>Note:</b> For an <b>account-level</b> <a href="https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app">OAuth app</a>, you can only use this API for a user assigned <a href="https://support.zoom.us/hc/en-us/articles/115001078646-Using-role-management#:~:text=Each%20user%20in%20a%20Zoom,owner%2C%20administrator%2C%20or%20member.&text=Role%2Dbased%20access%20control%20enables,needs%20to%20view%20or%20edit.">the <b>Edit</b> permission for the <b>Chat message</b> role setting</a>.</p>
348 *
349 * **Parameters:**
350 *
351 * * `message_id: &str` -- User's first name.
352 * * `to_contact: &str` -- The `userId` or email address of a Zoom Chat contact to whom you sent the message.\n\n**Note:** You must use this query parameter to delete a message sent to a Zoom Chat contact. .
353 * * `to_channel: &str` -- The `channelId` of the Zoom Chat channel where sent the message.\n\n**Note:** You must use this query parameter to delete a message sent to Zoom Chat channel.
354 */
355 pub async fn get(
356 &self,
357 user_id: &str,
358 message_id: &str,
359 to_contact: &str,
360 to_channel: &str,
361 ) -> ClientResult<crate::Response<crate::types::GetChatMessageResponse>> {
362 let mut query_args: Vec<(String, String)> = Default::default();
363 if !to_channel.is_empty() {
364 query_args.push(("to_channel".to_string(), to_channel.to_string()));
365 }
366 if !to_contact.is_empty() {
367 query_args.push(("to_contact".to_string(), to_contact.to_string()));
368 }
369 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
370 let url = self.client.url(
371 &format!(
372 "/chat/users/{}/messages/{}?{}",
373 crate::progenitor_support::encode_path(user_id),
374 crate::progenitor_support::encode_path(message_id),
375 query_
376 ),
377 None,
378 );
379 self.client
380 .get(
381 &url,
382 crate::Message {
383 body: None,
384 content_type: None,
385 },
386 )
387 .await
388 }
389 /**
390 * Update a message.
391 *
392 * This function performs a `PUT` to the `/chat/users/{userId}/messages/{messageId}` endpoint.
393 *
394 * Use this API to edit a chat message that you previously sent to either a contact or a channel in Zoom by providing the ID of the message as the value of the `messageId` parameter. You can get the ID from the **List User's Chat Messages** API. Additionally, as a query parameter, you must provide either the contact's **email address** of the contact or the **Channel ID** of the channel where the message was sent.
395 *
396 * For user-level apps, pass [the `me` value](https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#mekeyword) instead of the `userId` parameter.
397 *
398 * <p style="background-color:#e1f5fe; color:#01579b; padding:8px"> <b>Note:</b> For an <b>account-level</b> <a href="https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app">OAuth app</a>, this API can only be used on behalf of a user who is assigned with a <a href="https://support.zoom.us/hc/en-us/articles/115001078646-Using-role-management#:~:text=Each%20user%20in%20a%20Zoom,owner%2C%20administrator%2C%20or%20member.&text=Role%2Dbased%20access%20control%20enables,needs%20to%20view%20or%20edit."> role</a> that has the <b>Edit</b> permission for <b>Chat Messages</b>.</p>
399 *
400 * **Scope:** `chat_message:write`,`chat_message:write:admin` <br>
401 * **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
402 *
403 * **Parameters:**
404 *
405 * * `message_id: &str` -- Message ID: Unique Identifier of the message.
406 */
407 pub async fn edit_message(
408 &self,
409 user_id: &str,
410 message_id: &str,
411 body: &crate::types::EditMessageRequest,
412 ) -> ClientResult<crate::Response<()>> {
413 let url = self.client.url(
414 &format!(
415 "/chat/users/{}/messages/{}",
416 crate::progenitor_support::encode_path(user_id),
417 crate::progenitor_support::encode_path(message_id),
418 ),
419 None,
420 );
421 self.client
422 .put(
423 &url,
424 crate::Message {
425 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
426 content_type: Some("application/json".to_string()),
427 },
428 )
429 .await
430 }
431 /**
432 * Delete a message.
433 *
434 * This function performs a `DELETE` to the `/chat/users/{userId}/messages/{messageId}` endpoint.
435 *
436 * Delete a chat message that you previously sent to a contact or a channel. For user-level apps, pass [the `me` value](https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#mekeyword) instead of the `userId` parameter.
437 *
438 * In the query parameter, you must provide either of the following:
439 *
440 * * `to_contact`: The email address of the contact to whom you sent the message. Use this parameter to delete a message sent to an individual contact in Zoom.
441 * * `to_channel`: The channel ID of the channel where you sent the message. Use this parameter to delete a message sent to a channel in Zoom.
442 *
443 *
444 *
445 * **Scopes:** `chat_message:write`, `chat_message:write:admin`<br>**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
446 *
447 * <p style="background-color:#e1f5fe; color:#01579b; padding:8px"> <b>Note:</b> For an <b>account-level</b> <a href="https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app">OAuth app</a>, this API can only be used on behalf of a user who is assigned with a <a href="https://support.zoom.us/hc/en-us/articles/115001078646-Using-role-management#:~:text=Each%20user%20in%20a%20Zoom,owner%2C%20administrator%2C%20or%20member.&text=Role%2Dbased%20access%20control%20enables,needs%20to%20view%20or%20edit."> role</a> that has the <b>Edit</b> permission for <b>Chat Messages</b>.</p>
448 *
449 * **Parameters:**
450 *
451 * * `message_id: &str` -- User's first name.
452 * * `to_contact: &str` -- The userId or email address of a chat contact to whom you previously sent the message.
453 *
454 * Note: You must provide either `to_contact` or `to_channel` as a query parameter to delete a message that was previously sent to either an individual or a chat channel respectively. .
455 * * `to_channel: &str` -- The channel Id of the channel where you would like to send the message.
456 *
457 * You must provide either `to_contact` or `to_channel` as a query parameter to delete a message that was previously sent to either an individual or a chat channel .
458 */
459 pub async fn delete(
460 &self,
461 user_id: &str,
462 message_id: &str,
463 to_contact: &str,
464 to_channel: &str,
465 ) -> ClientResult<crate::Response<()>> {
466 let mut query_args: Vec<(String, String)> = Default::default();
467 if !to_channel.is_empty() {
468 query_args.push(("to_channel".to_string(), to_channel.to_string()));
469 }
470 if !to_contact.is_empty() {
471 query_args.push(("to_contact".to_string(), to_contact.to_string()));
472 }
473 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
474 let url = self.client.url(
475 &format!(
476 "/chat/users/{}/messages/{}?{}",
477 crate::progenitor_support::encode_path(user_id),
478 crate::progenitor_support::encode_path(message_id),
479 query_
480 ),
481 None,
482 );
483 self.client
484 .delete(
485 &url,
486 crate::Message {
487 body: None,
488 content_type: None,
489 },
490 )
491 .await
492 }
493}