Skip to main content

slack_web_api/api/
bookmarks.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 [`bookmarks.add`](https://docs.slack.dev/reference/methods/bookmarks.add): Add bookmark to a channel.
12///
13/// Send it with [`SlackClient::bookmarks_add`].
14#[doc(alias = "bookmarks.add")]
15#[derive(Debug, Clone, PartialEq, Serialize)]
16#[non_exhaustive]
17pub struct BookmarksAddRequest {
18    /// Title for the bookmark.
19    pub title: String,
20    /// Type of the bookmark i.e link.
21    pub r#type: String,
22    /// Channel to add bookmark in. Required for public channels.
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub channel_id: Option<String>,
25    /// Link to bookmark.
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub link: Option<String>,
28    /// Emoji tag to apply to the link.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub emoji: Option<String>,
31    /// ID of the entity being bookmarked. Only applies to message and file types.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub entity_id: Option<String>,
34    /// The level that we are setting the file's permission to (read or write)
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub access_level: Option<String>,
37    /// Id of this bookmark's parent
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub parent_id: Option<String>,
40}
41
42impl BookmarksAddRequest {
43    pub fn new(title: impl Into<String>, r#type: impl Into<String>) -> Self {
44        Self {
45            title: title.into(),
46            r#type: r#type.into(),
47            channel_id: None,
48            link: None,
49            emoji: None,
50            entity_id: None,
51            access_level: None,
52            parent_id: None,
53        }
54    }
55
56    pub fn channel_id(mut self, channel_id: impl Into<String>) -> Self {
57        self.channel_id = Some(channel_id.into());
58        self
59    }
60
61    pub fn link(mut self, link: impl Into<String>) -> Self {
62        self.link = Some(link.into());
63        self
64    }
65
66    pub fn emoji(mut self, emoji: impl Into<String>) -> Self {
67        self.emoji = Some(emoji.into());
68        self
69    }
70
71    pub fn entity_id(mut self, entity_id: impl Into<String>) -> Self {
72        self.entity_id = Some(entity_id.into());
73        self
74    }
75
76    pub fn access_level(mut self, access_level: impl Into<String>) -> Self {
77        self.access_level = Some(access_level.into());
78        self
79    }
80
81    pub fn parent_id(mut self, parent_id: impl Into<String>) -> Self {
82        self.parent_id = Some(parent_id.into());
83        self
84    }
85}
86
87impl SlackApiMethod for BookmarksAddRequest {
88    const METHOD: &'static str = "bookmarks.add";
89    type Response = BookmarksAddResponse;
90}
91
92/// Successful response of the Slack Web API method [`bookmarks.add`](https://docs.slack.dev/reference/methods/bookmarks.add).
93#[doc(alias = "bookmarks.add")]
94#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
95pub struct BookmarksAddResponse {
96    #[serde(
97        default,
98        deserialize_with = "crate::de::opt_object",
99        skip_serializing_if = "Option::is_none"
100    )]
101    pub bookmark: Option<Bookmark>,
102    #[serde(
103        default,
104        deserialize_with = "crate::de::opt_object",
105        skip_serializing_if = "Option::is_none"
106    )]
107    pub response_metadata: Option<ResponseMetadata>,
108    #[serde(
109        default,
110        deserialize_with = "crate::de::opt_string",
111        skip_serializing_if = "Option::is_none"
112    )]
113    pub warning: Option<String>,
114}
115
116/// Arguments for the Slack Web API method [`bookmarks.edit`](https://docs.slack.dev/reference/methods/bookmarks.edit): Edit bookmark.
117///
118/// Send it with [`SlackClient::bookmarks_edit`].
119#[doc(alias = "bookmarks.edit")]
120#[derive(Debug, Clone, PartialEq, Serialize, Default)]
121#[non_exhaustive]
122pub struct BookmarksEditRequest {
123    /// Channel to update bookmark in. Required for public channels.
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub channel_id: Option<String>,
126    /// Bookmark to update. Required for public channels.
127    #[serde(skip_serializing_if = "Option::is_none")]
128    pub bookmark_id: Option<String>,
129    /// Title for the bookmark.
130    #[serde(skip_serializing_if = "Option::is_none")]
131    pub title: Option<String>,
132    /// Link to bookmark.
133    #[serde(skip_serializing_if = "Option::is_none")]
134    pub link: Option<String>,
135    /// Emoji tag to apply to the link.
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub emoji: Option<String>,
138}
139
140impl BookmarksEditRequest {
141    pub fn new() -> Self {
142        Self {
143            channel_id: None,
144            bookmark_id: None,
145            title: None,
146            link: None,
147            emoji: None,
148        }
149    }
150
151    pub fn channel_id(mut self, channel_id: impl Into<String>) -> Self {
152        self.channel_id = Some(channel_id.into());
153        self
154    }
155
156    pub fn bookmark_id(mut self, bookmark_id: impl Into<String>) -> Self {
157        self.bookmark_id = Some(bookmark_id.into());
158        self
159    }
160
161    pub fn title(mut self, title: impl Into<String>) -> Self {
162        self.title = Some(title.into());
163        self
164    }
165
166    pub fn link(mut self, link: impl Into<String>) -> Self {
167        self.link = Some(link.into());
168        self
169    }
170
171    pub fn emoji(mut self, emoji: impl Into<String>) -> Self {
172        self.emoji = Some(emoji.into());
173        self
174    }
175}
176
177impl SlackApiMethod for BookmarksEditRequest {
178    const METHOD: &'static str = "bookmarks.edit";
179    type Response = BookmarksEditResponse;
180}
181
182/// Successful response of the Slack Web API method [`bookmarks.edit`](https://docs.slack.dev/reference/methods/bookmarks.edit).
183#[doc(alias = "bookmarks.edit")]
184#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
185pub struct BookmarksEditResponse {
186    #[serde(
187        default,
188        deserialize_with = "crate::de::opt_object",
189        skip_serializing_if = "Option::is_none"
190    )]
191    pub bookmark: Option<Bookmark>,
192    #[serde(
193        default,
194        deserialize_with = "crate::de::opt_object",
195        skip_serializing_if = "Option::is_none"
196    )]
197    pub response_metadata: Option<ResponseMetadata>,
198    #[serde(
199        default,
200        deserialize_with = "crate::de::opt_string",
201        skip_serializing_if = "Option::is_none"
202    )]
203    pub warning: Option<String>,
204}
205
206/// Arguments for the Slack Web API method [`bookmarks.list`](https://docs.slack.dev/reference/methods/bookmarks.list): List bookmark for the channel.
207///
208/// Send it with [`SlackClient::bookmarks_list`].
209#[doc(alias = "bookmarks.list")]
210#[derive(Debug, Clone, PartialEq, Serialize, Default)]
211#[non_exhaustive]
212pub struct BookmarksListRequest {
213    /// Channel to list bookmarks in. Required for public channels.
214    #[serde(skip_serializing_if = "Option::is_none")]
215    pub channel_id: Option<String>,
216}
217
218impl BookmarksListRequest {
219    pub fn new() -> Self {
220        Self { channel_id: None }
221    }
222
223    pub fn channel_id(mut self, channel_id: impl Into<String>) -> Self {
224        self.channel_id = Some(channel_id.into());
225        self
226    }
227}
228
229impl SlackApiMethod for BookmarksListRequest {
230    const METHOD: &'static str = "bookmarks.list";
231    type Response = BookmarksListResponse;
232}
233
234/// Successful response of the Slack Web API method [`bookmarks.list`](https://docs.slack.dev/reference/methods/bookmarks.list).
235#[doc(alias = "bookmarks.list")]
236#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
237pub struct BookmarksListResponse {
238    #[serde(
239        default,
240        deserialize_with = "crate::de::vec",
241        skip_serializing_if = "Vec::is_empty"
242    )]
243    pub bookmarks: Vec<Bookmark>,
244    #[serde(
245        default,
246        deserialize_with = "crate::de::opt_object",
247        skip_serializing_if = "Option::is_none"
248    )]
249    pub response_metadata: Option<ResponseMetadata>,
250    #[serde(
251        default,
252        deserialize_with = "crate::de::opt_string",
253        skip_serializing_if = "Option::is_none"
254    )]
255    pub warning: Option<String>,
256}
257
258/// Arguments for the Slack Web API method [`bookmarks.remove`](https://docs.slack.dev/reference/methods/bookmarks.remove): Remove bookmark from the channel.
259///
260/// Send it with [`SlackClient::bookmarks_remove`].
261#[doc(alias = "bookmarks.remove")]
262#[derive(Debug, Clone, PartialEq, Serialize, Default)]
263#[non_exhaustive]
264pub struct BookmarksRemoveRequest {
265    /// Channel to remove bookmark. Required for public channels.
266    #[serde(skip_serializing_if = "Option::is_none")]
267    pub channel_id: Option<String>,
268    /// Bookmark to remove. Required for public channels.
269    #[serde(skip_serializing_if = "Option::is_none")]
270    pub bookmark_id: Option<String>,
271    /// Quip section ID to unbookmark
272    #[serde(skip_serializing_if = "Option::is_none")]
273    pub quip_section_id: Option<String>,
274}
275
276impl BookmarksRemoveRequest {
277    pub fn new() -> Self {
278        Self {
279            channel_id: None,
280            bookmark_id: None,
281            quip_section_id: None,
282        }
283    }
284
285    pub fn channel_id(mut self, channel_id: impl Into<String>) -> Self {
286        self.channel_id = Some(channel_id.into());
287        self
288    }
289
290    pub fn bookmark_id(mut self, bookmark_id: impl Into<String>) -> Self {
291        self.bookmark_id = Some(bookmark_id.into());
292        self
293    }
294
295    pub fn quip_section_id(mut self, quip_section_id: impl Into<String>) -> Self {
296        self.quip_section_id = Some(quip_section_id.into());
297        self
298    }
299}
300
301impl SlackApiMethod for BookmarksRemoveRequest {
302    const METHOD: &'static str = "bookmarks.remove";
303    type Response = BookmarksRemoveResponse;
304}
305
306/// Successful response of the Slack Web API method [`bookmarks.remove`](https://docs.slack.dev/reference/methods/bookmarks.remove).
307#[doc(alias = "bookmarks.remove")]
308#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
309pub struct BookmarksRemoveResponse {
310    /// Fields returned by Slack. This method has no documented response example.
311    #[serde(flatten)]
312    pub extra: serde_json::Map<String, serde_json::Value>,
313    #[serde(
314        default,
315        deserialize_with = "crate::de::opt_object",
316        skip_serializing_if = "Option::is_none"
317    )]
318    pub response_metadata: Option<ResponseMetadata>,
319    #[serde(
320        default,
321        deserialize_with = "crate::de::opt_string",
322        skip_serializing_if = "Option::is_none"
323    )]
324    pub warning: Option<String>,
325}
326
327impl SlackClient {
328    /// Calls the Slack Web API method [`bookmarks.add`](https://docs.slack.dev/reference/methods/bookmarks.add): Add bookmark to a channel.
329    ///
330    /// Required scopes:
331    ///
332    /// - bot token: `bookmarks:write`
333    /// - user token: `bookmarks:write`
334    ///
335    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
336    ///
337    /// # Errors
338    ///
339    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
340    #[doc(alias = "bookmarks.add")]
341    pub async fn bookmarks_add(
342        &self,
343        request: &BookmarksAddRequest,
344    ) -> Result<BookmarksAddResponse, SlackError> {
345        self.call(request).await
346    }
347
348    /// Calls the Slack Web API method [`bookmarks.edit`](https://docs.slack.dev/reference/methods/bookmarks.edit): Edit bookmark.
349    ///
350    /// Required scopes:
351    ///
352    /// - bot token: `bookmarks:write`
353    /// - user token: `bookmarks:write`
354    ///
355    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
356    ///
357    /// # Errors
358    ///
359    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
360    #[doc(alias = "bookmarks.edit")]
361    pub async fn bookmarks_edit(
362        &self,
363        request: &BookmarksEditRequest,
364    ) -> Result<BookmarksEditResponse, SlackError> {
365        self.call(request).await
366    }
367
368    /// Calls the Slack Web API method [`bookmarks.list`](https://docs.slack.dev/reference/methods/bookmarks.list): List bookmark for the channel.
369    ///
370    /// Required scopes:
371    ///
372    /// - bot token: `bookmarks:read`
373    /// - user token: `bookmarks:read`
374    ///
375    /// Rate limit: Tier 3 (<https://docs.slack.dev/apis/web-api/rate-limits>).
376    ///
377    /// # Errors
378    ///
379    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
380    #[doc(alias = "bookmarks.list")]
381    pub async fn bookmarks_list(
382        &self,
383        request: &BookmarksListRequest,
384    ) -> Result<BookmarksListResponse, SlackError> {
385        self.call(request).await
386    }
387
388    /// Calls the Slack Web API method [`bookmarks.remove`](https://docs.slack.dev/reference/methods/bookmarks.remove): Remove bookmark from the channel.
389    ///
390    /// Required scopes:
391    ///
392    /// - bot token: `bookmarks:write`
393    /// - user token: `bookmarks:write`
394    ///
395    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
396    ///
397    /// # Errors
398    ///
399    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
400    #[doc(alias = "bookmarks.remove")]
401    pub async fn bookmarks_remove(
402        &self,
403        request: &BookmarksRemoveRequest,
404    ) -> Result<BookmarksRemoveResponse, SlackError> {
405        self.call(request).await
406    }
407}