lib_client_slack/
types.rs

1use serde::{Deserialize, Serialize};
2
3use crate::blocks::Block;
4
5/// Slack API response wrapper.
6#[derive(Debug, Clone, Deserialize)]
7pub struct SlackResponse<T> {
8    pub ok: bool,
9    #[serde(flatten)]
10    pub data: Option<T>,
11    pub error: Option<String>,
12}
13
14/// Message.
15#[derive(Debug, Clone, Deserialize)]
16pub struct Message {
17    pub ts: String,
18    pub text: Option<String>,
19    pub user: Option<String>,
20    #[serde(rename = "type")]
21    pub message_type: String,
22    pub thread_ts: Option<String>,
23}
24
25/// Channel.
26#[derive(Debug, Clone, Deserialize)]
27pub struct Channel {
28    pub id: String,
29    pub name: String,
30    pub is_channel: Option<bool>,
31    pub is_private: Option<bool>,
32    pub is_archived: Option<bool>,
33    pub is_member: Option<bool>,
34    pub topic: Option<Topic>,
35    pub purpose: Option<Purpose>,
36    pub num_members: Option<u32>,
37}
38
39#[derive(Debug, Clone, Deserialize)]
40pub struct Topic {
41    pub value: String,
42}
43
44#[derive(Debug, Clone, Deserialize)]
45pub struct Purpose {
46    pub value: String,
47}
48
49/// User.
50#[derive(Debug, Clone, Deserialize)]
51pub struct User {
52    pub id: String,
53    pub name: String,
54    pub real_name: Option<String>,
55    pub profile: Option<UserProfile>,
56    pub is_bot: Option<bool>,
57    pub is_admin: Option<bool>,
58    pub deleted: Option<bool>,
59}
60
61#[derive(Debug, Clone, Deserialize)]
62pub struct UserProfile {
63    pub display_name: Option<String>,
64    pub email: Option<String>,
65    pub image_72: Option<String>,
66    pub image_192: Option<String>,
67}
68
69/// File.
70#[derive(Debug, Clone, Deserialize)]
71pub struct File {
72    pub id: String,
73    pub name: String,
74    pub title: String,
75    pub mimetype: String,
76    pub filetype: String,
77    pub size: u64,
78    pub url_private: Option<String>,
79    pub url_private_download: Option<String>,
80    pub permalink: Option<String>,
81}
82
83/// Post message request.
84#[derive(Debug, Clone, Serialize)]
85pub struct PostMessageRequest {
86    pub channel: String,
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub text: Option<String>,
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub blocks: Option<Vec<Block>>,
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub thread_ts: Option<String>,
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub reply_broadcast: Option<bool>,
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub unfurl_links: Option<bool>,
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub unfurl_media: Option<bool>,
99}
100
101impl PostMessageRequest {
102    pub fn new(channel: impl Into<String>) -> Self {
103        Self {
104            channel: channel.into(),
105            text: None,
106            blocks: None,
107            thread_ts: None,
108            reply_broadcast: None,
109            unfurl_links: None,
110            unfurl_media: None,
111        }
112    }
113
114    pub fn text(mut self, text: impl Into<String>) -> Self {
115        self.text = Some(text.into());
116        self
117    }
118
119    pub fn blocks(mut self, blocks: Vec<Block>) -> Self {
120        self.blocks = Some(blocks);
121        self
122    }
123
124    pub fn thread_ts(mut self, ts: impl Into<String>) -> Self {
125        self.thread_ts = Some(ts.into());
126        self
127    }
128}
129
130/// Update message request.
131#[derive(Debug, Clone, Serialize)]
132pub struct UpdateMessageRequest {
133    pub channel: String,
134    pub ts: String,
135    #[serde(skip_serializing_if = "Option::is_none")]
136    pub text: Option<String>,
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub blocks: Option<Vec<Block>>,
139}
140
141impl UpdateMessageRequest {
142    pub fn new(channel: impl Into<String>, ts: impl Into<String>) -> Self {
143        Self {
144            channel: channel.into(),
145            ts: ts.into(),
146            text: None,
147            blocks: None,
148        }
149    }
150
151    pub fn text(mut self, text: impl Into<String>) -> Self {
152        self.text = Some(text.into());
153        self
154    }
155
156    pub fn blocks(mut self, blocks: Vec<Block>) -> Self {
157        self.blocks = Some(blocks);
158        self
159    }
160}
161
162/// Message response.
163#[derive(Debug, Clone, Deserialize)]
164pub struct MessageResponse {
165    pub channel: String,
166    pub ts: String,
167    pub message: Option<Message>,
168}
169
170/// Channels list response.
171#[derive(Debug, Clone, Deserialize)]
172pub struct ChannelsListResponse {
173    pub channels: Vec<Channel>,
174    pub response_metadata: Option<ResponseMetadata>,
175}
176
177/// Users list response.
178#[derive(Debug, Clone, Deserialize)]
179pub struct UsersListResponse {
180    pub members: Vec<User>,
181    pub response_metadata: Option<ResponseMetadata>,
182}
183
184/// Response metadata for pagination.
185#[derive(Debug, Clone, Deserialize)]
186pub struct ResponseMetadata {
187    pub next_cursor: Option<String>,
188}
189
190/// File upload response.
191#[derive(Debug, Clone, Deserialize)]
192pub struct FileUploadResponse {
193    pub file: File,
194}
195
196/// Reaction request.
197#[derive(Debug, Clone, Serialize)]
198pub struct ReactionRequest {
199    pub channel: String,
200    pub timestamp: String,
201    pub name: String,
202}
203
204impl ReactionRequest {
205    pub fn new(
206        channel: impl Into<String>,
207        timestamp: impl Into<String>,
208        emoji: impl Into<String>,
209    ) -> Self {
210        Self {
211            channel: channel.into(),
212            timestamp: timestamp.into(),
213            name: emoji.into(),
214        }
215    }
216}