slack_chat_api/
views.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Views {
5    pub client: Client,
6}
7
8impl Views {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Views { client }
12    }
13
14    /**
15     * This function performs a `GET` to the `/views.open` endpoint.
16     *
17     * Open a view for a user.
18     *
19     * FROM: <https://api.slack.com/methods/views.open>
20     *
21     * **Parameters:**
22     *
23     * * `token: &str` -- Authentication token. Requires scope: `none`.
24     * * `trigger_id: &str` -- Exchange a trigger to post to the user.
25     * * `view: &str` -- A [view payload](/reference/surfaces/views). This must be a JSON-encoded string.
26     */
27    pub async fn open(
28        &self,
29        trigger_id: &str,
30        view: &str,
31    ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
32        let mut query_args: Vec<(String, String)> = Default::default();
33        if !trigger_id.is_empty() {
34            query_args.push(("trigger_id".to_string(), trigger_id.to_string()));
35        }
36        if !view.is_empty() {
37            query_args.push(("view".to_string(), view.to_string()));
38        }
39        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
40        let url = self.client.url(&format!("/views.open?{}", query_), None);
41        self.client
42            .get(
43                &url,
44                crate::Message {
45                    body: None,
46                    content_type: None,
47                },
48            )
49            .await
50    }
51    /**
52     * This function performs a `GET` to the `/views.publish` endpoint.
53     *
54     * Publish a static view for a User.
55     *
56     * FROM: <https://api.slack.com/methods/views.publish>
57     *
58     * **Parameters:**
59     *
60     * * `token: &str` -- Authentication token. Requires scope: `none`.
61     * * `user_id: &str` -- `id` of the user you want publish a view to.
62     * * `view: &str` -- A [view payload](/reference/surfaces/views). This must be a JSON-encoded string.
63     * * `hash: &str` -- A string that represents view state to protect against possible race conditions.
64     */
65    pub async fn publish(
66        &self,
67        user_id: &str,
68        view: &str,
69        hash: &str,
70    ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
71        let mut query_args: Vec<(String, String)> = Default::default();
72        if !hash.is_empty() {
73            query_args.push(("hash".to_string(), hash.to_string()));
74        }
75        if !user_id.is_empty() {
76            query_args.push(("user_id".to_string(), user_id.to_string()));
77        }
78        if !view.is_empty() {
79            query_args.push(("view".to_string(), view.to_string()));
80        }
81        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
82        let url = self.client.url(&format!("/views.publish?{}", query_), None);
83        self.client
84            .get(
85                &url,
86                crate::Message {
87                    body: None,
88                    content_type: None,
89                },
90            )
91            .await
92    }
93    /**
94     * This function performs a `GET` to the `/views.push` endpoint.
95     *
96     * Push a view onto the stack of a root view.
97     *
98     * FROM: <https://api.slack.com/methods/views.push>
99     *
100     * **Parameters:**
101     *
102     * * `token: &str` -- Authentication token. Requires scope: `none`.
103     * * `trigger_id: &str` -- Exchange a trigger to post to the user.
104     * * `view: &str` -- A [view payload](/reference/surfaces/views). This must be a JSON-encoded string.
105     */
106    pub async fn push(
107        &self,
108        trigger_id: &str,
109        view: &str,
110    ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
111        let mut query_args: Vec<(String, String)> = Default::default();
112        if !trigger_id.is_empty() {
113            query_args.push(("trigger_id".to_string(), trigger_id.to_string()));
114        }
115        if !view.is_empty() {
116            query_args.push(("view".to_string(), view.to_string()));
117        }
118        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
119        let url = self.client.url(&format!("/views.push?{}", query_), None);
120        self.client
121            .get(
122                &url,
123                crate::Message {
124                    body: None,
125                    content_type: None,
126                },
127            )
128            .await
129    }
130    /**
131     * This function performs a `GET` to the `/views.update` endpoint.
132     *
133     * Update an existing view.
134     *
135     * FROM: <https://api.slack.com/methods/views.update>
136     *
137     * **Parameters:**
138     *
139     * * `token: &str` -- Authentication token. Requires scope: `none`.
140     * * `view_id: &str` -- A unique identifier of the view to be updated. Either `view_id` or `external_id` is required.
141     * * `external_id: &str` -- A unique identifier of the view set by the developer. Must be unique for all views on a team. Max length of 255 characters. Either `view_id` or `external_id` is required.
142     * * `view: &str` -- A [view object](/reference/surfaces/views). This must be a JSON-encoded string.
143     * * `hash: &str` -- A string that represents view state to protect against possible race conditions.
144     */
145    pub async fn update(
146        &self,
147        view_id: &str,
148        external_id: &str,
149        view: &str,
150        hash: &str,
151    ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
152        let mut query_args: Vec<(String, String)> = Default::default();
153        if !external_id.is_empty() {
154            query_args.push(("external_id".to_string(), external_id.to_string()));
155        }
156        if !hash.is_empty() {
157            query_args.push(("hash".to_string(), hash.to_string()));
158        }
159        if !view.is_empty() {
160            query_args.push(("view".to_string(), view.to_string()));
161        }
162        if !view_id.is_empty() {
163            query_args.push(("view_id".to_string(), view_id.to_string()));
164        }
165        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
166        let url = self.client.url(&format!("/views.update?{}", query_), None);
167        self.client
168            .get(
169                &url,
170                crate::Message {
171                    body: None,
172                    content_type: None,
173                },
174            )
175            .await
176    }
177}