1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
use anyhow::Result;

use crate::Client;

pub struct Users {
    pub client: Client,
}

impl Users {
    #[doc(hidden)]
    pub fn new(client: Client) -> Self {
        Users { client }
    }

    /**
     * This function performs a `GET` to the `/users.conversations` endpoint.
     *
     * List conversations the calling user may access.
     *
     * FROM: <https://api.slack.com/methods/users.conversations>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `conversations:read`.
     * * `user: &str` -- Browse conversations by a specific user ID's membership. Non-public channels are restricted to those where the calling user shares membership.
     * * `types: &str` -- Mix and match channel types by providing a comma-separated list of any combination of `public_channel`, `private_channel`, `mpim`, `im`.
     * * `exclude_archived: bool` -- Set to `true` to exclude archived channels from the list.
     * * `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.
     * * `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.
     */
    pub async fn conversation(
        &self,
        user: &str,
        types: &str,
        exclude_archived: bool,
        limit: i64,
        cursor: &str,
    ) -> Result<crate::types::UsersConversationsSuccessSchema> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !cursor.is_empty() {
            query_args.push(("cursor".to_string(), cursor.to_string()));
        }
        if exclude_archived {
            query_args.push(("exclude_archived".to_string(), exclude_archived.to_string()));
        }
        if limit > 0 {
            query_args.push(("limit".to_string(), limit.to_string()));
        }
        if !types.is_empty() {
            query_args.push(("types".to_string(), types.to_string()));
        }
        if !user.is_empty() {
            query_args.push(("user".to_string(), user.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/users.conversations?{}", query_);

        self.client.get(&url, None).await
    }

    /**
     * This function performs a `POST` to the `/users.deletePhoto` endpoint.
     *
     * Delete the user profile photo
     *
     * FROM: <https://api.slack.com/methods/users.deletePhoto>
     */
    pub async fn delete_photo(&self) -> Result<crate::types::DndEndSchema> {
        let url = "/users.deletePhoto".to_string();
        self.client.post(&url, None).await
    }

    /**
     * This function performs a `GET` to the `/users.getPresence` endpoint.
     *
     * Gets user presence information.
     *
     * FROM: <https://api.slack.com/methods/users.getPresence>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `users:read`.
     * * `user: &str` -- User to get presence info on. Defaults to the authed user.
     */
    pub async fn get_presence(
        &self,
        user: &str,
    ) -> Result<crate::types::ApiMethodUsersGetPresence> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !user.is_empty() {
            query_args.push(("user".to_string(), user.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/users.getPresence?{}", query_);

        self.client.get(&url, None).await
    }

    /**
     * This function performs a `GET` to the `/users.identity` endpoint.
     *
     * Get a user's identity.
     *
     * FROM: <https://api.slack.com/methods/users.identity>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `identity.basic`.
     */
    pub async fn identity(&self) -> Result<Vec<crate::types::UsersIdentityResponseAnyOf>> {
        let url = "/users.identity".to_string();
        self.client.get(&url, None).await
    }

    /**
     * This function performs a `GET` to the `/users.identity` endpoint.
     *
     * As opposed to `identity`, this function returns all the pages of the request at once.
     *
     * Get a user's identity.
     *
     * FROM: <https://api.slack.com/methods/users.identity>
     */
    pub async fn get_all_identity(&self) -> Result<Vec<crate::types::UsersIdentityResponseAnyOf>> {
        let url = "/users.identity".to_string();
        self.client.get_all_pages(&url, None).await
    }

    /**
     * This function performs a `GET` to the `/users.info` endpoint.
     *
     * Gets information about a user.
     *
     * FROM: <https://api.slack.com/methods/users.info>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `users:read`.
     * * `include_locale: bool` -- Set this to `true` to receive the locale for this user. Defaults to `false`.
     * * `user: &str` -- User to get info on.
     */
    pub async fn info(
        &self,
        include_locale: bool,
        user: &str,
    ) -> Result<crate::types::UsersInfoSuccessSchema> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if include_locale {
            query_args.push(("include_locale".to_string(), include_locale.to_string()));
        }
        if !user.is_empty() {
            query_args.push(("user".to_string(), user.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/users.info?{}", query_);

        self.client.get(&url, None).await
    }

    /**
     * This function performs a `GET` to the `/users.list` endpoint.
     *
     * Lists all users in a Slack team.
     *
     * FROM: <https://api.slack.com/methods/users.list>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `users:read`.
     * * `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.
     * * `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.
     * * `include_locale: bool` -- Set this to `true` to receive the locale for users. Defaults to `false`.
     */
    pub async fn list(
        &self,
        limit: i64,
        cursor: &str,
        include_locale: bool,
    ) -> Result<crate::types::UsersListSchema> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !cursor.is_empty() {
            query_args.push(("cursor".to_string(), cursor.to_string()));
        }
        if include_locale {
            query_args.push(("include_locale".to_string(), include_locale.to_string()));
        }
        if limit > 0 {
            query_args.push(("limit".to_string(), limit.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/users.list?{}", query_);

        self.client.get(&url, None).await
    }

    /**
     * This function performs a `GET` to the `/users.lookupByEmail` endpoint.
     *
     * Find a user with an email address.
     *
     * FROM: <https://api.slack.com/methods/users.lookupByEmail>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `users:read.email`.
     * * `email: &str` -- An email address belonging to a user in the workspace.
     */
    pub async fn lookup_email(&self, email: &str) -> Result<crate::types::UsersInfoSuccessSchema> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !email.is_empty() {
            query_args.push(("email".to_string(), email.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/users.lookupByEmail?{}", query_);

        self.client.get(&url, None).await
    }

    /**
     * This function performs a `POST` to the `/users.setActive` endpoint.
     *
     * Marked a user as active. Deprecated and non-functional.
     *
     * FROM: <https://api.slack.com/methods/users.setActive>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `users:write`.
     */
    pub async fn set_active(&self) -> Result<crate::types::DndEndSchema> {
        let url = "/users.setActive".to_string();
        self.client.post(&url, None).await
    }

    /**
     * This function performs a `POST` to the `/users.setPhoto` endpoint.
     *
     * Set the user profile photo
     *
     * FROM: <https://api.slack.com/methods/users.setPhoto>
     */
    pub async fn set_photo(&self) -> Result<crate::types::UsersSetPhotoSchema> {
        let url = "/users.setPhoto".to_string();
        self.client.post(&url, None).await
    }

    /**
     * This function performs a `POST` to the `/users.setPresence` endpoint.
     *
     * Manually sets user presence.
     *
     * FROM: <https://api.slack.com/methods/users.setPresence>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `users:write`.
     */
    pub async fn set_presence(&self) -> Result<crate::types::DndEndSchema> {
        let url = "/users.setPresence".to_string();
        self.client.post(&url, None).await
    }
}