slack_chat_api/dnd.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Dnd {
5 pub client: Client,
6}
7
8impl Dnd {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Dnd { client }
12 }
13
14 /**
15 * This function performs a `POST` to the `/dnd.endDnd` endpoint.
16 *
17 * Ends the current user's Do Not Disturb session immediately.
18 *
19 * FROM: <https://api.slack.com/methods/dnd.endDnd>
20 *
21 * **Parameters:**
22 *
23 * * `token: &str` -- Authentication token. Requires scope: `dnd:write`.
24 */
25 pub async fn end(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
26 let url = self.client.url("/dnd.endDnd", None);
27 self.client
28 .post(
29 &url,
30 crate::Message {
31 body: None,
32 content_type: None,
33 },
34 )
35 .await
36 }
37 /**
38 * This function performs a `POST` to the `/dnd.endSnooze` endpoint.
39 *
40 * Ends the current user's snooze mode immediately.
41 *
42 * FROM: <https://api.slack.com/methods/dnd.endSnooze>
43 *
44 * **Parameters:**
45 *
46 * * `token: &str` -- Authentication token. Requires scope: `dnd:write`.
47 */
48 pub async fn end_snooze(
49 &self,
50 ) -> ClientResult<crate::Response<crate::types::DndEndSnoozeSchema>> {
51 let url = self.client.url("/dnd.endSnooze", None);
52 self.client
53 .post(
54 &url,
55 crate::Message {
56 body: None,
57 content_type: None,
58 },
59 )
60 .await
61 }
62 /**
63 * This function performs a `GET` to the `/dnd.info` endpoint.
64 *
65 * Retrieves a user's current Do Not Disturb status.
66 *
67 * FROM: <https://api.slack.com/methods/dnd.info>
68 *
69 * **Parameters:**
70 *
71 * * `token: &str` -- Authentication token. Requires scope: `dnd:read`.
72 * * `user: &str` -- User to fetch status for (defaults to current user).
73 */
74 pub async fn info(
75 &self,
76 user: &str,
77 ) -> ClientResult<crate::Response<crate::types::DndInfoSchema>> {
78 let mut query_args: Vec<(String, String)> = Default::default();
79 if !user.is_empty() {
80 query_args.push(("user".to_string(), user.to_string()));
81 }
82 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
83 let url = self.client.url(&format!("/dnd.info?{}", query_), None);
84 self.client
85 .get(
86 &url,
87 crate::Message {
88 body: None,
89 content_type: None,
90 },
91 )
92 .await
93 }
94 /**
95 * This function performs a `POST` to the `/dnd.setSnooze` endpoint.
96 *
97 * Turns on Do Not Disturb mode for the current user, or changes its duration.
98 *
99 * FROM: <https://api.slack.com/methods/dnd.setSnooze>
100 */
101 pub async fn set_snooze(
102 &self,
103 ) -> ClientResult<crate::Response<crate::types::DndSetSnoozeSchema>> {
104 let url = self.client.url("/dnd.setSnooze", None);
105 self.client
106 .post(
107 &url,
108 crate::Message {
109 body: None,
110 content_type: Some("application/x-www-form-urlencoded".to_string()),
111 },
112 )
113 .await
114 }
115 /**
116 * This function performs a `GET` to the `/dnd.teamInfo` endpoint.
117 *
118 * Retrieves the Do Not Disturb status for up to 50 users on a team.
119 *
120 * FROM: <https://api.slack.com/methods/dnd.teamInfo>
121 *
122 * **Parameters:**
123 *
124 * * `token: &str` -- Authentication token. Requires scope: `dnd:read`.
125 * * `users: &str` -- Comma-separated list of users to fetch Do Not Disturb status for.
126 */
127 pub async fn team_info(
128 &self,
129 users: &str,
130 ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
131 let mut query_args: Vec<(String, String)> = Default::default();
132 if !users.is_empty() {
133 query_args.push(("users".to_string(), users.to_string()));
134 }
135 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
136 let url = self.client.url(&format!("/dnd.teamInfo?{}", query_), None);
137 self.client
138 .get(
139 &url,
140 crate::Message {
141 body: None,
142 content_type: None,
143 },
144 )
145 .await
146 }
147}