Skip to main content

slack_web_api/api/
reactions.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 [`reactions.add`](https://docs.slack.dev/reference/methods/reactions.add): Adds a reaction to an item.
12///
13/// Send it with [`SlackClient::reactions_add`].
14#[doc(alias = "reactions.add")]
15#[derive(Debug, Clone, PartialEq, Serialize)]
16#[non_exhaustive]
17pub struct ReactionsAddRequest {
18    /// Channel where the message to add reaction to was posted.
19    pub channel: String,
20    /// Reaction (emoji) name
21    pub name: String,
22    /// Timestamp of the message to add reaction to.
23    pub timestamp: String,
24}
25
26impl ReactionsAddRequest {
27    pub fn new(
28        channel: impl Into<String>,
29        name: impl Into<String>,
30        timestamp: impl Into<String>,
31    ) -> Self {
32        Self {
33            channel: channel.into(),
34            name: name.into(),
35            timestamp: timestamp.into(),
36        }
37    }
38}
39
40impl SlackApiMethod for ReactionsAddRequest {
41    const METHOD: &'static str = "reactions.add";
42    type Response = ReactionsAddResponse;
43}
44
45/// Successful response of the Slack Web API method [`reactions.add`](https://docs.slack.dev/reference/methods/reactions.add).
46#[doc(alias = "reactions.add")]
47#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
48pub struct ReactionsAddResponse {
49    /// Fields returned by Slack. This method has no documented response example.
50    #[serde(flatten)]
51    pub extra: serde_json::Map<String, serde_json::Value>,
52    #[serde(
53        default,
54        deserialize_with = "crate::de::opt_object",
55        skip_serializing_if = "Option::is_none"
56    )]
57    pub response_metadata: Option<ResponseMetadata>,
58    #[serde(
59        default,
60        deserialize_with = "crate::de::opt_string",
61        skip_serializing_if = "Option::is_none"
62    )]
63    pub warning: Option<String>,
64}
65
66/// Arguments for the Slack Web API method [`reactions.get`](https://docs.slack.dev/reference/methods/reactions.get): Gets reactions for an item.
67///
68/// Send it with [`SlackClient::reactions_get`].
69#[doc(alias = "reactions.get")]
70#[derive(Debug, Clone, PartialEq, Serialize, Default)]
71#[non_exhaustive]
72pub struct ReactionsGetRequest {
73    /// Channel where the message to get reactions for was posted.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub channel: Option<String>,
76    /// File to get reactions for.
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub file: Option<String>,
79    /// File comment to get reactions for.
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub file_comment: Option<String>,
82    /// If true always return the complete reaction list.
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub full: Option<bool>,
85    /// Timestamp of the message to get reactions for.
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub timestamp: Option<String>,
88}
89
90impl ReactionsGetRequest {
91    pub fn new() -> Self {
92        Self {
93            channel: None,
94            file: None,
95            file_comment: None,
96            full: None,
97            timestamp: None,
98        }
99    }
100
101    pub fn channel(mut self, channel: impl Into<String>) -> Self {
102        self.channel = Some(channel.into());
103        self
104    }
105
106    pub fn file(mut self, file: impl Into<String>) -> Self {
107        self.file = Some(file.into());
108        self
109    }
110
111    pub fn file_comment(mut self, file_comment: impl Into<String>) -> Self {
112        self.file_comment = Some(file_comment.into());
113        self
114    }
115
116    pub fn full(mut self, full: bool) -> Self {
117        self.full = Some(full);
118        self
119    }
120
121    pub fn timestamp(mut self, timestamp: impl Into<String>) -> Self {
122        self.timestamp = Some(timestamp.into());
123        self
124    }
125}
126
127impl SlackApiMethod for ReactionsGetRequest {
128    const METHOD: &'static str = "reactions.get";
129    type Response = ReactionsGetResponse;
130}
131
132/// Successful response of the Slack Web API method [`reactions.get`](https://docs.slack.dev/reference/methods/reactions.get).
133#[doc(alias = "reactions.get")]
134#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
135pub struct ReactionsGetResponse {
136    #[serde(
137        default,
138        deserialize_with = "crate::de::opt_string",
139        skip_serializing_if = "Option::is_none"
140    )]
141    pub r#type: Option<String>,
142    #[serde(
143        default,
144        deserialize_with = "crate::de::opt_object",
145        skip_serializing_if = "Option::is_none"
146    )]
147    pub message: Option<Message>,
148    #[serde(
149        default,
150        deserialize_with = "crate::de::opt_string",
151        skip_serializing_if = "Option::is_none"
152    )]
153    pub channel: Option<String>,
154    #[serde(
155        default,
156        deserialize_with = "crate::de::opt_object",
157        skip_serializing_if = "Option::is_none"
158    )]
159    pub response_metadata: Option<ResponseMetadata>,
160    #[serde(
161        default,
162        deserialize_with = "crate::de::opt_string",
163        skip_serializing_if = "Option::is_none"
164    )]
165    pub warning: Option<String>,
166}
167
168/// Arguments for the Slack Web API method [`reactions.list`](https://docs.slack.dev/reference/methods/reactions.list): Lists reactions made by a user.
169///
170/// Send it with [`SlackClient::reactions_list`].
171#[doc(alias = "reactions.list")]
172#[derive(Debug, Clone, PartialEq, Serialize, Default)]
173#[non_exhaustive]
174pub struct ReactionsListRequest {
175    /// Show reactions made by this user. Defaults to the authed user.
176    #[serde(skip_serializing_if = "Option::is_none")]
177    pub user: Option<String>,
178    /// If true always return the complete reaction list.
179    #[serde(skip_serializing_if = "Option::is_none")]
180    pub full: Option<bool>,
181    #[serde(skip_serializing_if = "Option::is_none")]
182    pub count: Option<i64>,
183    #[serde(skip_serializing_if = "Option::is_none")]
184    pub page: Option<i64>,
185    /// Parameter for pagination. Set `cursor` equal to the `next_cursor` attribute returned by the previous request's `response_metadata`. This parameter is optional, but pagination is mandatory: the default value simply fetches the first "page" of the collection. See [pagination](https://docs.slack.dev/apis/web-api/pagination.md) for more details.
186    #[serde(skip_serializing_if = "Option::is_none")]
187    pub cursor: Option<String>,
188    /// The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the list hasn't been reached.
189    #[serde(skip_serializing_if = "Option::is_none")]
190    pub limit: Option<i64>,
191    /// encoded team id to list reactions in, required if org token is used
192    #[serde(skip_serializing_if = "Option::is_none")]
193    pub team_id: Option<String>,
194}
195
196impl ReactionsListRequest {
197    pub fn new() -> Self {
198        Self {
199            user: None,
200            full: None,
201            count: None,
202            page: None,
203            cursor: None,
204            limit: None,
205            team_id: None,
206        }
207    }
208
209    pub fn user(mut self, user: impl Into<String>) -> Self {
210        self.user = Some(user.into());
211        self
212    }
213
214    pub fn full(mut self, full: bool) -> Self {
215        self.full = Some(full);
216        self
217    }
218
219    pub fn count(mut self, count: i64) -> Self {
220        self.count = Some(count);
221        self
222    }
223
224    pub fn page(mut self, page: i64) -> Self {
225        self.page = Some(page);
226        self
227    }
228
229    pub fn cursor(mut self, cursor: impl Into<String>) -> Self {
230        self.cursor = Some(cursor.into());
231        self
232    }
233
234    pub fn limit(mut self, limit: i64) -> Self {
235        self.limit = Some(limit);
236        self
237    }
238
239    pub fn team_id(mut self, team_id: impl Into<String>) -> Self {
240        self.team_id = Some(team_id.into());
241        self
242    }
243}
244
245impl SlackApiMethod for ReactionsListRequest {
246    const METHOD: &'static str = "reactions.list";
247    type Response = ReactionsListResponse;
248}
249
250impl CursorPaginated for ReactionsListRequest {
251    fn set_cursor(&mut self, cursor: String) {
252        self.cursor = Some(cursor);
253    }
254}
255
256impl NextCursor for ReactionsListResponse {
257    fn next_cursor(&self) -> Option<&str> {
258        self.response_metadata.as_ref()?.next_cursor.as_deref()
259    }
260}
261
262/// Successful response of the Slack Web API method [`reactions.list`](https://docs.slack.dev/reference/methods/reactions.list).
263#[doc(alias = "reactions.list")]
264#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
265pub struct ReactionsListResponse {
266    #[serde(
267        default,
268        deserialize_with = "crate::de::vec",
269        skip_serializing_if = "Vec::is_empty"
270    )]
271    pub items: Vec<ReactionsListResponseItems>,
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
286#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
287pub struct ReactionsListResponseItems {
288    #[serde(
289        default,
290        deserialize_with = "crate::de::opt_string",
291        skip_serializing_if = "Option::is_none"
292    )]
293    pub r#type: Option<String>,
294    #[serde(
295        default,
296        deserialize_with = "crate::de::opt_string",
297        skip_serializing_if = "Option::is_none"
298    )]
299    pub channel: Option<String>,
300    #[serde(
301        default,
302        deserialize_with = "crate::de::opt_object",
303        skip_serializing_if = "Option::is_none"
304    )]
305    pub message: Option<Message>,
306    #[serde(
307        default,
308        deserialize_with = "crate::de::opt_object",
309        skip_serializing_if = "Option::is_none"
310    )]
311    pub comment: Option<ReactionsListResponseItemsComment>,
312    #[serde(
313        default,
314        deserialize_with = "crate::de::opt_object",
315        skip_serializing_if = "Option::is_none"
316    )]
317    pub file: Option<ReactionsListResponseItemsFile>,
318}
319
320#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
321pub struct ReactionsListResponseItemsComment {
322    #[serde(
323        default,
324        deserialize_with = "crate::de::opt_string",
325        skip_serializing_if = "Option::is_none"
326    )]
327    pub r#type: Option<String>,
328    #[serde(
329        default,
330        deserialize_with = "crate::de::opt_string",
331        skip_serializing_if = "Option::is_none"
332    )]
333    pub comment: Option<String>,
334    #[serde(
335        default,
336        deserialize_with = "crate::de::opt_i64",
337        skip_serializing_if = "Option::is_none"
338    )]
339    pub created: Option<i64>,
340    #[serde(
341        default,
342        deserialize_with = "crate::de::opt_string",
343        skip_serializing_if = "Option::is_none"
344    )]
345    pub id: Option<String>,
346    #[serde(
347        default,
348        deserialize_with = "crate::de::vec",
349        skip_serializing_if = "Vec::is_empty"
350    )]
351    pub reactions: Vec<Reaction>,
352    #[serde(
353        default,
354        deserialize_with = "crate::de::opt_i64",
355        skip_serializing_if = "Option::is_none"
356    )]
357    pub timestamp: Option<i64>,
358    #[serde(
359        default,
360        deserialize_with = "crate::de::opt_string",
361        skip_serializing_if = "Option::is_none"
362    )]
363    pub user: Option<String>,
364}
365
366#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
367pub struct ReactionsListResponseItemsFile {
368    #[serde(
369        default,
370        deserialize_with = "crate::de::vec",
371        skip_serializing_if = "Vec::is_empty"
372    )]
373    pub channels: Vec<String>,
374    #[serde(
375        default,
376        deserialize_with = "crate::de::opt_i64",
377        skip_serializing_if = "Option::is_none"
378    )]
379    pub comments_count: Option<i64>,
380    #[serde(
381        default,
382        deserialize_with = "crate::de::opt_i64",
383        skip_serializing_if = "Option::is_none"
384    )]
385    pub created: Option<i64>,
386    #[serde(
387        default,
388        deserialize_with = "crate::de::vec",
389        skip_serializing_if = "Vec::is_empty"
390    )]
391    pub reactions: Vec<Reaction>,
392    #[serde(
393        default,
394        deserialize_with = "crate::de::opt_string",
395        skip_serializing_if = "Option::is_none"
396    )]
397    pub title: Option<String>,
398    #[serde(
399        default,
400        deserialize_with = "crate::de::opt_string",
401        skip_serializing_if = "Option::is_none"
402    )]
403    pub user: Option<String>,
404    #[serde(
405        default,
406        deserialize_with = "crate::de::opt_string",
407        skip_serializing_if = "Option::is_none"
408    )]
409    pub username: Option<String>,
410    #[serde(
411        default,
412        deserialize_with = "crate::de::opt_string",
413        skip_serializing_if = "Option::is_none"
414    )]
415    pub id: Option<String>,
416    #[serde(
417        default,
418        deserialize_with = "crate::de::opt_string",
419        skip_serializing_if = "Option::is_none"
420    )]
421    pub name: Option<String>,
422    #[serde(
423        default,
424        deserialize_with = "crate::de::opt_i64",
425        skip_serializing_if = "Option::is_none"
426    )]
427    pub size: Option<i64>,
428}
429
430/// Arguments for the Slack Web API method [`reactions.remove`](https://docs.slack.dev/reference/methods/reactions.remove): Removes a reaction from an item.
431///
432/// Send it with [`SlackClient::reactions_remove`].
433#[doc(alias = "reactions.remove")]
434#[derive(Debug, Clone, PartialEq, Serialize)]
435#[non_exhaustive]
436pub struct ReactionsRemoveRequest {
437    /// Reaction (emoji) name.
438    pub name: String,
439    /// File to remove reaction from.
440    #[serde(skip_serializing_if = "Option::is_none")]
441    pub file: Option<String>,
442    /// File comment to remove reaction from.
443    #[serde(skip_serializing_if = "Option::is_none")]
444    pub file_comment: Option<String>,
445    /// Channel where the message to remove reaction from was posted.
446    #[serde(skip_serializing_if = "Option::is_none")]
447    pub channel: Option<String>,
448    /// Timestamp of the message to remove reaction from.
449    #[serde(skip_serializing_if = "Option::is_none")]
450    pub timestamp: Option<String>,
451}
452
453impl ReactionsRemoveRequest {
454    pub fn new(name: impl Into<String>) -> Self {
455        Self {
456            name: name.into(),
457            file: None,
458            file_comment: None,
459            channel: None,
460            timestamp: None,
461        }
462    }
463
464    pub fn file(mut self, file: impl Into<String>) -> Self {
465        self.file = Some(file.into());
466        self
467    }
468
469    pub fn file_comment(mut self, file_comment: impl Into<String>) -> Self {
470        self.file_comment = Some(file_comment.into());
471        self
472    }
473
474    pub fn channel(mut self, channel: impl Into<String>) -> Self {
475        self.channel = Some(channel.into());
476        self
477    }
478
479    pub fn timestamp(mut self, timestamp: impl Into<String>) -> Self {
480        self.timestamp = Some(timestamp.into());
481        self
482    }
483}
484
485impl SlackApiMethod for ReactionsRemoveRequest {
486    const METHOD: &'static str = "reactions.remove";
487    type Response = ReactionsRemoveResponse;
488}
489
490/// Successful response of the Slack Web API method [`reactions.remove`](https://docs.slack.dev/reference/methods/reactions.remove).
491#[doc(alias = "reactions.remove")]
492#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
493pub struct ReactionsRemoveResponse {
494    /// Fields returned by Slack. This method has no documented response example.
495    #[serde(flatten)]
496    pub extra: serde_json::Map<String, serde_json::Value>,
497    #[serde(
498        default,
499        deserialize_with = "crate::de::opt_object",
500        skip_serializing_if = "Option::is_none"
501    )]
502    pub response_metadata: Option<ResponseMetadata>,
503    #[serde(
504        default,
505        deserialize_with = "crate::de::opt_string",
506        skip_serializing_if = "Option::is_none"
507    )]
508    pub warning: Option<String>,
509}
510
511impl SlackClient {
512    /// Calls the Slack Web API method [`reactions.add`](https://docs.slack.dev/reference/methods/reactions.add): Adds a reaction to an item.
513    ///
514    /// Required scopes:
515    ///
516    /// - bot token: `reactions:write`
517    /// - user token: `reactions:write`
518    ///
519    /// Rate limit: Tier 3 (<https://docs.slack.dev/apis/web-api/rate-limits>).
520    ///
521    /// # Errors
522    ///
523    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
524    #[doc(alias = "reactions.add")]
525    pub async fn reactions_add(
526        &self,
527        request: &ReactionsAddRequest,
528    ) -> Result<ReactionsAddResponse, SlackError> {
529        self.call(request).await
530    }
531
532    /// Calls the Slack Web API method [`reactions.get`](https://docs.slack.dev/reference/methods/reactions.get): Gets reactions for an item.
533    ///
534    /// Required scopes:
535    ///
536    /// - bot token: `reactions:read`
537    /// - user token: `reactions:read`
538    ///
539    /// Rate limit: Tier 3 (<https://docs.slack.dev/apis/web-api/rate-limits>).
540    ///
541    /// # Errors
542    ///
543    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
544    #[doc(alias = "reactions.get")]
545    pub async fn reactions_get(
546        &self,
547        request: &ReactionsGetRequest,
548    ) -> Result<ReactionsGetResponse, SlackError> {
549        self.call(request).await
550    }
551
552    /// Calls the Slack Web API method [`reactions.list`](https://docs.slack.dev/reference/methods/reactions.list): Lists reactions made by a user.
553    ///
554    /// Required scopes:
555    ///
556    /// - bot token: `reactions:read`
557    /// - user token: `reactions:read`
558    ///
559    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
560    ///
561    /// # Errors
562    ///
563    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
564    #[doc(alias = "reactions.list")]
565    pub async fn reactions_list(
566        &self,
567        request: &ReactionsListRequest,
568    ) -> Result<ReactionsListResponse, SlackError> {
569        self.call(request).await
570    }
571
572    /// Calls the Slack Web API method [`reactions.remove`](https://docs.slack.dev/reference/methods/reactions.remove): Removes a reaction from an item.
573    ///
574    /// Required scopes:
575    ///
576    /// - bot token: `reactions:write`
577    /// - user token: `reactions:write`
578    ///
579    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
580    ///
581    /// # Errors
582    ///
583    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
584    #[doc(alias = "reactions.remove")]
585    pub async fn reactions_remove(
586        &self,
587        request: &ReactionsRemoveRequest,
588    ) -> Result<ReactionsRemoveResponse, SlackError> {
589        self.call(request).await
590    }
591}