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
use anyhow::Result;

use crate::Client;

pub struct Dnd {
    pub client: Client,
}

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

    /**
     * This function performs a `POST` to the `/dnd.endDnd` endpoint.
     *
     * Ends the current user's Do Not Disturb session immediately.
     *
     * FROM: <https://api.slack.com/methods/dnd.endDnd>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `dnd:write`.
     */
    pub async fn end(&self) -> Result<crate::types::DndEndSchema> {
        let url = "/dnd.endDnd".to_string();
        self.client.post(&url, None).await
    }

    /**
     * This function performs a `POST` to the `/dnd.endSnooze` endpoint.
     *
     * Ends the current user's snooze mode immediately.
     *
     * FROM: <https://api.slack.com/methods/dnd.endSnooze>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `dnd:write`.
     */
    pub async fn end_snooze(&self) -> Result<crate::types::DndEndSnoozeSchema> {
        let url = "/dnd.endSnooze".to_string();
        self.client.post(&url, None).await
    }

    /**
     * This function performs a `GET` to the `/dnd.info` endpoint.
     *
     * Retrieves a user's current Do Not Disturb status.
     *
     * FROM: <https://api.slack.com/methods/dnd.info>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `dnd:read`.
     * * `user: &str` -- User to fetch status for (defaults to current user).
     */
    pub async fn info(&self, user: &str) -> Result<crate::types::DndInfoSchema> {
        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!("/dnd.info?{}", query_);

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

    /**
     * This function performs a `POST` to the `/dnd.setSnooze` endpoint.
     *
     * Turns on Do Not Disturb mode for the current user, or changes its duration.
     *
     * FROM: <https://api.slack.com/methods/dnd.setSnooze>
     */
    pub async fn set_snooze(&self) -> Result<crate::types::DndSetSnoozeSchema> {
        let url = "/dnd.setSnooze".to_string();
        self.client.post(&url, None).await
    }

    /**
     * This function performs a `GET` to the `/dnd.teamInfo` endpoint.
     *
     * Retrieves the Do Not Disturb status for up to 50 users on a team.
     *
     * FROM: <https://api.slack.com/methods/dnd.teamInfo>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `dnd:read`.
     * * `users: &str` -- Comma-separated list of users to fetch Do Not Disturb status for.
     */
    pub async fn team_info(&self, users: &str) -> Result<crate::types::DndEndSchema> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !users.is_empty() {
            query_args.push(("users".to_string(), users.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/dnd.teamInfo?{}", query_);

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