Skip to main content

slack_web_api/api/
rtm.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 [`rtm.connect`](https://docs.slack.dev/reference/methods/rtm.connect): Starts a Real Time Messaging session.
12///
13/// Send it with [`SlackClient::rtm_connect`].
14#[doc(alias = "rtm.connect")]
15#[derive(Debug, Clone, PartialEq, Serialize, Default)]
16#[non_exhaustive]
17pub struct RtmConnectRequest {
18    /// Batch presence deliveries via subscription. Enabling changes the shape of `presence_change` events. See [batch presence](https://docs.slack.dev/apis/web-api/user-presence-and-status.md#batching).
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub batch_presence_aware: Option<bool>,
21    /// Only deliver presence events when requested by subscription. See [presence subscriptions](https://docs.slack.dev/apis/web-api/user-presence-and-status.md#subscriptions).
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub presence_sub: Option<bool>,
24}
25
26impl RtmConnectRequest {
27    pub fn new() -> Self {
28        Self {
29            batch_presence_aware: None,
30            presence_sub: None,
31        }
32    }
33
34    pub fn batch_presence_aware(mut self, batch_presence_aware: bool) -> Self {
35        self.batch_presence_aware = Some(batch_presence_aware);
36        self
37    }
38
39    pub fn presence_sub(mut self, presence_sub: bool) -> Self {
40        self.presence_sub = Some(presence_sub);
41        self
42    }
43}
44
45impl SlackApiMethod for RtmConnectRequest {
46    const METHOD: &'static str = "rtm.connect";
47    type Response = RtmConnectResponse;
48}
49
50/// Successful response of the Slack Web API method [`rtm.connect`](https://docs.slack.dev/reference/methods/rtm.connect).
51#[doc(alias = "rtm.connect")]
52#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
53pub struct RtmConnectResponse {
54    #[serde(
55        rename = "self",
56        default,
57        deserialize_with = "crate::de::opt_object",
58        skip_serializing_if = "Option::is_none"
59    )]
60    pub self_: Option<RtmConnectResponseSelf>,
61    #[serde(
62        default,
63        deserialize_with = "crate::de::opt_object",
64        skip_serializing_if = "Option::is_none"
65    )]
66    pub team: Option<Team>,
67    #[serde(
68        default,
69        deserialize_with = "crate::de::opt_string",
70        skip_serializing_if = "Option::is_none"
71    )]
72    pub url: Option<String>,
73    #[serde(
74        default,
75        deserialize_with = "crate::de::opt_object",
76        skip_serializing_if = "Option::is_none"
77    )]
78    pub response_metadata: Option<ResponseMetadata>,
79    #[serde(
80        default,
81        deserialize_with = "crate::de::opt_string",
82        skip_serializing_if = "Option::is_none"
83    )]
84    pub warning: Option<String>,
85}
86
87#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
88pub struct RtmConnectResponseSelf {
89    #[serde(
90        default,
91        deserialize_with = "crate::de::opt_string",
92        skip_serializing_if = "Option::is_none"
93    )]
94    pub id: Option<String>,
95    #[serde(
96        default,
97        deserialize_with = "crate::de::opt_string",
98        skip_serializing_if = "Option::is_none"
99    )]
100    pub name: Option<String>,
101}
102
103/// Arguments for the Slack Web API method [`rtm.start`](https://docs.slack.dev/reference/methods/rtm.start): Deprecated: Starts a Real Time Messaging session. Use rtm.connect instead.
104///
105/// Send it with [`SlackClient::rtm_start`].
106#[doc(alias = "rtm.start")]
107#[derive(Debug, Clone, PartialEq, Serialize, Default)]
108#[non_exhaustive]
109pub struct RtmStartRequest {
110    /// Return timestamp only for latest message object of each channel (improves performance).
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub simple_latest: Option<bool>,
113    /// Skip unread counts for each channel (improves performance).
114    #[serde(skip_serializing_if = "Option::is_none")]
115    pub no_unreads: Option<bool>,
116    /// Returns MPIMs to the client in the API response.
117    #[serde(skip_serializing_if = "Option::is_none")]
118    pub mpim_aware: Option<bool>,
119    /// Only deliver presence events when requested by subscription. See [presence subscriptions](https://docs.slack.dev/apis/web-api/user-presence-and-status.md#subscriptions).
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub presence_sub: Option<bool>,
122    /// Batch presence deliveries via subscription. Enabling changes the shape of `presence_change` events. See [batch presence](https://docs.slack.dev/apis/web-api/user-presence-and-status.md#batching).
123    #[serde(skip_serializing_if = "Option::is_none")]
124    pub batch_presence_aware: Option<bool>,
125    /// Exclude latest timestamps for channels, groups, mpims, and ims. Automatically sets `no_unreads` to `1`
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub no_latest: Option<bool>,
128    /// Set this to `true` to receive the locale for users and channels. Defaults to `false`
129    #[serde(skip_serializing_if = "Option::is_none")]
130    pub include_locale: Option<bool>,
131}
132
133impl RtmStartRequest {
134    pub fn new() -> Self {
135        Self {
136            simple_latest: None,
137            no_unreads: None,
138            mpim_aware: None,
139            presence_sub: None,
140            batch_presence_aware: None,
141            no_latest: None,
142            include_locale: None,
143        }
144    }
145
146    pub fn simple_latest(mut self, simple_latest: bool) -> Self {
147        self.simple_latest = Some(simple_latest);
148        self
149    }
150
151    pub fn no_unreads(mut self, no_unreads: bool) -> Self {
152        self.no_unreads = Some(no_unreads);
153        self
154    }
155
156    pub fn mpim_aware(mut self, mpim_aware: bool) -> Self {
157        self.mpim_aware = Some(mpim_aware);
158        self
159    }
160
161    pub fn presence_sub(mut self, presence_sub: bool) -> Self {
162        self.presence_sub = Some(presence_sub);
163        self
164    }
165
166    pub fn batch_presence_aware(mut self, batch_presence_aware: bool) -> Self {
167        self.batch_presence_aware = Some(batch_presence_aware);
168        self
169    }
170
171    pub fn no_latest(mut self, no_latest: bool) -> Self {
172        self.no_latest = Some(no_latest);
173        self
174    }
175
176    pub fn include_locale(mut self, include_locale: bool) -> Self {
177        self.include_locale = Some(include_locale);
178        self
179    }
180}
181
182impl SlackApiMethod for RtmStartRequest {
183    const METHOD: &'static str = "rtm.start";
184    type Response = RtmStartResponse;
185}
186
187/// Successful response of the Slack Web API method [`rtm.start`](https://docs.slack.dev/reference/methods/rtm.start).
188#[doc(alias = "rtm.start")]
189#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
190pub struct RtmStartResponse {
191    /// Fields returned by Slack. This method has no documented response example.
192    #[serde(flatten)]
193    pub extra: serde_json::Map<String, serde_json::Value>,
194    #[serde(
195        default,
196        deserialize_with = "crate::de::opt_object",
197        skip_serializing_if = "Option::is_none"
198    )]
199    pub response_metadata: Option<ResponseMetadata>,
200    #[serde(
201        default,
202        deserialize_with = "crate::de::opt_string",
203        skip_serializing_if = "Option::is_none"
204    )]
205    pub warning: Option<String>,
206}
207
208impl SlackClient {
209    /// Calls the Slack Web API method [`rtm.connect`](https://docs.slack.dev/reference/methods/rtm.connect): Starts a Real Time Messaging session.
210    ///
211    /// Rate limit: Tier 1 (<https://docs.slack.dev/apis/web-api/rate-limits>).
212    ///
213    /// # Errors
214    ///
215    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
216    #[doc(alias = "rtm.connect")]
217    pub async fn rtm_connect(
218        &self,
219        request: &RtmConnectRequest,
220    ) -> Result<RtmConnectResponse, SlackError> {
221        self.call(request).await
222    }
223
224    /// Calls the Slack Web API method [`rtm.start`](https://docs.slack.dev/reference/methods/rtm.start): Deprecated: Starts a Real Time Messaging session. Use rtm.connect instead.
225    ///
226    /// Rate limit: Tier 1 (<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 = "rtm.start")]
232    pub async fn rtm_start(
233        &self,
234        request: &RtmStartRequest,
235    ) -> Result<RtmStartResponse, SlackError> {
236        self.call(request).await
237    }
238}