slack_chat_api/rtm.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Rtm {
5 pub client: Client,
6}
7
8impl Rtm {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Rtm { client }
12 }
13
14 /**
15 * This function performs a `GET` to the `/rtm.connect` endpoint.
16 *
17 * Starts a Real Time Messaging session.
18 *
19 * FROM: <https://api.slack.com/methods/rtm.connect>
20 *
21 * **Parameters:**
22 *
23 * * `token: &str` -- Authentication token. Requires scope: `rtm:stream`.
24 * * `batch_presence_aware: bool` -- Batch presence deliveries via subscription. Enabling changes the shape of `presence_change` events. See [batch presence](/docs/presence-and-status#batching).
25 * * `presence_sub: bool` -- Only deliver presence events when requested by subscription. See [presence subscriptions](/docs/presence-and-status#subscriptions).
26 */
27 pub async fn connect(
28 &self,
29 batch_presence_aware: bool,
30 presence_sub: bool,
31 ) -> ClientResult<crate::Response<crate::types::RtmConnectSchema>> {
32 let mut query_args: Vec<(String, String)> = Default::default();
33 if batch_presence_aware {
34 query_args.push((
35 "batch_presence_aware".to_string(),
36 batch_presence_aware.to_string(),
37 ));
38 }
39 if presence_sub {
40 query_args.push(("presence_sub".to_string(), presence_sub.to_string()));
41 }
42 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
43 let url = self.client.url(&format!("/rtm.connect?{}", query_), None);
44 self.client
45 .get(
46 &url,
47 crate::Message {
48 body: None,
49 content_type: None,
50 },
51 )
52 .await
53 }
54}