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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
//! Rich text block.
//!
//! <https://api.slack.com/reference/block-kit/blocks#rich_text>

use crate::BlockId;
use serde::Serialize;

/// Rich text block.
///
/// <https://api.slack.com/reference/block-kit/blocks#rich_text>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextBlock {
    /// An array of rich text objects - [`rich_text_section`](https://api.slack.com/reference/block-kit/blocks#rich_text_section), [`rich_text_list`](https://api.slack.com/reference/block-kit/blocks#rich_text_list), [`rich_text_preformatted`](https://api.slack.com/reference/block-kit/blocks#rich_text_preformatted), and [`rich_text_quote`](https://api.slack.com/reference/block-kit/blocks#rich_text_quote).
    pub elements: Vec<RichTextObject>,

    /// A unique identifier for a block.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub block_id: Option<BlockId>,
}

#[allow(clippy::enum_variant_names)]
/// An element in rich text block.
///
/// <https://api.slack.com/reference/block-kit/blocks#rich_text>
#[derive(Serialize, Debug, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RichTextObject {
    /// Section element: `rich_text_section`.
    ///
    /// <https://api.slack.com/reference/block-kit/blocks#rich_text_section>
    RichTextSection(RichTextSection),

    /// List element: `rich_text_list`.
    ///
    /// <https://api.slack.com/reference/block-kit/blocks#rich_text_list>
    RichTextList(RichTextList),

    /// Preformatted code block element: `rich_text_preformatted`.
    ///
    /// <https://api.slack.com/reference/block-kit/blocks#rich_text_preformatted>
    RichTextPreformatted(RichTextPreformatted),

    /// Quote element: `rich_text_quote`.
    ///
    /// <https://api.slack.com/reference/block-kit/blocks#rich_text_quote>
    RichTextQuote(RichTextQuote),
}

/// Section element: `rich_text_section`.
///
/// <https://api.slack.com/reference/block-kit/blocks#rich_text_section>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextSection {
    /// An array of [rich text elements](https://api.slack.com/reference/block-kit/blocks#element-types).
    pub elements: Vec<RichTextElement>,
}

/// List element: `rich_text_list`.
///
/// <https://api.slack.com/reference/block-kit/blocks#rich_text_list>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextList {
    /// Either `bullet` or `ordered`, the latter meaning a numbered list.
    pub style: RichTextListStyle,

    /// An array of [`rich_text_section`](https://api.slack.com/reference/block-kit/blocks#rich_text_section) objects containing two properties: type, which is "rich_text_section", and elements, which is an array of [rich text element objects](https://api.slack.com/reference/block-kit/blocks#element-types).
    pub elements: Vec<RichTextSection>,

    /// Number of pixels to indent the list.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub indent: Option<u64>,

    /// Number of pixels to offset the list.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<u64>,

    /// Number of pixels of border thickness.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub border: Option<u64>,
}

/// The value of the `style` field in [`RichTextList`].
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "lowercase")]
pub enum RichTextListStyle {
    /// `bullet`.
    Bullet,

    /// `ordered`.
    Ordered,
}

/// Preformatted code block element: `rich_text_preformatted`.
///
/// <https://api.slack.com/reference/block-kit/blocks#rich_text_preformatted>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextPreformatted {
    /// An array of [rich text elements](https://api.slack.com/reference/block-kit/blocks#element-types).
    pub elements: Vec<RichTextElement>,

    /// Number of pixels of border thickness.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub border: Option<u64>,
}

/// Quote element: `rich_text_quote`.
///
/// <https://api.slack.com/reference/block-kit/blocks#rich_text_quote>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextQuote {
    /// An array of [rich text elements](https://api.slack.com/reference/block-kit/blocks#element-types).
    pub elements: Vec<RichTextElement>,

    /// Number of pixels of border thickness.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub border: Option<u64>,
}

/// Rich text element types.
///
/// <https://api.slack.com/reference/block-kit/blocks#element-types>
#[derive(Serialize, Debug, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RichTextElement {
    /// The following are the properties of the `broadcast` object type in the `elements` array.
    Broadcast(RichTextElementBroadcast),

    /// The following are the properties of the `color` object type in the `elements` array.
    Color(RichTextElementColor),

    /// The following are the properties of the `channel` object type in the `elements` array.
    Channel(RichTextElementChannel),

    /// The following are the properties of the `date` object type in the `elements` array.
    Date(RichTextElementDate),

    /// The following are the properties of the `emoji` object type in the `elements` array.
    Emoji(RichTextElementEmoji),

    /// The following are the properties of the `link` object type in the `elements` array.
    Link(RichTextElementLink),

    /// The following are the properties of the `text` object type in the `elements` array.
    Text(RichTextElementText),

    /// The following are the properties of the `user` object type in the `elements` array.
    User(RichTextElementUser),

    /// The following are the properties of the `usergroup` object type in the `elements` array.
    Usergroup(RichTextElementUsergroup),
}

