1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use anyhow::Result;

use crate::Client;

pub struct Rtm {
    pub client: Client,
}

impl Rtm {
    #[doc(hidden)]
    pub fn new(client: Client) -> Self {
        Rtm { client }
    }

    /**
     * This function performs a `GET` to the `/rtm.connect` endpoint.
     *
     * Starts a Real Time Messaging session.
     *
     * FROM: <https://api.slack.com/methods/rtm.connect>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `rtm:stream`.
     * * `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).
     * * `presence_sub: bool` -- Only deliver presence events when requested by subscription. See [presence subscriptions](/docs/presence-and-status#subscriptions).
     */
    pub async fn connect(
        &self,
        batch_presence_aware: bool,
        presence_sub: bool,
    ) -> Result<crate::types::RtmConnectSchema> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if batch_presence_aware {
            query_args.push((
                "batch_presence_aware".to_string(),
                batch_presence_aware.to_string(),
            ));
        }
        if presence_sub {
            query_args.push(("presence_sub".to_string(), presence_sub.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/rtm.connect?{}", query_);

        self.client.get(&url, None).await
    }
}