slack_chat_api/chat.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Chat {
5 pub client: Client,
6}
7
8impl Chat {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Chat { client }
12 }
13
14 /**
15 * This function performs a `POST` to the `/chat.delete` endpoint.
16 *
17 * Deletes a message.
18 *
19 * FROM: <https://api.slack.com/methods/chat.delete>
20 *
21 * **Parameters:**
22 *
23 * * `token: &str` -- Authentication token. Requires scope: `chat:write`.
24 */
25 pub async fn delete(
26 &self,
27 ) -> ClientResult<crate::Response<crate::types::ChatDeleteSuccessSchema>> {
28 let url = self.client.url("/chat.delete", None);
29 self.client
30 .post(
31 &url,
32 crate::Message {
33 body: None,
34 content_type: Some("application/x-www-form-urlencoded".to_string()),
35 },
36 )
37 .await
38 }
39 /**
40 * This function performs a `POST` to the `/chat.deleteScheduledMessage` endpoint.
41 *
42 * Deletes a pending scheduled message from the queue.
43 *
44 * FROM: <https://api.slack.com/methods/chat.deleteScheduledMessage>
45 *
46 * **Parameters:**
47 *
48 * * `token: &str` -- Authentication token. Requires scope: `chat:write`.
49 */
50 pub async fn delete_scheduled_message(
51 &self,
52 ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
53 let url = self.client.url("/chat.deleteScheduledMessage", None);
54 self.client
55 .post(
56 &url,
57 crate::Message {
58 body: None,
59 content_type: Some("application/x-www-form-urlencoded".to_string()),
60 },
61 )
62 .await
63 }
64 /**
65 * This function performs a `GET` to the `/chat.getPermalink` endpoint.
66 *
67 * Retrieve a permalink URL for a specific extant message
68 *
69 * FROM: <https://api.slack.com/methods/chat.getPermalink>
70 *
71 * **Parameters:**
72 *
73 * * `token: &str` -- Authentication token. Requires scope: `none`.
74 * * `channel: &str` -- The ID of the conversation or channel containing the message.
75 * * `message_ts: &str` -- A message's `ts` value, uniquely identifying it within a channel.
76 */
77 pub async fn get_permalink(
78 &self,
79 channel: &str,
80 message_ts: &str,
81 ) -> ClientResult<crate::Response<crate::types::ChatGetPermalinkSuccessSchema>> {
82 let mut query_args: Vec<(String, String)> = Default::default();
83 if !channel.is_empty() {
84 query_args.push(("channel".to_string(), channel.to_string()));
85 }
86 if !message_ts.is_empty() {
87 query_args.push(("message_ts".to_string(), message_ts.to_string()));
88 }
89 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
90 let url = self
91 .client
92 .url(&format!("/chat.getPermalink?{}", query_), None);
93 self.client
94 .get(
95 &url,
96 crate::Message {
97 body: None,
98 content_type: None,
99 },
100 )
101 .await
102 }
103 /**
104 * This function performs a `POST` to the `/chat.meMessage` endpoint.
105 *
106 * Share a me message into a channel.
107 *
108 * FROM: <https://api.slack.com/methods/chat.meMessage>
109 *
110 * **Parameters:**
111 *
112 * * `token: &str` -- Authentication token. Requires scope: `chat:write`.
113 */
114 pub async fn me_message(
115 &self,
116 ) -> ClientResult<crate::Response<crate::types::ChatMeMessageSchema>> {
117 let url = self.client.url("/chat.meMessage", None);
118 self.client
119 .post(
120 &url,
121 crate::Message {
122 body: None,
123 content_type: Some("application/x-www-form-urlencoded".to_string()),
124 },
125 )
126 .await
127 }
128 /**
129 * This function performs a `POST` to the `/chat.postEphemeral` endpoint.
130 *
131 * Sends an ephemeral message to a user in a channel.
132 *
133 * FROM: <https://api.slack.com/methods/chat.postEphemeral>
134 *
135 * **Parameters:**
136 *
137 * * `token: &str` -- Authentication token. Requires scope: `chat:write`.
138 */
139 pub async fn post_ephemeral(
140 &self,
141 ) -> ClientResult<crate::Response<crate::types::ChatPostEphemeralSuccessSchema>> {
142 let url = self.client.url("/chat.postEphemeral", None);
143 self.client
144 .post(
145 &url,
146 crate::Message {
147 body: None,
148 content_type: Some("application/x-www-form-urlencoded".to_string()),
149 },
150 )
151 .await
152 }
153 /**
154 * This function performs a `POST` to the `/chat.postMessage` endpoint.
155 *
156 * Sends a message to a channel.
157 *
158 * FROM: <https://api.slack.com/methods/chat.postMessage>
159 *
160 * **Parameters:**
161 *
162 * * `token: &str` -- Authentication token. Requires scope: `chat:write`.
163 */
164 pub async fn post_message(
165 &self,
166 ) -> ClientResult<crate::Response<crate::types::ChatPostMessageSuccessSchema>> {
167 let url = self.client.url("/chat.postMessage", None);
168 self.client
169 .post(
170 &url,
171 crate::Message {
172 body: None,
173 content_type: Some("application/x-www-form-urlencoded".to_string()),
174 },
175 )
176 .await
177 }
178 /**
179 * This function performs a `POST` to the `/chat.scheduleMessage` endpoint.
180 *
181 * Schedules a message to be sent to a channel.
182 *
183 * FROM: <https://api.slack.com/methods/chat.scheduleMessage>
184 *
185 * **Parameters:**
186 *
187 * * `token: &str` -- Authentication token. Requires scope: `chat:write`.
188 */
189 pub async fn schedule_message(
190 &self,
191 ) -> ClientResult<crate::Response<crate::types::ChatScheduleMessageSuccessSchema>> {
192 let url = self.client.url("/chat.scheduleMessage", None);
193 self.client
194 .post(
195 &url,
196 crate::Message {
197 body: None,
198 content_type: Some("application/x-www-form-urlencoded".to_string()),
199 },
200 )
201 .await
202 }
203 /**
204 * This function performs a `POST` to the `/chat.unfurl` endpoint.
205 *
206 * Provide custom unfurl behavior for user-posted URLs
207 *
208 * FROM: <https://api.slack.com/methods/chat.unfurl>
209 *
210 * **Parameters:**
211 *
212 * * `token: &str` -- Authentication token. Requires scope: `links:write`.
213 */
214 pub async fn unfurl(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
215 let url = self.client.url("/chat.unfurl", None);
216 self.client
217 .post(
218 &url,
219 crate::Message {
220 body: None,
221 content_type: Some("application/x-www-form-urlencoded".to_string()),
222 },
223 )
224 .await
225 }
226 /**
227 * This function performs a `POST` to the `/chat.update` endpoint.
228 *
229 * Updates a message.
230 *
231 * FROM: <https://api.slack.com/methods/chat.update>
232 *
233 * **Parameters:**
234 *
235 * * `token: &str` -- Authentication token. Requires scope: `chat:write`.
236 */
237 pub async fn update(
238 &self,
239 ) -> ClientResult<crate::Response<crate::types::ChatUpdateSuccessSchema>> {
240 let url = self.client.url("/chat.update", None);
241 self.client
242 .post(
243 &url,
244 crate::Message {
245 body: None,
246 content_type: Some("application/x-www-form-urlencoded".to_string()),
247 },
248 )
249 .await
250 }
251}