slack_rust/users/profile/
set.rs

1use crate::error::Error;
2use crate::http_client::{get_slack_url, SlackWebAPIClient};
3use crate::profiles::profile::Profile;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
8pub struct SetRequest {
9    pub name: Option<String>,
10    pub profile: Option<Profile>,
11    pub user: Option<String>,
12    pub value: Option<String>,
13}
14
15#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
16pub struct SetResponse {
17    pub ok: bool,
18    pub error: Option<String>,
19    pub profile: Option<Profile>,
20}
21
22pub async fn set<T>(client: &T, param: &SetRequest, bot_token: &str) -> Result<SetResponse, Error>
23where
24    T: SlackWebAPIClient,
25{
26    let url = get_slack_url("users.profile.set");
27    let json = serde_json::to_string(&param)?;
28
29    client
30        .post_json(&url, &json, bot_token)
31        .await
32        .and_then(|result| {
33            serde_json::from_str::<SetResponse>(&result).map_err(Error::SerdeJsonError)
34        })
35}