Skip to main content

slack_web_api/api/
views.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 [`views.open`](https://docs.slack.dev/reference/methods/views.open): Open a view for a user.
12///
13/// Send it with [`SlackClient::views_open`].
14#[doc(alias = "views.open")]
15#[derive(Debug, Clone, PartialEq, Serialize)]
16#[non_exhaustive]
17pub struct ViewsOpenRequest {
18    /// A [view payload](https://docs.slack.dev/reference/views.md). This must be a JSON-encoded string.
19    pub view: crate::blocks::View,
20    /// Exchange a trigger to post to the user.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub trigger_id: Option<String>,
23    /// Exchange an interactivity pointer to post to the user.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub interactivity_pointer: Option<String>,
26}
27
28impl ViewsOpenRequest {
29    pub fn new(view: crate::blocks::View) -> Self {
30        Self {
31            view,
32            trigger_id: None,
33            interactivity_pointer: None,
34        }
35    }
36
37    pub fn trigger_id(mut self, trigger_id: impl Into<String>) -> Self {
38        self.trigger_id = Some(trigger_id.into());
39        self
40    }
41
42    pub fn interactivity_pointer(mut self, interactivity_pointer: impl Into<String>) -> Self {
43        self.interactivity_pointer = Some(interactivity_pointer.into());
44        self
45    }
46}
47
48impl SlackApiMethod for ViewsOpenRequest {
49    const METHOD: &'static str = "views.open";
50    type Response = ViewsOpenResponse;
51}
52
53/// Successful response of the Slack Web API method [`views.open`](https://docs.slack.dev/reference/methods/views.open).
54#[doc(alias = "views.open")]
55#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
56pub struct ViewsOpenResponse {
57    #[serde(
58        default,
59        deserialize_with = "crate::de::opt_object",
60        skip_serializing_if = "Option::is_none"
61    )]
62    pub view: Option<ViewInfo>,
63    #[serde(
64        default,
65        deserialize_with = "crate::de::opt_object",
66        skip_serializing_if = "Option::is_none"
67    )]
68    pub response_metadata: Option<ResponseMetadata>,
69    #[serde(
70        default,
71        deserialize_with = "crate::de::opt_string",
72        skip_serializing_if = "Option::is_none"
73    )]
74    pub warning: Option<String>,
75}
76
77/// Arguments for the Slack Web API method [`views.publish`](https://docs.slack.dev/reference/methods/views.publish): Publish a static view for a User.
78///
79/// Send it with [`SlackClient::views_publish`].
80#[doc(alias = "views.publish")]
81#[derive(Debug, Clone, PartialEq, Serialize)]
82#[non_exhaustive]
83pub struct ViewsPublishRequest {
84    /// `id` of the user you want publish a view to.
85    pub user_id: String,
86    /// A [view payload](https://docs.slack.dev/reference/views.md). This must be a JSON-encoded string.
87    pub view: crate::blocks::View,
88    /// A string that represents view state to protect against possible race conditions.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub hash: Option<String>,
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub interactivity_pointer: Option<String>,
93}
94
95impl ViewsPublishRequest {
96    pub fn new(user_id: impl Into<String>, view: crate::blocks::View) -> Self {
97        Self {
98            user_id: user_id.into(),
99            view,
100            hash: None,
101            interactivity_pointer: None,
102        }
103    }
104
105    pub fn hash(mut self, hash: impl Into<String>) -> Self {
106        self.hash = Some(hash.into());
107        self
108    }
109
110    pub fn interactivity_pointer(mut self, interactivity_pointer: impl Into<String>) -> Self {
111        self.interactivity_pointer = Some(interactivity_pointer.into());
112        self
113    }
114}
115
116impl SlackApiMethod for ViewsPublishRequest {
117    const METHOD: &'static str = "views.publish";
118    type Response = ViewsPublishResponse;
119}
120
121/// Successful response of the Slack Web API method [`views.publish`](https://docs.slack.dev/reference/methods/views.publish).
122#[doc(alias = "views.publish")]
123#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
124pub struct ViewsPublishResponse {
125    #[serde(
126        default,
127        deserialize_with = "crate::de::opt_object",
128        skip_serializing_if = "Option::is_none"
129    )]
130    pub view: Option<ViewInfo>,
131    #[serde(
132        default,
133        deserialize_with = "crate::de::opt_object",
134        skip_serializing_if = "Option::is_none"
135    )]
136    pub response_metadata: Option<ResponseMetadata>,
137    #[serde(
138        default,
139        deserialize_with = "crate::de::opt_string",
140        skip_serializing_if = "Option::is_none"
141    )]
142    pub warning: Option<String>,
143}
144
145/// Arguments for the Slack Web API method [`views.push`](https://docs.slack.dev/reference/methods/views.push): Push a view onto the stack of a root view.
146///
147/// Send it with [`SlackClient::views_push`].
148#[doc(alias = "views.push")]
149#[derive(Debug, Clone, PartialEq, Serialize)]
150#[non_exhaustive]
151pub struct ViewsPushRequest {
152    /// A [view payload](https://docs.slack.dev/reference/views.md). This must be a JSON-encoded string.
153    pub view: crate::blocks::View,
154    /// Exchange a trigger to post to the user.
155    #[serde(skip_serializing_if = "Option::is_none")]
156    pub trigger_id: Option<String>,
157    /// Exchange an interactivity pointer to post to the user.
158    #[serde(skip_serializing_if = "Option::is_none")]
159    pub interactivity_pointer: Option<String>,
160}
161
162impl ViewsPushRequest {
163    pub fn new(view: crate::blocks::View) -> Self {
164        Self {
165            view,
166            trigger_id: None,
167            interactivity_pointer: None,
168        }
169    }
170
171    pub fn trigger_id(mut self, trigger_id: impl Into<String>) -> Self {
172        self.trigger_id = Some(trigger_id.into());
173        self
174    }
175
176    pub fn interactivity_pointer(mut self, interactivity_pointer: impl Into<String>) -> Self {
177        self.interactivity_pointer = Some(interactivity_pointer.into());
178        self
179    }
180}
181
182impl SlackApiMethod for ViewsPushRequest {
183    const METHOD: &'static str = "views.push";
184    type Response = ViewsPushResponse;
185}
186
187/// Successful response of the Slack Web API method [`views.push`](https://docs.slack.dev/reference/methods/views.push).
188#[doc(alias = "views.push")]
189#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
190pub struct ViewsPushResponse {
191    #[serde(
192        default,
193        deserialize_with = "crate::de::opt_object",
194        skip_serializing_if = "Option::is_none"
195    )]
196    pub view: Option<ViewInfo>,
197    #[serde(
198        default,
199        deserialize_with = "crate::de::opt_object",
200        skip_serializing_if = "Option::is_none"
201    )]
202    pub response_metadata: Option<ResponseMetadata>,
203    #[serde(
204        default,
205        deserialize_with = "crate::de::opt_string",
206        skip_serializing_if = "Option::is_none"
207    )]
208    pub warning: Option<String>,
209}
210
211/// Arguments for the Slack Web API method [`views.update`](https://docs.slack.dev/reference/methods/views.update): Update an existing view.
212///
213/// Send it with [`SlackClient::views_update`].
214#[doc(alias = "views.update")]
215#[derive(Debug, Clone, PartialEq, Serialize)]
216#[non_exhaustive]
217pub struct ViewsUpdateRequest {
218    /// A [view object](https://docs.slack.dev/reference/views.md). This must be a JSON-encoded string.
219    pub view: crate::blocks::View,
220    /// A unique identifier of the view to be updated. Either `view_id` or `external_id` is required.
221    #[serde(skip_serializing_if = "Option::is_none")]
222    pub view_id: Option<String>,
223    /// A unique identifier of the view set by the developer. Must be unique for all views on a team. Max length of 255 characters. Either `view_id` or `external_id` is required.
224    #[serde(skip_serializing_if = "Option::is_none")]
225    pub external_id: Option<String>,
226    /// A string that represents view state to protect against possible race conditions.
227    #[serde(skip_serializing_if = "Option::is_none")]
228    pub hash: Option<String>,
229}
230
231impl ViewsUpdateRequest {
232    pub fn new(view: crate::blocks::View) -> Self {
233        Self {
234            view,
235            view_id: None,
236            external_id: None,
237            hash: None,
238        }
239    }
240
241    pub fn view_id(mut self, view_id: impl Into<String>) -> Self {
242        self.view_id = Some(view_id.into());
243        self
244    }
245
246    pub fn external_id(mut self, external_id: impl Into<String>) -> Self {
247        self.external_id = Some(external_id.into());
248        self
249    }
250
251    pub fn hash(mut self, hash: impl Into<String>) -> Self {
252        self.hash = Some(hash.into());
253        self
254    }
255}
256
257impl SlackApiMethod for ViewsUpdateRequest {
258    const METHOD: &'static str = "views.update";
259    type Response = ViewsUpdateResponse;
260}
261
262/// Successful response of the Slack Web API method [`views.update`](https://docs.slack.dev/reference/methods/views.update).
263#[doc(alias = "views.update")]
264#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
265pub struct ViewsUpdateResponse {
266    #[serde(
267        default,
268        deserialize_with = "crate::de::opt_object",
269        skip_serializing_if = "Option::is_none"
270    )]
271    pub view: Option<ViewInfo>,
272    #[serde(
273        default,
274        deserialize_with = "crate::de::opt_object",
275        skip_serializing_if = "Option::is_none"
276    )]
277    pub response_metadata: Option<ResponseMetadata>,
278    #[serde(
279        default,
280        deserialize_with = "crate::de::opt_string",
281        skip_serializing_if = "Option::is_none"
282    )]
283    pub warning: Option<String>,
284}
285
286impl SlackClient {
287    /// Calls the Slack Web API method [`views.open`](https://docs.slack.dev/reference/methods/views.open): Open a view for a user.
288    ///
289    /// Rate limit: Tier 4 (<https://docs.slack.dev/apis/web-api/rate-limits>).
290    ///
291    /// # Errors
292    ///
293    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
294    #[doc(alias = "views.open")]
295    pub async fn views_open(
296        &self,
297        request: &ViewsOpenRequest,
298    ) -> Result<ViewsOpenResponse, SlackError> {
299        self.call(request).await
300    }
301
302    /// Calls the Slack Web API method [`views.publish`](https://docs.slack.dev/reference/methods/views.publish): Publish a static view for a User.
303    ///
304    /// Rate limit: Tier 4 (<https://docs.slack.dev/apis/web-api/rate-limits>).
305    ///
306    /// # Errors
307    ///
308    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
309    #[doc(alias = "views.publish")]
310    pub async fn views_publish(
311        &self,
312        request: &ViewsPublishRequest,
313    ) -> Result<ViewsPublishResponse, SlackError> {
314        self.call(request).await
315    }
316
317    /// Calls the Slack Web API method [`views.push`](https://docs.slack.dev/reference/methods/views.push): Push a view onto the stack of a root view.
318    ///
319    /// Rate limit: Tier 4 (<https://docs.slack.dev/apis/web-api/rate-limits>).
320    ///
321    /// # Errors
322    ///
323    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
324    #[doc(alias = "views.push")]
325    pub async fn views_push(
326        &self,
327        request: &ViewsPushRequest,
328    ) -> Result<ViewsPushResponse, SlackError> {
329        self.call(request).await
330    }
331
332    /// Calls the Slack Web API method [`views.update`](https://docs.slack.dev/reference/methods/views.update): Update an existing view.
333    ///
334    /// Rate limit: Tier 4 (<https://docs.slack.dev/apis/web-api/rate-limits>).
335    ///
336    /// # Errors
337    ///
338    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
339    #[doc(alias = "views.update")]
340    pub async fn views_update(
341        &self,
342        request: &ViewsUpdateRequest,
343    ) -> Result<ViewsUpdateResponse, SlackError> {
344        self.call(request).await
345    }
346}