slack_chat_api/
reactions.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Reactions {
5    pub client: Client,
6}
7
8impl Reactions {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Reactions { client }
12    }
13
14    /**
15     * This function performs a `POST` to the `/reactions.add` endpoint.
16     *
17     * Adds a reaction to an item.
18     *
19     * FROM: <https://api.slack.com/methods/reactions.add>
20     *
21     * **Parameters:**
22     *
23     * * `token: &str` -- Authentication token. Requires scope: `reactions:write`.
24     */
25    pub async fn add(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
26        let url = self.client.url("/reactions.add", 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 `GET` to the `/reactions.get` endpoint.
39     *
40     * Gets reactions for an item.
41     *
42     * FROM: <https://api.slack.com/methods/reactions.get>
43     *
44     * **Parameters:**
45     *
46     * * `token: &str` -- Authentication token. Requires scope: `reactions:read`.
47     * * `channel: &str` -- Channel where the message to get reactions for was posted.
48     * * `file: &str` -- File to get reactions for.
49     * * `file_comment: &str` -- File comment to get reactions for.
50     * * `full: bool` -- If true always return the complete reaction list.
51     * * `timestamp: &str` -- Timestamp of the message to get reactions for.
52     */
53    pub async fn get(
54        &self,
55        channel: &str,
56        file: &str,
57        file_comment: &str,
58        full: bool,
59        timestamp: &str,
60    ) -> ClientResult<crate::Response<crate::types::Fields>> {
61        let mut query_args: Vec<(String, String)> = Default::default();
62        if !channel.is_empty() {
63            query_args.push(("channel".to_string(), channel.to_string()));
64        }
65        if !file.is_empty() {
66            query_args.push(("file".to_string(), file.to_string()));
67        }
68        if !file_comment.is_empty() {
69            query_args.push(("file_comment".to_string(), file_comment.to_string()));
70        }
71        if full {
72            query_args.push(("full".to_string(), full.to_string()));
73        }
74        if !timestamp.is_empty() {
75            query_args.push(("timestamp".to_string(), timestamp.to_string()));
76        }
77        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
78        let url = self.client.url(&format!("/reactions.get?{}", query_), None);
79        self.client
80            .get(
81                &url,
82                crate::Message {
83                    body: None,
84                    content_type: None,
85                },
86            )
87            .await
88    }
89    /**
90     * This function performs a `GET` to the `/reactions.list` endpoint.
91     *
92     * Lists reactions made by a user.
93     *
94     * FROM: <https://api.slack.com/methods/reactions.list>
95     *
96     * **Parameters:**
97     *
98     * * `token: &str` -- Authentication token. Requires scope: `reactions:read`.
99     * * `user: &str` -- Show reactions made by this user. Defaults to the authed user.
100     * * `full: bool` -- If true always return the complete reaction list.
101     * * `count: i64`
102     * * `page: i64`
103     * * `cursor: &str` -- Parameter for pagination. Set `cursor` equal to the `next_cursor` attribute returned by the previous request's `response_metadata`. This parameter is optional, but pagination is mandatory: the default value simply fetches the first "page" of the collection. See [pagination](/docs/pagination) for more details.
104     * * `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.
105     */
106    pub async fn list(
107        &self,
108        user: &str,
109        full: bool,
110        count: i64,
111        page: i64,
112        cursor: &str,
113        limit: i64,
114    ) -> ClientResult<crate::Response<crate::types::ReactionsListSchema>> {
115        let mut query_args: Vec<(String, String)> = Default::default();
116        if count > 0 {
117            query_args.push(("count".to_string(), count.to_string()));
118        }
119        if !cursor.is_empty() {
120            query_args.push(("cursor".to_string(), cursor.to_string()));
121        }
122        if full {
123            query_args.push(("full".to_string(), full.to_string()));
124        }
125        if limit > 0 {
126            query_args.push(("limit".to_string(), limit.to_string()));
127        }
128        if page > 0 {
129            query_args.push(("page".to_string(), page.to_string()));
130        }
131        if !user.is_empty() {
132            query_args.push(("user".to_string(), user.to_string()));
133        }
134        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
135        let url = self
136            .client
137            .url(&format!("/reactions.list?{}", query_), None);
138        self.client
139            .get(
140                &url,
141                crate::Message {
142                    body: None,
143                    content_type: None,
144                },
145            )
146            .await
147    }
148    /**
149     * This function performs a `POST` to the `/reactions.remove` endpoint.
150     *
151     * Removes a reaction from an item.
152     *
153     * FROM: <https://api.slack.com/methods/reactions.remove>
154     *
155     * **Parameters:**
156     *
157     * * `token: &str` -- Authentication token. Requires scope: `reactions:write`.
158     */
159    pub async fn remove(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
160        let url = self.client.url("/reactions.remove", None);
161        self.client
162            .post(
163                &url,
164                crate::Message {
165                    body: None,
166                    content_type: Some("application/x-www-form-urlencoded".to_string()),
167                },
168            )
169            .await
170    }
171}