slack_chat_api/users.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Users {
5 pub client: Client,
6}
7
8impl Users {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Users { client }
12 }
13
14 /**
15 * This function performs a `GET` to the `/users.conversations` endpoint.
16 *
17 * List conversations the calling user may access.
18 *
19 * FROM: <https://api.slack.com/methods/users.conversations>
20 *
21 * **Parameters:**
22 *
23 * * `token: &str` -- Authentication token. Requires scope: `conversations:read`.
24 * * `user: &str` -- Browse conversations by a specific user ID's membership. Non-public channels are restricted to those where the calling user shares membership.
25 * * `types: &str` -- Mix and match channel types by providing a comma-separated list of any combination of `public_channel`, `private_channel`, `mpim`, `im`.
26 * * `exclude_archived: bool` -- Set to `true` to exclude archived channels from the list.
27 * * `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.
28 * * `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.
29 */
30 pub async fn conversation(
31 &self,
32 user: &str,
33 types: &str,
34 exclude_archived: bool,
35 limit: i64,
36 cursor: &str,
37 ) -> ClientResult<crate::Response<crate::types::UsersConversationsSuccessSchema>> {
38 let mut query_args: Vec<(String, String)> = Default::default();
39 if !cursor.is_empty() {
40 query_args.push(("cursor".to_string(), cursor.to_string()));
41 }
42 if exclude_archived {
43 query_args.push(("exclude_archived".to_string(), exclude_archived.to_string()));
44 }
45 if limit > 0 {
46 query_args.push(("limit".to_string(), limit.to_string()));
47 }
48 if !types.is_empty() {
49 query_args.push(("types".to_string(), types.to_string()));
50 }
51 if !user.is_empty() {
52 query_args.push(("user".to_string(), user.to_string()));
53 }
54 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
55 let url = self
56 .client
57 .url(&format!("/users.conversations?{}", query_), None);
58 self.client
59 .get(
60 &url,
61 crate::Message {
62 body: None,
63 content_type: None,
64 },
65 )
66 .await
67 }
68 /**
69 * This function performs a `POST` to the `/users.deletePhoto` endpoint.
70 *
71 * Delete the user profile photo
72 *
73 * FROM: <https://api.slack.com/methods/users.deletePhoto>
74 */
75 pub async fn delete_photo(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
76 let url = self.client.url("/users.deletePhoto", 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 `/users.getPresence` endpoint.
89 *
90 * Gets user presence information.
91 *
92 * FROM: <https://api.slack.com/methods/users.getPresence>
93 *
94 * **Parameters:**
95 *
96 * * `token: &str` -- Authentication token. Requires scope: `users:read`.
97 * * `user: &str` -- User to get presence info on. Defaults to the authed user.
98 */
99 pub async fn get_presence(
100 &self,
101 user: &str,
102 ) -> ClientResult<crate::Response<crate::types::ApiMethodUsersGetPresence>> {
103 let mut query_args: Vec<(String, String)> = Default::default();
104 if !user.is_empty() {
105 query_args.push(("user".to_string(), user.to_string()));
106 }
107 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
108 let url = self
109 .client
110 .url(&format!("/users.getPresence?{}", query_), None);
111 self.client
112 .get(
113 &url,
114 crate::Message {
115 body: None,
116 content_type: None,
117 },
118 )
119 .await
120 }
121 /**
122 * This function performs a `GET` to the `/users.identity` endpoint.
123 *
124 * Get a user's identity.
125 *
126 * FROM: <https://api.slack.com/methods/users.identity>
127 *
128 * **Parameters:**
129 *
130 * * `token: &str` -- Authentication token. Requires scope: `identity.basic`.
131 */
132 pub async fn identity(
133 &self,
134 ) -> ClientResult<crate::Response<Vec<crate::types::UsersIdentityResponseAnyOf>>> {
135 let url = self.client.url("/users.identity", 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 `/users.identity` endpoint.
148 *
149 * As opposed to `identity`, this function returns all the pages of the request at once.
150 *
151 * Get a user's identity.
152 *
153 * FROM: <https://api.slack.com/methods/users.identity>
154 */
155 pub async fn get_all_identity(
156 &self,
157 ) -> ClientResult<crate::Response<Vec<crate::types::UsersIdentityResponseAnyOf>>> {
158 let url = self.client.url("/users.identity", None);
159 self.client
160 .get_all_pages(
161 &url,
162 crate::Message {
163 body: None,
164 content_type: None,
165 },
166 )
167 .await
168 }
169 /**
170 * This function performs a `GET` to the `/users.info` endpoint.
171 *
172 * Gets information about a user.
173 *
174 * FROM: <https://api.slack.com/methods/users.info>
175 *
176 * **Parameters:**
177 *
178 * * `token: &str` -- Authentication token. Requires scope: `users:read`.
179 * * `include_locale: bool` -- Set this to `true` to receive the locale for this user. Defaults to `false`.
180 * * `user: &str` -- User to get info on.
181 */
182 pub async fn info(
183 &self,
184 include_locale: bool,
185 user: &str,
186 ) -> ClientResult<crate::Response<crate::types::UsersInfoSuccessSchema>> {
187 let mut query_args: Vec<(String, String)> = Default::default();
188 if include_locale {
189 query_args.push(("include_locale".to_string(), include_locale.to_string()));
190 }
191 if !user.is_empty() {
192 query_args.push(("user".to_string(), user.to_string()));
193 }
194 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
195 let url = self.client.url(&format!("/users.info?{}", query_), None);
196 self.client
197 .get(
198 &url,
199 crate::Message {
200 body: None,
201 content_type: None,
202 },
203 )
204 .await
205 }
206 /**
207 * This function performs a `GET` to the `/users.list` endpoint.
208 *
209 * Lists all users in a Slack team.
210 *
211 * FROM: <https://api.slack.com/methods/users.list>
212 *
213 * **Parameters:**
214 *
215 * * `token: &str` -- Authentication token. Requires scope: `users:read`.
216 * * `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. Providing no `limit` value will result in Slack attempting to deliver you the entire result set. If the collection is too large you may experience `limit_required` or HTTP 500 errors.
217 * * `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.
218 * * `include_locale: bool` -- Set this to `true` to receive the locale for users. Defaults to `false`.
219 */
220 pub async fn list(
221 &self,
222 limit: i64,
223 cursor: &str,
224 include_locale: bool,
225 ) -> ClientResult<crate::Response<crate::types::UsersListSchema>> {
226 let mut query_args: Vec<(String, String)> = Default::default();
227 if !cursor.is_empty() {
228 query_args.push(("cursor".to_string(), cursor.to_string()));
229 }
230 if include_locale {
231 query_args.push(("include_locale".to_string(), include_locale.to_string()));
232 }
233 if limit > 0 {
234 query_args.push(("limit".to_string(), limit.to_string()));
235 }
236 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
237 let url = self.client.url(&format!("/users.list?{}", query_), None);
238 self.client
239 .get(
240 &url,
241 crate::Message {
242 body: None,
243 content_type: None,
244 },
245 )
246 .await
247 }
248 /**
249 * This function performs a `GET` to the `/users.lookupByEmail` endpoint.
250 *
251 * Find a user with an email address.
252 *
253 * FROM: <https://api.slack.com/methods/users.lookupByEmail>
254 *
255 * **Parameters:**
256 *
257 * * `token: &str` -- Authentication token. Requires scope: `users:read.email`.
258 * * `email: &str` -- An email address belonging to a user in the workspace.
259 */
260 pub async fn lookup_email(
261 &self,
262 email: &str,
263 ) -> ClientResult<crate::Response<crate::types::UsersInfoSuccessSchema>> {
264 let mut query_args: Vec<(String, String)> = Default::default();
265 if !email.is_empty() {
266 query_args.push(("email".to_string(), email.to_string()));
267 }
268 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
269 let url = self
270 .client
271 .url(&format!("/users.lookupByEmail?{}", query_), None);
272 self.client
273 .get(
274 &url,
275 crate::Message {
276 body: None,
277 content_type: None,
278 },
279 )
280 .await
281 }
282 /**
283 * This function performs a `POST` to the `/users.setActive` endpoint.
284 *
285 * Marked a user as active. Deprecated and non-functional.
286 *
287 * FROM: <https://api.slack.com/methods/users.setActive>
288 *
289 * **Parameters:**
290 *
291 * * `token: &str` -- Authentication token. Requires scope: `users:write`.
292 */
293 pub async fn set_active(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
294 let url = self.client.url("/users.setActive", None);
295 self.client
296 .post(
297 &url,
298 crate::Message {
299 body: None,
300 content_type: None,
301 },
302 )
303 .await
304 }
305 /**
306 * This function performs a `POST` to the `/users.setPhoto` endpoint.
307 *
308 * Set the user profile photo
309 *
310 * FROM: <https://api.slack.com/methods/users.setPhoto>
311 */
312 pub async fn set_photo(
313 &self,
314 ) -> ClientResult<crate::Response<crate::types::UsersSetPhotoSchema>> {
315 let url = self.client.url("/users.setPhoto", None);
316 self.client
317 .post(
318 &url,
319 crate::Message {
320 body: None,
321 content_type: Some("application/x-www-form-urlencoded".to_string()),
322 },
323 )
324 .await
325 }
326 /**
327 * This function performs a `POST` to the `/users.setPresence` endpoint.
328 *
329 * Manually sets user presence.
330 *
331 * FROM: <https://api.slack.com/methods/users.setPresence>
332 *
333 * **Parameters:**
334 *
335 * * `token: &str` -- Authentication token. Requires scope: `users:write`.
336 */
337 pub async fn set_presence(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
338 let url = self.client.url("/users.setPresence", None);
339 self.client
340 .post(
341 &url,
342 crate::Message {
343 body: None,
344 content_type: Some("application/x-www-form-urlencoded".to_string()),
345 },
346 )
347 .await
348 }
349}