mattermost_rust_client/apis/
commands_api.rs

1/*
2 * Mattermost API Reference
3 *
4 * There is also a work-in-progress [Postman API reference](https://documenter.getpostman.com/view/4508214/RW8FERUn). 
5 *
6 * The version of the OpenAPI document: 4.0.0
7 * Contact: feedback@mattermost.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`create_command`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateCommandError {
22    Status400(crate::models::AppError),
23    Status401(crate::models::AppError),
24    Status403(crate::models::AppError),
25    Status501(crate::models::AppError),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`delete_command`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DeleteCommandError {
33    Status400(crate::models::AppError),
34    Status401(crate::models::AppError),
35    Status403(crate::models::AppError),
36    Status404(crate::models::AppError),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`execute_command`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ExecuteCommandError {
44    Status400(crate::models::AppError),
45    Status401(crate::models::AppError),
46    Status403(crate::models::AppError),
47    Status501(crate::models::AppError),
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`get_command_by_id`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum GetCommandByIdError {
55    Status400(crate::models::AppError),
56    Status401(crate::models::AppError),
57    Status404(crate::models::AppError),
58    UnknownValue(serde_json::Value),
59}
60
61/// struct for typed errors of method [`list_autocomplete_commands`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum ListAutocompleteCommandsError {
65    Status400(crate::models::AppError),
66    Status401(crate::models::AppError),
67    Status403(crate::models::AppError),
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`list_command_autocomplete_suggestions`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum ListCommandAutocompleteSuggestionsError {
75    Status400(crate::models::AppError),
76    Status401(crate::models::AppError),
77    Status403(crate::models::AppError),
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`list_commands`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum ListCommandsError {
85    Status400(crate::models::AppError),
86    Status401(crate::models::AppError),
87    Status403(crate::models::AppError),
88    Status501(crate::models::AppError),
89    UnknownValue(serde_json::Value),
90}
91
92/// struct for typed errors of method [`move_command`]
93#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum MoveCommandError {
96    Status400(crate::models::AppError),
97    Status401(crate::models::AppError),
98    Status403(crate::models::AppError),
99    Status404(crate::models::AppError),
100    UnknownValue(serde_json::Value),
101}
102
103/// struct for typed errors of method [`regen_command_token`]
104#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(untagged)]
106pub enum RegenCommandTokenError {
107    Status400(crate::models::AppError),
108    Status401(crate::models::AppError),
109    Status403(crate::models::AppError),
110    UnknownValue(serde_json::Value),
111}
112
113/// struct for typed errors of method [`update_command`]
114#[derive(Debug, Clone, Serialize, Deserialize)]
115#[serde(untagged)]
116pub enum UpdateCommandError {
117    Status400(crate::models::AppError),
118    Status401(crate::models::AppError),
119    Status403(crate::models::AppError),
120    UnknownValue(serde_json::Value),
121}
122
123
124/// Create a command for a team. ##### Permissions `manage_slash_commands` for the team the command is in. 
125pub async fn create_command(configuration: &configuration::Configuration, create_command_request: crate::models::CreateCommandRequest) -> Result<crate::models::Command, Error<CreateCommandError>> {
126    let local_var_configuration = configuration;
127
128    let local_var_client = &local_var_configuration.client;
129
130    let local_var_uri_str = format!("{}/commands", local_var_configuration.base_path);
131    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
132
133    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
134        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
135    }
136    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
137        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
138    };
139    local_var_req_builder = local_var_req_builder.json(&create_command_request);
140
141    let local_var_req = local_var_req_builder.build()?;
142    let local_var_resp = local_var_client.execute(local_var_req).await?;
143
144    let local_var_status = local_var_resp.status();
145    let local_var_content = local_var_resp.text().await?;
146
147    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
148        serde_json::from_str(&local_var_content).map_err(Error::from)
149    } else {
150        let local_var_entity: Option<CreateCommandError> = serde_json::from_str(&local_var_content).ok();
151        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
152        Err(Error::ResponseError(local_var_error))
153    }
154}
155
156/// Delete a command based on command id string. ##### Permissions Must have `manage_slash_commands` permission for the team the command is in. 
157pub async fn delete_command(configuration: &configuration::Configuration, command_id: &str) -> Result<crate::models::StatusOk, Error<DeleteCommandError>> {
158    let local_var_configuration = configuration;
159
160    let local_var_client = &local_var_configuration.client;
161
162    let local_var_uri_str = format!("{}/commands/{command_id}", local_var_configuration.base_path, command_id=crate::apis::urlencode(command_id));
163    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
164
165    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
166        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
167    }
168    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
169        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
170    };
171
172    let local_var_req = local_var_req_builder.build()?;
173    let local_var_resp = local_var_client.execute(local_var_req).await?;
174
175    let local_var_status = local_var_resp.status();
176    let local_var_content = local_var_resp.text().await?;
177
178    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
179        serde_json::from_str(&local_var_content).map_err(Error::from)
180    } else {
181        let local_var_entity: Option<DeleteCommandError> = serde_json::from_str(&local_var_content).ok();
182        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
183        Err(Error::ResponseError(local_var_error))
184    }
185}
186
187/// Execute a command on a team. ##### Permissions Must have `use_slash_commands` permission for the team the command is in. 
188pub async fn execute_command(configuration: &configuration::Configuration, execute_command_request: crate::models::ExecuteCommandRequest) -> Result<crate::models::CommandResponse, Error<ExecuteCommandError>> {
189    let local_var_configuration = configuration;
190
191    let local_var_client = &local_var_configuration.client;
192
193    let local_var_uri_str = format!("{}/commands/execute", local_var_configuration.base_path);
194    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
195
196    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
197        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
198    }
199    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
200        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
201    };
202    local_var_req_builder = local_var_req_builder.json(&execute_command_request);
203
204    let local_var_req = local_var_req_builder.build()?;
205    let local_var_resp = local_var_client.execute(local_var_req).await?;
206
207    let local_var_status = local_var_resp.status();
208    let local_var_content = local_var_resp.text().await?;
209
210    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
211        serde_json::from_str(&local_var_content).map_err(Error::from)
212    } else {
213        let local_var_entity: Option<ExecuteCommandError> = serde_json::from_str(&local_var_content).ok();
214        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
215        Err(Error::ResponseError(local_var_error))
216    }
217}
218
219/// Get a command definition based on command id string. ##### Permissions Must have `manage_slash_commands` permission for the team the command is in.  __Minimum server version__: 5.22 
220pub async fn get_command_by_id(configuration: &configuration::Configuration, command_id: &str) -> Result<crate::models::Command, Error<GetCommandByIdError>> {
221    let local_var_configuration = configuration;
222
223    let local_var_client = &local_var_configuration.client;
224
225    let local_var_uri_str = format!("{}/commands/{command_id}", local_var_configuration.base_path, command_id=crate::apis::urlencode(command_id));
226    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
227
228    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
229        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
230    }
231    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
232        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
233    };
234
235    let local_var_req = local_var_req_builder.build()?;
236    let local_var_resp = local_var_client.execute(local_var_req).await?;
237
238    let local_var_status = local_var_resp.status();
239    let local_var_content = local_var_resp.text().await?;
240
241    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
242        serde_json::from_str(&local_var_content).map_err(Error::from)
243    } else {
244        let local_var_entity: Option<GetCommandByIdError> = serde_json::from_str(&local_var_content).ok();
245        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
246        Err(Error::ResponseError(local_var_error))
247    }
248}
249
250/// List autocomplete commands in the team. ##### Permissions `view_team` for the team. 
251pub async fn list_autocomplete_commands(configuration: &configuration::Configuration, team_id: &str) -> Result<Vec<crate::models::Command>, Error<ListAutocompleteCommandsError>> {
252    let local_var_configuration = configuration;
253
254    let local_var_client = &local_var_configuration.client;
255
256    let local_var_uri_str = format!("{}/teams/{team_id}/commands/autocomplete", local_var_configuration.base_path, team_id=crate::apis::urlencode(team_id));
257    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
258
259    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
260        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
261    }
262    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
263        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
264    };
265
266    let local_var_req = local_var_req_builder.build()?;
267    let local_var_resp = local_var_client.execute(local_var_req).await?;
268
269    let local_var_status = local_var_resp.status();
270    let local_var_content = local_var_resp.text().await?;
271
272    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
273        serde_json::from_str(&local_var_content).map_err(Error::from)
274    } else {
275        let local_var_entity: Option<ListAutocompleteCommandsError> = serde_json::from_str(&local_var_content).ok();
276        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
277        Err(Error::ResponseError(local_var_error))
278    }
279}
280
281/// List commands' autocomplete data for the team. ##### Permissions `view_team` for the team. __Minimum server version__: 5.24 
282pub async fn list_command_autocomplete_suggestions(configuration: &configuration::Configuration, team_id: &str, user_input: &str) -> Result<Vec<crate::models::AutocompleteSuggestion>, Error<ListCommandAutocompleteSuggestionsError>> {
283    let local_var_configuration = configuration;
284
285    let local_var_client = &local_var_configuration.client;
286
287    let local_var_uri_str = format!("{}/teams/{team_id}/commands/autocomplete_suggestions", local_var_configuration.base_path, team_id=crate::apis::urlencode(team_id));
288    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
289
290    local_var_req_builder = local_var_req_builder.query(&[("user_input", &user_input.to_string())]);
291    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
292        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
293    }
294    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
295        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
296    };
297
298    let local_var_req = local_var_req_builder.build()?;
299    let local_var_resp = local_var_client.execute(local_var_req).await?;
300
301    let local_var_status = local_var_resp.status();
302    let local_var_content = local_var_resp.text().await?;
303
304    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
305        serde_json::from_str(&local_var_content).map_err(Error::from)
306    } else {
307        let local_var_entity: Option<ListCommandAutocompleteSuggestionsError> = serde_json::from_str(&local_var_content).ok();
308        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
309        Err(Error::ResponseError(local_var_error))
310    }
311}
312
313/// List commands for a team. ##### Permissions `manage_slash_commands` if need list custom commands. 
314pub async fn list_commands(configuration: &configuration::Configuration, team_id: Option<&str>, custom_only: Option<bool>) -> Result<Vec<crate::models::Command>, Error<ListCommandsError>> {
315    let local_var_configuration = configuration;
316
317    let local_var_client = &local_var_configuration.client;
318
319    let local_var_uri_str = format!("{}/commands", local_var_configuration.base_path);
320    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
321
322    if let Some(ref local_var_str) = team_id {
323        local_var_req_builder = local_var_req_builder.query(&[("team_id", &local_var_str.to_string())]);
324    }
325    if let Some(ref local_var_str) = custom_only {
326        local_var_req_builder = local_var_req_builder.query(&[("custom_only", &local_var_str.to_string())]);
327    }
328    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
329        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
330    }
331    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
332        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
333    };
334
335    let local_var_req = local_var_req_builder.build()?;
336    let local_var_resp = local_var_client.execute(local_var_req).await?;
337
338    let local_var_status = local_var_resp.status();
339    let local_var_content = local_var_resp.text().await?;
340
341    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
342        serde_json::from_str(&local_var_content).map_err(Error::from)
343    } else {
344        let local_var_entity: Option<ListCommandsError> = serde_json::from_str(&local_var_content).ok();
345        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
346        Err(Error::ResponseError(local_var_error))
347    }
348}
349
350/// Move a command to a different team based on command id string. ##### Permissions Must have `manage_slash_commands` permission for the team the command is currently in and the destination team.  __Minimum server version__: 5.22 
351pub async fn move_command(configuration: &configuration::Configuration, command_id: &str, move_command_request: crate::models::MoveCommandRequest) -> Result<crate::models::StatusOk, Error<MoveCommandError>> {
352    let local_var_configuration = configuration;
353
354    let local_var_client = &local_var_configuration.client;
355
356    let local_var_uri_str = format!("{}/commands/{command_id}/move", local_var_configuration.base_path, command_id=crate::apis::urlencode(command_id));
357    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
358
359    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
360        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
361    }
362    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
363        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
364    };
365    local_var_req_builder = local_var_req_builder.json(&move_command_request);
366
367    let local_var_req = local_var_req_builder.build()?;
368    let local_var_resp = local_var_client.execute(local_var_req).await?;
369
370    let local_var_status = local_var_resp.status();
371    let local_var_content = local_var_resp.text().await?;
372
373    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
374        serde_json::from_str(&local_var_content).map_err(Error::from)
375    } else {
376        let local_var_entity: Option<MoveCommandError> = serde_json::from_str(&local_var_content).ok();
377        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
378        Err(Error::ResponseError(local_var_error))
379    }
380}
381
382/// Generate a new token for the command based on command id string. ##### Permissions Must have `manage_slash_commands` permission for the team the command is in. 
383pub async fn regen_command_token(configuration: &configuration::Configuration, command_id: &str) -> Result<crate::models::RegenCommandToken200Response, Error<RegenCommandTokenError>> {
384    let local_var_configuration = configuration;
385
386    let local_var_client = &local_var_configuration.client;
387
388    let local_var_uri_str = format!("{}/commands/{command_id}/regen_token", local_var_configuration.base_path, command_id=crate::apis::urlencode(command_id));
389    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
390
391    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
392        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
393    }
394    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
395        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
396    };
397
398    let local_var_req = local_var_req_builder.build()?;
399    let local_var_resp = local_var_client.execute(local_var_req).await?;
400
401    let local_var_status = local_var_resp.status();
402    let local_var_content = local_var_resp.text().await?;
403
404    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
405        serde_json::from_str(&local_var_content).map_err(Error::from)
406    } else {
407        let local_var_entity: Option<RegenCommandTokenError> = serde_json::from_str(&local_var_content).ok();
408        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
409        Err(Error::ResponseError(local_var_error))
410    }
411}
412
413/// Update a single command based on command id string and Command struct. ##### Permissions Must have `manage_slash_commands` permission for the team the command is in. 
414pub async fn update_command(configuration: &configuration::Configuration, command_id: &str, command: crate::models::Command) -> Result<crate::models::Command, Error<UpdateCommandError>> {
415    let local_var_configuration = configuration;
416
417    let local_var_client = &local_var_configuration.client;
418
419    let local_var_uri_str = format!("{}/commands/{command_id}", local_var_configuration.base_path, command_id=crate::apis::urlencode(command_id));
420    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
421
422    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
423        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
424    }
425    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
426        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
427    };
428    local_var_req_builder = local_var_req_builder.json(&command);
429
430    let local_var_req = local_var_req_builder.build()?;
431    let local_var_resp = local_var_client.execute(local_var_req).await?;
432
433    let local_var_status = local_var_resp.status();
434    let local_var_content = local_var_resp.text().await?;
435
436    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
437        serde_json::from_str(&local_var_content).map_err(Error::from)
438    } else {
439        let local_var_entity: Option<UpdateCommandError> = serde_json::from_str(&local_var_content).ok();
440        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
441        Err(Error::ResponseError(local_var_error))
442    }
443}
444