/// The following are the properties of the `broadcast` object type in the `elements` array.
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextElementBroadcast {
    /// The range of the broadcast; value can be `here`, `channel`, or `everyone`.
    pub range: RichTextElementBroadcastRange,
}

/// The range of the broadcast; value can be `here`, `channel`, or `everyone`.
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "lowercase")]
pub enum RichTextElementBroadcastRange {
    /// `here`.
    Here,

    /// `channel`.
    Channel,

    /// `everyone`.
    Everyone,
}

/// The following are the properties of the `color` object type in the `elements` array.
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextElementColor {
    /// The hex value for the color.
    pub value: String,
}

/// The following are the properties of the `channel` object type in the `elements` array.
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextElementChannel {
    /// The ID of the channel to be mentioned.
    pub channel_id: String,

    /// An object of six optional boolean properties that dictate style: `bold`, `italic`, `strike`, `highlight`, `client_highlight`, and `unlink`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub style: Option<RichTextStyle2>,
}

/// An object of six optional boolean properties that dictate style: `bold`, `italic`, `strike`, `highlight`, `client_highlight`, and `unlink`.
///
/// like <https://github.com/slackapi/node-slack-sdk/blob/220da721c04d37dacf06c4b6c6630dc3b451b583/packages/types/src/block-kit/extensions.ts#L82>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextStyle2 {
    /// When `true`, boldens the text in this element. Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bold: Option<bool>,

    /// When `true`, italicizes the text in this element. Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub italic: Option<bool>,

    /// When `true`, strikes through the text in this element. Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub strike: Option<bool>,

    /// Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub highlight: Option<bool>,

    /// Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub client_highlight: Option<bool>,

    /// Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub unlink: Option<bool>,
}

/// The following are the properties of the `date` object type in the `elements` array.
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextElementDate {
    /// A Unix timestamp for the date to be displayed in seconds.
    pub timestamp: u64,

    /// A template string containing curly-brace-enclosed tokens to substitute your provided `timestamp`.
    pub format: String,

    /// URL to link the entire `format` string to.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,

    /// Text to display in place of the date should parsing, formatting or displaying fail.
    pub fallback: Option<String>,
}

/// The following are the properties of the `emoji` object type in the `elements` array.
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextElementEmoji {
    /// The name of the emoji; i.e. "wave" or "wave::skin-tone-2".
    pub name: String,
}

/// The following are the properties of the `link` object type in the `elements` array.
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextElementLink {
    /// The link's url.
    pub url: String,

    /// The text shown to the user (instead of the url).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub text: Option<String>,

    /// Indicates whether the link is safe.
    #[serde(skip_serializing_if = "Option::is_none", rename = "unsafe")]
    pub unsafe_: Option<bool>,

    /// An object containing four boolean properties: bold, italic, strike, and code.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub style: Option<RichTextStyle>,
}

/// An object containing four boolean properties: `bold`, `italic`, `strike`, and `code`.
///
/// <https://github.com/slackapi/node-slack-sdk/blob/220da721c04d37dacf06c4b6c6630dc3b451b583/packages/types/src/block-kit/extensions.ts#L82>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextStyle {
    /// When `true`, boldens the text in this element. Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bold: Option<bool>,

    /// When `true`, the text is preformatted in an inline code style. Defaults to `false.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub code: Option<bool>,

    /// When `true`, italicizes the text in this element. Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub italic: Option<bool>,

    /// When `true`, strikes through the text in this element. Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub strike: Option<bool>,
}

/// The following are the properties of the `text` object type in the `elements` array.
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextElementText {
    /// The text shown to the user.
    pub text: String,

    /// An object containing four boolean fields, none of which are required: `bold`, `italic`, `strike`, and `code`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub style: Option<RichTextStyle>,
}

/// The following are the properties of the `user` object type in the `elements` array.
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextElementUser {
    /// The ID of the user to be mentioned.
    pub user_id: String,

    /// An object of six optional boolean properties that dictate style: `bold`, `italic`, `strike`, `highlight`, `client_highlight`, and `unlink`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub style: Option<RichTextStyle2>,
}

/// The following are the properties of the `usergroup` object type in the `elements` array.
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RichTextElementUsergroup {
    /// The ID of the user group to be mentioned.
    pub usergroup_id: String,

    /// An object of six optional boolean properties that dictate style: `bold`, `italic`, `strike`, `highlight`, `client_highlight`, and `unlink`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub style: Option<RichTextStyle2>,
}