slack_chat_api/
conversations.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Conversations {
5    pub client: Client,
6}
7
8impl Conversations {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Conversations { client }
12    }
13
14    /**
15     * This function performs a `POST` to the `/conversations.archive` endpoint.
16     *
17     * Archives a conversation.
18     *
19     * FROM: <https://api.slack.com/methods/conversations.archive>
20     *
21     * **Parameters:**
22     *
23     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
24     */
25    pub async fn archive(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
26        let url = self.client.url("/conversations.archive", None);
27        self.client
28            .post(
29                &url,
30                crate::Message {
31                    body: None,
32                    content_type: Some("application/x-www-form-urlencoded".to_string()),
33                },
34            )
35            .await
36    }
37    /**
38     * This function performs a `POST` to the `/conversations.close` endpoint.
39     *
40     * Closes a direct message or multi-person direct message.
41     *
42     * FROM: <https://api.slack.com/methods/conversations.close>
43     *
44     * **Parameters:**
45     *
46     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
47     */
48    pub async fn close(
49        &self,
50    ) -> ClientResult<crate::Response<crate::types::ConversationsCloseSuccessSchema>> {
51        let url = self.client.url("/conversations.close", None);
52        self.client
53            .post(
54                &url,
55                crate::Message {
56                    body: None,
57                    content_type: Some("application/x-www-form-urlencoded".to_string()),
58                },
59            )
60            .await
61    }
62    /**
63     * This function performs a `POST` to the `/conversations.create` endpoint.
64     *
65     * Initiates a public or private channel-based conversation
66     *
67     * FROM: <https://api.slack.com/methods/conversations.create>
68     *
69     * **Parameters:**
70     *
71     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
72     */
73    pub async fn create(
74        &self,
75    ) -> ClientResult<crate::Response<crate::types::ConversationsInfoSuccessSchema>> {
76        let url = self.client.url("/conversations.create", None);
77        self.client
78            .post(
79                &url,
80                crate::Message {
81                    body: None,
82                    content_type: Some("application/x-www-form-urlencoded".to_string()),
83                },
84            )
85            .await
86    }
87    /**
88     * This function performs a `GET` to the `/conversations.history` endpoint.
89     *
90     * Fetches a conversation's history of messages and events.
91     *
92     * FROM: <https://api.slack.com/methods/conversations.history>
93     *
94     * **Parameters:**
95     *
96     * * `token: &str` -- Authentication token. Requires scope: `conversations:history`.
97     * * `channel: &str` -- Conversation ID to fetch history for.
98     * * `latest: f64` -- End of time range of messages to include in results.
99     * * `oldest: f64` -- Start of time range of messages to include in results.
100     * * `inclusive: bool` -- Include messages with latest or oldest timestamp in results only when either timestamp is specified.
101     * * `limit: i64` -- The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached.
102     * * `cursor: &str` -- Paginate through collections of data by setting the `cursor` parameter to a `next_cursor` attribute returned by a previous request's `response_metadata`. Default value fetches the first "page" of the collection. See [pagination](/docs/pagination) for more detail.
103     */
104    pub async fn history(
105        &self,
106        channel: &str,
107        latest: f64,
108        oldest: f64,
109        inclusive: bool,
110        limit: i64,
111        cursor: &str,
112    ) -> ClientResult<crate::Response<crate::types::ConversationsHistorySuccessSchema>> {
113        let mut query_args: Vec<(String, String)> = Default::default();
114        if !channel.is_empty() {
115            query_args.push(("channel".to_string(), channel.to_string()));
116        }
117        if !cursor.is_empty() {
118            query_args.push(("cursor".to_string(), cursor.to_string()));
119        }
120        if inclusive {
121            query_args.push(("inclusive".to_string(), inclusive.to_string()));
122        }
123        if !latest.to_string().is_empty() {
124            query_args.push(("latest".to_string(), latest.to_string()));
125        }
126        if limit > 0 {
127            query_args.push(("limit".to_string(), limit.to_string()));
128        }
129        if !oldest.to_string().is_empty() {
130            query_args.push(("oldest".to_string(), oldest.to_string()));
131        }
132        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
133        let url = self
134            .client
135            .url(&format!("/conversations.history?{}", query_), None);
136        self.client
137            .get(
138                &url,
139                crate::Message {
140                    body: None,
141                    content_type: None,
142                },
143            )
144            .await
145    }
146    /**
147     * This function performs a `GET` to the `/conversations.info` endpoint.
148     *
149     * Retrieve information about a conversation.
150     *
151     * FROM: <https://api.slack.com/methods/conversations.info>
152     *
153     * **Parameters:**
154     *
155     * * `token: &str` -- Authentication token. Requires scope: `conversations:read`.
156     * * `channel: &str` -- Conversation ID to learn more about.
157     * * `include_locale: bool` -- Set this to `true` to receive the locale for this conversation. Defaults to `false`.
158     * * `include_num_members: bool` -- Set to `true` to include the member count for the specified conversation. Defaults to `false`.
159     */
160    pub async fn info(
161        &self,
162        channel: &str,
163        include_locale: bool,
164        include_num_members: bool,
165    ) -> ClientResult<crate::Response<crate::types::ConversationsInfoSuccessSchema>> {
166        let mut query_args: Vec<(String, String)> = Default::default();
167        if !channel.is_empty() {
168            query_args.push(("channel".to_string(), channel.to_string()));
169        }
170        if include_locale {
171            query_args.push(("include_locale".to_string(), include_locale.to_string()));
172        }
173        if include_num_members {
174            query_args.push((
175                "include_num_members".to_string(),
176                include_num_members.to_string(),
177            ));
178        }
179        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
180        let url = self
181            .client
182            .url(&format!("/conversations.info?{}", query_), None);
183        self.client
184            .get(
185                &url,
186                crate::Message {
187                    body: None,
188                    content_type: None,
189                },
190            )
191            .await
192    }
193    /**
194     * This function performs a `POST` to the `/conversations.invite` endpoint.
195     *
196     * Invites users to a channel.
197     *
198     * FROM: <https://api.slack.com/methods/conversations.invite>
199     *
200     * **Parameters:**
201     *
202     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
203     */
204    pub async fn invite(
205        &self,
206    ) -> ClientResult<crate::Response<crate::types::ConversationsInfoSuccessSchema>> {
207        let url = self.client.url("/conversations.invite", None);
208        self.client
209            .post(
210                &url,
211                crate::Message {
212                    body: None,
213                    content_type: Some("application/x-www-form-urlencoded".to_string()),
214                },
215            )
216            .await
217    }
218    /**
219     * This function performs a `POST` to the `/conversations.join` endpoint.
220     *
221     * Joins an existing conversation.
222     *
223     * FROM: <https://api.slack.com/methods/conversations.join>
224     *
225     * **Parameters:**
226     *
227     * * `token: &str` -- Authentication token. Requires scope: `channels:write`.
228     */
229    pub async fn join(
230        &self,
231    ) -> ClientResult<crate::Response<crate::types::ConversationsJoinSuccessSchema>> {
232        let url = self.client.url("/conversations.join", None);
233        self.client
234            .post(
235                &url,
236                crate::Message {
237                    body: None,
238                    content_type: Some("application/x-www-form-urlencoded".to_string()),
239                },
240            )
241            .await
242    }
243    /**
244     * This function performs a `POST` to the `/conversations.kick` endpoint.
245     *
246     * Removes a user from a conversation.
247     *
248     * FROM: <https://api.slack.com/methods/conversations.kick>
249     *
250     * **Parameters:**
251     *
252     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
253     */
254    pub async fn kick(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
255        let url = self.client.url("/conversations.kick", None);
256        self.client
257            .post(
258                &url,
259                crate::Message {
260                    body: None,
261                    content_type: Some("application/x-www-form-urlencoded".to_string()),
262                },
263            )
264            .await
265    }
266    /**
267     * This function performs a `POST` to the `/conversations.leave` endpoint.
268     *
269     * Leaves a conversation.
270     *
271     * FROM: <https://api.slack.com/methods/conversations.leave>
272     *
273     * **Parameters:**
274     *
275     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
276     */
277    pub async fn leave(
278        &self,
279    ) -> ClientResult<crate::Response<crate::types::ConversationsLeaveSuccessSchema>> {
280        let url = self.client.url("/conversations.leave", None);
281        self.client
282            .post(
283                &url,
284                crate::Message {
285                    body: None,
286                    content_type: Some("application/x-www-form-urlencoded".to_string()),
287                },
288            )
289            .await
290    }
291    /**
292     * This function performs a `GET` to the `/conversations.list` endpoint.
293     *
294     * Lists all channels in a Slack team.
295     *
296     * FROM: <https://api.slack.com/methods/conversations.list>
297     *
298     * **Parameters:**
299     *
300     * * `token: &str` -- Authentication token. Requires scope: `conversations:read`.
301     * * `exclude_archived: bool` -- Set to `true` to exclude archived channels from the list.
302     * * `types: &str` -- Mix and match channel types by providing a comma-separated list of any combination of `public_channel`, `private_channel`, `mpim`, `im`.
303     * * `limit: i64` -- The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the list hasn't been reached. Must be an integer no larger than 1000.
304     * * `cursor: &str` -- Paginate through collections of data by setting the `cursor` parameter to a `next_cursor` attribute returned by a previous request's `response_metadata`. Default value fetches the first "page" of the collection. See [pagination](/docs/pagination) for more detail.
305     */
306    pub async fn list(
307        &self,
308        exclude_archived: bool,
309        types: &str,
310        limit: i64,
311        cursor: &str,
312    ) -> ClientResult<crate::Response<crate::types::ConversationsListSuccessSchema>> {
313        let mut query_args: Vec<(String, String)> = Default::default();
314        if !cursor.is_empty() {
315            query_args.push(("cursor".to_string(), cursor.to_string()));
316        }
317        if exclude_archived {
318            query_args.push(("exclude_archived".to_string(), exclude_archived.to_string()));
319        }
320        if limit > 0 {
321            query_args.push(("limit".to_string(), limit.to_string()));
322        }
323        if !types.is_empty() {
324            query_args.push(("types".to_string(), types.to_string()));
325        }
326        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
327        let url = self
328            .client
329            .url(&format!("/conversations.list?{}", query_), None);
330        self.client
331            .get(
332                &url,
333                crate::Message {
334                    body: None,
335                    content_type: None,
336                },
337            )
338            .await
339    }
340    /**
341     * This function performs a `POST` to the `/conversations.mark` endpoint.
342     *
343     * Sets the read cursor in a channel.
344     *
345     * FROM: <https://api.slack.com/methods/conversations.mark>
346     *
347     * **Parameters:**
348     *
349     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
350     */
351    pub async fn mark(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
352        let url = self.client.url("/conversations.mark", None);
353        self.client
354            .post(
355                &url,
356                crate::Message {
357                    body: None,
358                    content_type: Some("application/x-www-form-urlencoded".to_string()),
359                },
360            )
361            .await
362    }
363    /**
364     * This function performs a `GET` to the `/conversations.members` endpoint.
365     *
366     * Retrieve members of a conversation.
367     *
368     * FROM: <https://api.slack.com/methods/conversations.members>
369     *
370     * **Parameters:**
371     *
372     * * `token: &str` -- Authentication token. Requires scope: `conversations:read`.
373     * * `channel: &str` -- ID of the conversation to retrieve members for.
374     * * `limit: i64` -- The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached.
375     * * `cursor: &str` -- Paginate through collections of data by setting the `cursor` parameter to a `next_cursor` attribute returned by a previous request's `response_metadata`. Default value fetches the first "page" of the collection. See [pagination](/docs/pagination) for more detail.
376     */
377    pub async fn member(
378        &self,
379        channel: &str,
380        limit: i64,
381        cursor: &str,
382    ) -> ClientResult<crate::Response<crate::types::ConversationsMembersSuccessSchema>> {
383        let mut query_args: Vec<(String, String)> = Default::default();
384        if !channel.is_empty() {
385            query_args.push(("channel".to_string(), channel.to_string()));
386        }
387        if !cursor.is_empty() {
388            query_args.push(("cursor".to_string(), cursor.to_string()));
389        }
390        if limit > 0 {
391            query_args.push(("limit".to_string(), limit.to_string()));
392        }
393        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
394        let url = self
395            .client
396            .url(&format!("/conversations.members?{}", query_), None);
397        self.client
398            .get(
399                &url,
400                crate::Message {
401                    body: None,
402                    content_type: None,
403                },
404            )
405            .await
406    }
407    /**
408     * This function performs a `POST` to the `/conversations.open` endpoint.
409     *
410     * Opens or resumes a direct message or multi-person direct message.
411     *
412     * FROM: <https://api.slack.com/methods/conversations.open>
413     *
414     * **Parameters:**
415     *
416     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
417     */
418    pub async fn open(
419        &self,
420    ) -> ClientResult<crate::Response<crate::types::ConversationsOpenSuccessSchema>> {
421        let url = self.client.url("/conversations.open", None);
422        self.client
423            .post(
424                &url,
425                crate::Message {
426                    body: None,
427                    content_type: Some("application/x-www-form-urlencoded".to_string()),
428                },
429            )
430            .await
431    }
432    /**
433     * This function performs a `POST` to the `/conversations.rename` endpoint.
434     *
435     * Renames a conversation.
436     *
437     * FROM: <https://api.slack.com/methods/conversations.rename>
438     *
439     * **Parameters:**
440     *
441     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
442     */
443    pub async fn rename(
444        &self,
445    ) -> ClientResult<crate::Response<crate::types::ConversationsInfoSuccessSchema>> {
446        let url = self.client.url("/conversations.rename", None);
447        self.client
448            .post(
449                &url,
450                crate::Message {
451                    body: None,
452                    content_type: Some("application/x-www-form-urlencoded".to_string()),
453                },
454            )
455            .await
456    }
457    /**
458     * This function performs a `GET` to the `/conversations.replies` endpoint.
459     *
460     * Retrieve a thread of messages posted to a conversation
461     *
462     * FROM: <https://api.slack.com/methods/conversations.replies>
463     *
464     * **Parameters:**
465     *
466     * * `token: &str` -- Authentication token. Requires scope: `conversations:history`.
467     * * `channel: &str` -- Conversation ID to fetch thread from.
468     * * `ts: f64` -- Unique identifier of a thread's parent message. `ts` must be the timestamp of an existing message with 0 or more replies. If there are no replies then just the single message referenced by `ts` will return - it is just an ordinary, unthreaded message.
469     * * `latest: f64` -- End of time range of messages to include in results.
470     * * `oldest: f64` -- Start of time range of messages to include in results.
471     * * `inclusive: bool` -- Include messages with latest or oldest timestamp in results only when either timestamp is specified.
472     * * `limit: i64` -- The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached.
473     * * `cursor: &str` -- Paginate through collections of data by setting the `cursor` parameter to a `next_cursor` attribute returned by a previous request's `response_metadata`. Default value fetches the first "page" of the collection. See [pagination](/docs/pagination) for more detail.
474     */
475    pub async fn replie(
476        &self,
477        channel: &str,
478        ts: f64,
479        latest: f64,
480        oldest: f64,
481        inclusive: bool,
482        limit: i64,
483        cursor: &str,
484    ) -> ClientResult<crate::Response<crate::types::ConversationsRepliesSuccessSchema>> {
485        let mut query_args: Vec<(String, String)> = Default::default();
486        if !channel.is_empty() {
487            query_args.push(("channel".to_string(), channel.to_string()));
488        }
489        if !cursor.is_empty() {
490            query_args.push(("cursor".to_string(), cursor.to_string()));
491        }
492        if inclusive {
493            query_args.push(("inclusive".to_string(), inclusive.to_string()));
494        }
495        if !latest.to_string().is_empty() {
496            query_args.push(("latest".to_string(), latest.to_string()));
497        }
498        if limit > 0 {
499            query_args.push(("limit".to_string(), limit.to_string()));
500        }
501        if !oldest.to_string().is_empty() {
502            query_args.push(("oldest".to_string(), oldest.to_string()));
503        }
504        if !ts.to_string().is_empty() {
505            query_args.push(("ts".to_string(), ts.to_string()));
506        }
507        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
508        let url = self
509            .client
510            .url(&format!("/conversations.replies?{}", query_), None);
511        self.client
512            .get(
513                &url,
514                crate::Message {
515                    body: None,
516                    content_type: None,
517                },
518            )
519            .await
520    }
521    /**
522     * This function performs a `POST` to the `/conversations.setPurpose` endpoint.
523     *
524     * Sets the purpose for a conversation.
525     *
526     * FROM: <https://api.slack.com/methods/conversations.setPurpose>
527     *
528     * **Parameters:**
529     *
530     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
531     */
532    pub async fn set_purpose(
533        &self,
534    ) -> ClientResult<crate::Response<crate::types::ConversationsInfoSuccessSchema>> {
535        let url = self.client.url("/conversations.setPurpose", None);
536        self.client
537            .post(
538                &url,
539                crate::Message {
540                    body: None,
541                    content_type: Some("application/x-www-form-urlencoded".to_string()),
542                },
543            )
544            .await
545    }
546    /**
547     * This function performs a `POST` to the `/conversations.setTopic` endpoint.
548     *
549     * Sets the topic for a conversation.
550     *
551     * FROM: <https://api.slack.com/methods/conversations.setTopic>
552     *
553     * **Parameters:**
554     *
555     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
556     */
557    pub async fn set_topic(
558        &self,
559    ) -> ClientResult<crate::Response<crate::types::ConversationsInfoSuccessSchema>> {
560        let url = self.client.url("/conversations.setTopic", None);
561        self.client
562            .post(
563                &url,
564                crate::Message {
565                    body: None,
566                    content_type: Some("application/x-www-form-urlencoded".to_string()),
567                },
568            )
569            .await
570    }
571    /**
572     * This function performs a `POST` to the `/conversations.unarchive` endpoint.
573     *
574     * Reverses conversation archival.
575     *
576     * FROM: <https://api.slack.com/methods/conversations.unarchive>
577     *
578     * **Parameters:**
579     *
580     * * `token: &str` -- Authentication token. Requires scope: `conversations:write`.
581     */
582    pub async fn unarchive(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
583        let url = self.client.url("/conversations.unarchive", None);
584        self.client
585            .post(
586                &url,
587                crate::Message {
588                    body: None,
589                    content_type: Some("application/x-www-form-urlencoded".to_string()),
590                },
591            )
592            .await
593    }
594}