Skip to main content

slack_web_api/api/
pins.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 [`pins.add`](https://docs.slack.dev/reference/methods/pins.add): Pins an item to a channel.
12///
13/// Send it with [`SlackClient::pins_add`].
14#[doc(alias = "pins.add")]
15#[derive(Debug, Clone, PartialEq, Serialize)]
16#[non_exhaustive]
17pub struct PinsAddRequest {
18    /// Channel to pin the messsage to. You must also include a `timestamp` when pinning messages.
19    pub channel: String,
20    /// Timestamp of the message to pin. You must also include the `channel`.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub timestamp: Option<String>,
23}
24
25impl PinsAddRequest {
26    pub fn new(channel: impl Into<String>) -> Self {
27        Self {
28            channel: channel.into(),
29            timestamp: None,
30        }
31    }
32
33    pub fn timestamp(mut self, timestamp: impl Into<String>) -> Self {
34        self.timestamp = Some(timestamp.into());
35        self
36    }
37}
38
39impl SlackApiMethod for PinsAddRequest {
40    const METHOD: &'static str = "pins.add";
41    type Response = PinsAddResponse;
42}
43
44/// Successful response of the Slack Web API method [`pins.add`](https://docs.slack.dev/reference/methods/pins.add).
45#[doc(alias = "pins.add")]
46#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
47pub struct PinsAddResponse {
48    /// Fields returned by Slack. This method has no documented response example.
49    #[serde(flatten)]
50    pub extra: serde_json::Map<String, serde_json::Value>,
51    #[serde(
52        default,
53        deserialize_with = "crate::de::opt_object",
54        skip_serializing_if = "Option::is_none"
55    )]
56    pub response_metadata: Option<ResponseMetadata>,
57    #[serde(
58        default,
59        deserialize_with = "crate::de::opt_string",
60        skip_serializing_if = "Option::is_none"
61    )]
62    pub warning: Option<String>,
63}
64
65/// Arguments for the Slack Web API method [`pins.list`](https://docs.slack.dev/reference/methods/pins.list): Lists items pinned to a channel.
66///
67/// Send it with [`SlackClient::pins_list`].
68#[doc(alias = "pins.list")]
69#[derive(Debug, Clone, PartialEq, Serialize)]
70#[non_exhaustive]
71pub struct PinsListRequest {
72    /// Channel to get pinned items for.
73    pub channel: String,
74}
75
76impl PinsListRequest {
77    pub fn new(channel: impl Into<String>) -> Self {
78        Self {
79            channel: channel.into(),
80        }
81    }
82}
83
84impl SlackApiMethod for PinsListRequest {
85    const METHOD: &'static str = "pins.list";
86    type Response = PinsListResponse;
87}
88
89/// Successful response of the Slack Web API method [`pins.list`](https://docs.slack.dev/reference/methods/pins.list).
90#[doc(alias = "pins.list")]
91#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
92pub struct PinsListResponse {
93    #[serde(
94        default,
95        deserialize_with = "crate::de::vec",
96        skip_serializing_if = "Vec::is_empty"
97    )]
98    pub items: Vec<PinsListResponseItems>,
99    #[serde(
100        default,
101        deserialize_with = "crate::de::opt_object",
102        skip_serializing_if = "Option::is_none"
103    )]
104    pub response_metadata: Option<ResponseMetadata>,
105    #[serde(
106        default,
107        deserialize_with = "crate::de::opt_string",
108        skip_serializing_if = "Option::is_none"
109    )]
110    pub warning: Option<String>,
111}
112
113#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
114pub struct PinsListResponseItems {
115    #[serde(
116        default,
117        deserialize_with = "crate::de::opt_string",
118        skip_serializing_if = "Option::is_none"
119    )]
120    pub channel: Option<String>,
121    #[serde(
122        default,
123        deserialize_with = "crate::de::opt_i64",
124        skip_serializing_if = "Option::is_none"
125    )]
126    pub created: Option<i64>,
127    #[serde(
128        default,
129        deserialize_with = "crate::de::opt_string",
130        skip_serializing_if = "Option::is_none"
131    )]
132    pub created_by: Option<String>,
133    #[serde(
134        default,
135        deserialize_with = "crate::de::opt_object",
136        skip_serializing_if = "Option::is_none"
137    )]
138    pub message: Option<Message>,
139    #[serde(
140        default,
141        deserialize_with = "crate::de::opt_string",
142        skip_serializing_if = "Option::is_none"
143    )]
144    pub r#type: Option<String>,
145}
146
147/// Arguments for the Slack Web API method [`pins.remove`](https://docs.slack.dev/reference/methods/pins.remove): Un-pins an item from a channel.
148///
149/// Send it with [`SlackClient::pins_remove`].
150#[doc(alias = "pins.remove")]
151#[derive(Debug, Clone, PartialEq, Serialize)]
152#[non_exhaustive]
153pub struct PinsRemoveRequest {
154    /// Channel where the item is pinned to.
155    pub channel: String,
156    /// Timestamp of the message to un-pin.
157    #[serde(skip_serializing_if = "Option::is_none")]
158    pub timestamp: Option<String>,
159}
160
161impl PinsRemoveRequest {
162    pub fn new(channel: impl Into<String>) -> Self {
163        Self {
164            channel: channel.into(),
165            timestamp: None,
166        }
167    }
168
169    pub fn timestamp(mut self, timestamp: impl Into<String>) -> Self {
170        self.timestamp = Some(timestamp.into());
171        self
172    }
173}
174
175impl SlackApiMethod for PinsRemoveRequest {
176    const METHOD: &'static str = "pins.remove";
177    type Response = PinsRemoveResponse;
178}
179
180/// Successful response of the Slack Web API method [`pins.remove`](https://docs.slack.dev/reference/methods/pins.remove).
181#[doc(alias = "pins.remove")]
182#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
183pub struct PinsRemoveResponse {
184    /// Fields returned by Slack. This method has no documented response example.
185    #[serde(flatten)]
186    pub extra: serde_json::Map<String, serde_json::Value>,
187    #[serde(
188        default,
189        deserialize_with = "crate::de::opt_object",
190        skip_serializing_if = "Option::is_none"
191    )]
192    pub response_metadata: Option<ResponseMetadata>,
193    #[serde(
194        default,
195        deserialize_with = "crate::de::opt_string",
196        skip_serializing_if = "Option::is_none"
197    )]
198    pub warning: Option<String>,
199}
200
201impl SlackClient {
202    /// Calls the Slack Web API method [`pins.add`](https://docs.slack.dev/reference/methods/pins.add): Pins an item to a channel.
203    ///
204    /// Required scopes:
205    ///
206    /// - bot token: `pins:write`
207    /// - user token: `pins:write`
208    ///
209    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
210    ///
211    /// # Errors
212    ///
213    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
214    #[doc(alias = "pins.add")]
215    pub async fn pins_add(&self, request: &PinsAddRequest) -> Result<PinsAddResponse, SlackError> {
216        self.call(request).await
217    }
218
219    /// Calls the Slack Web API method [`pins.list`](https://docs.slack.dev/reference/methods/pins.list): Lists items pinned to a channel.
220    ///
221    /// Required scopes:
222    ///
223    /// - bot token: `pins:read`
224    /// - user token: `pins:read`
225    ///
226    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
227    ///
228    /// # Errors
229    ///
230    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
231    #[doc(alias = "pins.list")]
232    pub async fn pins_list(
233        &self,
234        request: &PinsListRequest,
235    ) -> Result<PinsListResponse, SlackError> {
236        self.call(request).await
237    }
238
239    /// Calls the Slack Web API method [`pins.remove`](https://docs.slack.dev/reference/methods/pins.remove): Un-pins an item from a channel.
240    ///
241    /// Required scopes:
242    ///
243    /// - bot token: `pins:write`
244    /// - user token: `pins:write`
245    ///
246    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
247    ///
248    /// # Errors
249    ///
250    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
251    #[doc(alias = "pins.remove")]
252    pub async fn pins_remove(
253        &self,
254        request: &PinsRemoveRequest,
255    ) -> Result<PinsRemoveResponse, SlackError> {
256        self.call(request).await
257    }
258}