Skip to main content

slack_web_api/api/
dnd.rs

1// このファイルは codegen/generate.py が生成する。手で編集しない
2
3#![allow(unused_imports)]
4
5use crate::objects::*;
6use crate::{
7    CursorPaginated, NextCursor, ResponseMetadata, SlackApiMethod, SlackClient, SlackError,
8};
9use serde::{Deserialize, Serialize};
10
11/// Arguments for the Slack Web API method [`dnd.endDnd`](https://docs.slack.dev/reference/methods/dnd.endDnd): Ends the current user's Do Not Disturb session immediately.
12///
13/// Send it with [`SlackClient::dnd_end_dnd`].
14#[doc(alias = "dnd.endDnd")]
15#[derive(Debug, Clone, PartialEq, Serialize, Default)]
16#[non_exhaustive]
17pub struct DndEndDndRequest {}
18
19impl DndEndDndRequest {
20    pub fn new() -> Self {
21        Self {}
22    }
23}
24
25impl SlackApiMethod for DndEndDndRequest {
26    const METHOD: &'static str = "dnd.endDnd";
27    type Response = DndEndDndResponse;
28}
29
30/// Successful response of the Slack Web API method [`dnd.endDnd`](https://docs.slack.dev/reference/methods/dnd.endDnd).
31#[doc(alias = "dnd.endDnd")]
32#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
33pub struct DndEndDndResponse {
34    /// Fields returned by Slack. This method has no documented response example.
35    #[serde(flatten)]
36    pub extra: serde_json::Map<String, serde_json::Value>,
37    #[serde(
38        default,
39        deserialize_with = "crate::de::opt_object",
40        skip_serializing_if = "Option::is_none"
41    )]
42    pub response_metadata: Option<ResponseMetadata>,
43    #[serde(
44        default,
45        deserialize_with = "crate::de::opt_string",
46        skip_serializing_if = "Option::is_none"
47    )]
48    pub warning: Option<String>,
49}
50
51/// Arguments for the Slack Web API method [`dnd.endSnooze`](https://docs.slack.dev/reference/methods/dnd.endSnooze): Ends the current user's snooze mode immediately.
52///
53/// Send it with [`SlackClient::dnd_end_snooze`].
54#[doc(alias = "dnd.endSnooze")]
55#[derive(Debug, Clone, PartialEq, Serialize, Default)]
56#[non_exhaustive]
57pub struct DndEndSnoozeRequest {}
58
59impl DndEndSnoozeRequest {
60    pub fn new() -> Self {
61        Self {}
62    }
63}
64
65impl SlackApiMethod for DndEndSnoozeRequest {
66    const METHOD: &'static str = "dnd.endSnooze";
67    type Response = DndEndSnoozeResponse;
68}
69
70/// Successful response of the Slack Web API method [`dnd.endSnooze`](https://docs.slack.dev/reference/methods/dnd.endSnooze).
71#[doc(alias = "dnd.endSnooze")]
72#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
73pub struct DndEndSnoozeResponse {
74    #[serde(
75        default,
76        deserialize_with = "crate::de::opt_bool",
77        skip_serializing_if = "Option::is_none"
78    )]
79    pub dnd_enabled: Option<bool>,
80    #[serde(
81        default,
82        deserialize_with = "crate::de::opt_i64",
83        skip_serializing_if = "Option::is_none"
84    )]
85    pub next_dnd_start_ts: Option<i64>,
86    #[serde(
87        default,
88        deserialize_with = "crate::de::opt_i64",
89        skip_serializing_if = "Option::is_none"
90    )]
91    pub next_dnd_end_ts: Option<i64>,
92    #[serde(
93        default,
94        deserialize_with = "crate::de::opt_bool",
95        skip_serializing_if = "Option::is_none"
96    )]
97    pub snooze_enabled: Option<bool>,
98    #[serde(
99        default,
100        deserialize_with = "crate::de::opt_object",
101        skip_serializing_if = "Option::is_none"
102    )]
103    pub response_metadata: Option<ResponseMetadata>,
104    #[serde(
105        default,
106        deserialize_with = "crate::de::opt_string",
107        skip_serializing_if = "Option::is_none"
108    )]
109    pub warning: Option<String>,
110}
111
112/// Arguments for the Slack Web API method [`dnd.info`](https://docs.slack.dev/reference/methods/dnd.info): Retrieves a user's current Do Not Disturb status.
113///
114/// Send it with [`SlackClient::dnd_info`].
115#[doc(alias = "dnd.info")]
116#[derive(Debug, Clone, PartialEq, Serialize, Default)]
117#[non_exhaustive]
118pub struct DndInfoRequest {
119    /// User to fetch status for (defaults to current user)
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub user: Option<String>,
122    /// Encoded team id where passed in user param belongs, required if org token is used. If no user param is passed, then a team which has access to the app should be passed
123    #[serde(skip_serializing_if = "Option::is_none")]
124    pub team_id: Option<String>,
125}
126
127impl DndInfoRequest {
128    pub fn new() -> Self {
129        Self {
130            user: None,
131            team_id: None,
132        }
133    }
134
135    pub fn user(mut self, user: impl Into<String>) -> Self {
136        self.user = Some(user.into());
137        self
138    }
139
140    pub fn team_id(mut self, team_id: impl Into<String>) -> Self {
141        self.team_id = Some(team_id.into());
142        self
143    }
144}
145
146impl SlackApiMethod for DndInfoRequest {
147    const METHOD: &'static str = "dnd.info";
148    type Response = DndInfoResponse;
149}
150
151/// Successful response of the Slack Web API method [`dnd.info`](https://docs.slack.dev/reference/methods/dnd.info).
152#[doc(alias = "dnd.info")]
153#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
154pub struct DndInfoResponse {
155    /// Fields returned by Slack. This method has no documented response example.
156    #[serde(flatten)]
157    pub extra: serde_json::Map<String, serde_json::Value>,
158    #[serde(
159        default,
160        deserialize_with = "crate::de::opt_object",
161        skip_serializing_if = "Option::is_none"
162    )]
163    pub response_metadata: Option<ResponseMetadata>,
164    #[serde(
165        default,
166        deserialize_with = "crate::de::opt_string",
167        skip_serializing_if = "Option::is_none"
168    )]
169    pub warning: Option<String>,
170}
171
172/// Arguments for the Slack Web API method [`dnd.setSnooze`](https://docs.slack.dev/reference/methods/dnd.setSnooze): Turns on Do Not Disturb mode for the current user, or changes its duration.
173///
174/// Send it with [`SlackClient::dnd_set_snooze`].
175#[doc(alias = "dnd.setSnooze")]
176#[derive(Debug, Clone, PartialEq, Serialize)]
177#[non_exhaustive]
178pub struct DndSetSnoozeRequest {
179    /// This argument is required. Number of minutes, from now, to snooze until.
180    pub num_minutes: String,
181}
182
183impl DndSetSnoozeRequest {
184    pub fn new(num_minutes: impl Into<String>) -> Self {
185        Self {
186            num_minutes: num_minutes.into(),
187        }
188    }
189}
190
191impl SlackApiMethod for DndSetSnoozeRequest {
192    const METHOD: &'static str = "dnd.setSnooze";
193    type Response = DndSetSnoozeResponse;
194}
195
196/// Successful response of the Slack Web API method [`dnd.setSnooze`](https://docs.slack.dev/reference/methods/dnd.setSnooze).
197#[doc(alias = "dnd.setSnooze")]
198#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
199pub struct DndSetSnoozeResponse {
200    #[serde(
201        default,
202        deserialize_with = "crate::de::opt_bool",
203        skip_serializing_if = "Option::is_none"
204    )]
205    pub snooze_enabled: Option<bool>,
206    #[serde(
207        default,
208        deserialize_with = "crate::de::opt_i64",
209        skip_serializing_if = "Option::is_none"
210    )]
211    pub snooze_endtime: Option<i64>,
212    #[serde(
213        default,
214        deserialize_with = "crate::de::opt_i64",
215        skip_serializing_if = "Option::is_none"
216    )]
217    pub snooze_remaining: Option<i64>,
218    #[serde(
219        default,
220        deserialize_with = "crate::de::opt_bool",
221        skip_serializing_if = "Option::is_none"
222    )]
223    pub snooze_is_indefinite: Option<bool>,
224    #[serde(
225        default,
226        deserialize_with = "crate::de::opt_object",
227        skip_serializing_if = "Option::is_none"
228    )]
229    pub response_metadata: Option<ResponseMetadata>,
230    #[serde(
231        default,
232        deserialize_with = "crate::de::opt_string",
233        skip_serializing_if = "Option::is_none"
234    )]
235    pub warning: Option<String>,
236}
237
238/// Arguments for the Slack Web API method [`dnd.teamInfo`](https://docs.slack.dev/reference/methods/dnd.teamInfo): Retrieves the Do Not Disturb status for up to 50 users on a team.
239///
240/// Send it with [`SlackClient::dnd_team_info`].
241#[doc(alias = "dnd.teamInfo")]
242#[derive(Debug, Clone, PartialEq, Serialize)]
243#[non_exhaustive]
244pub struct DndTeamInfoRequest {
245    /// Comma-separated list of users to fetch Do Not Disturb status for
246    pub users: String,
247    /// Encoded team id where passed in users belong, required if org token is used
248    #[serde(skip_serializing_if = "Option::is_none")]
249    pub team_id: Option<String>,
250}
251
252impl DndTeamInfoRequest {
253    pub fn new(users: impl Into<String>) -> Self {
254        Self {
255            users: users.into(),
256            team_id: None,
257        }
258    }
259
260    pub fn team_id(mut self, team_id: impl Into<String>) -> Self {
261        self.team_id = Some(team_id.into());
262        self
263    }
264}
265
266impl SlackApiMethod for DndTeamInfoRequest {
267    const METHOD: &'static str = "dnd.teamInfo";
268    type Response = DndTeamInfoResponse;
269}
270
271/// Successful response of the Slack Web API method [`dnd.teamInfo`](https://docs.slack.dev/reference/methods/dnd.teamInfo).
272#[doc(alias = "dnd.teamInfo")]
273#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
274pub struct DndTeamInfoResponse {
275    #[serde(
276        default,
277        deserialize_with = "crate::de::opt_object",
278        skip_serializing_if = "Option::is_none"
279    )]
280    pub users: Option<std::collections::HashMap<String, DndTeamInfoResponseUsersValue>>,
281    #[serde(
282        default,
283        deserialize_with = "crate::de::opt_object",
284        skip_serializing_if = "Option::is_none"
285    )]
286    pub response_metadata: Option<ResponseMetadata>,
287    #[serde(
288        default,
289        deserialize_with = "crate::de::opt_string",
290        skip_serializing_if = "Option::is_none"
291    )]
292    pub warning: Option<String>,
293}
294
295#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
296pub struct DndTeamInfoResponseUsersValue {
297    #[serde(
298        default,
299        deserialize_with = "crate::de::opt_bool",
300        skip_serializing_if = "Option::is_none"
301    )]
302    pub dnd_enabled: Option<bool>,
303    #[serde(
304        default,
305        deserialize_with = "crate::de::opt_i64",
306        skip_serializing_if = "Option::is_none"
307    )]
308    pub next_dnd_start_ts: Option<i64>,
309    #[serde(
310        default,
311        deserialize_with = "crate::de::opt_i64",
312        skip_serializing_if = "Option::is_none"
313    )]
314    pub next_dnd_end_ts: Option<i64>,
315}
316
317impl SlackClient {
318    /// Calls the Slack Web API method [`dnd.endDnd`](https://docs.slack.dev/reference/methods/dnd.endDnd): Ends the current user's Do Not Disturb session immediately.
319    ///
320    /// Required scopes:
321    ///
322    /// - user token: `dnd:write`
323    ///
324    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
325    ///
326    /// # Errors
327    ///
328    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
329    #[doc(alias = "dnd.endDnd")]
330    pub async fn dnd_end_dnd(
331        &self,
332        request: &DndEndDndRequest,
333    ) -> Result<DndEndDndResponse, SlackError> {
334        self.call(request).await
335    }
336
337    /// Calls the Slack Web API method [`dnd.endSnooze`](https://docs.slack.dev/reference/methods/dnd.endSnooze): Ends the current user's snooze mode immediately.
338    ///
339    /// Required scopes:
340    ///
341    /// - user token: `dnd:write`
342    ///
343    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
344    ///
345    /// # Errors
346    ///
347    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
348    #[doc(alias = "dnd.endSnooze")]
349    pub async fn dnd_end_snooze(
350        &self,
351        request: &DndEndSnoozeRequest,
352    ) -> Result<DndEndSnoozeResponse, SlackError> {
353        self.call(request).await
354    }
355
356    /// Calls the Slack Web API method [`dnd.info`](https://docs.slack.dev/reference/methods/dnd.info): Retrieves a user's current Do Not Disturb status.
357    ///
358    /// Required scopes:
359    ///
360    /// - bot token: `dnd:read`
361    /// - user token: `dnd:read`
362    ///
363    /// Rate limit: Tier 3 (<https://docs.slack.dev/apis/web-api/rate-limits>).
364    ///
365    /// # Errors
366    ///
367    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
368    #[doc(alias = "dnd.info")]
369    pub async fn dnd_info(&self, request: &DndInfoRequest) -> Result<DndInfoResponse, SlackError> {
370        self.call(request).await
371    }
372
373    /// Calls the Slack Web API method [`dnd.setSnooze`](https://docs.slack.dev/reference/methods/dnd.setSnooze): Turns on Do Not Disturb mode for the current user, or changes its duration.
374    ///
375    /// Required scopes:
376    ///
377    /// - user token: `dnd:write`
378    ///
379    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
380    ///
381    /// # Errors
382    ///
383    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
384    #[doc(alias = "dnd.setSnooze")]
385    pub async fn dnd_set_snooze(
386        &self,
387        request: &DndSetSnoozeRequest,
388    ) -> Result<DndSetSnoozeResponse, SlackError> {
389        self.call(request).await
390    }
391
392    /// Calls the Slack Web API method [`dnd.teamInfo`](https://docs.slack.dev/reference/methods/dnd.teamInfo): Retrieves the Do Not Disturb status for up to 50 users on a team.
393    ///
394    /// Required scopes:
395    ///
396    /// - bot token: `dnd:read`
397    /// - user token: `dnd:read`
398    ///
399    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
400    ///
401    /// # Errors
402    ///
403    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
404    #[doc(alias = "dnd.teamInfo")]
405    pub async fn dnd_team_info(
406        &self,
407        request: &DndTeamInfoRequest,
408    ) -> Result<DndTeamInfoResponse, SlackError> {
409        self.call(request).await
410    }
411}