sfr_types/block/rich_text.rs
1//! Rich text block.
2//!
3//! <https://api.slack.com/reference/block-kit/blocks#rich_text>
4
5use crate::BlockId;
6use serde::Serialize;
7
8/// Rich text block.
9///
10/// <https://api.slack.com/reference/block-kit/blocks#rich_text>
11#[derive(Serialize, Debug, Clone)]
12#[serde(rename_all = "snake_case")]
13pub struct RichTextBlock {
14 /// 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).
15 pub elements: Vec<RichTextObject>,
16
17 /// A unique identifier for a block.
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub block_id: Option<BlockId>,
20}
21
22#[allow(clippy::enum_variant_names)]
23/// An element in rich text block.
24///
25/// <https://api.slack.com/reference/block-kit/blocks#rich_text>
26#[derive(Serialize, Debug, Clone)]
27#[serde(tag = "type", rename_all = "snake_case")]
28pub enum RichTextObject {
29 /// Section element: `rich_text_section`.
30 ///
31 /// <https://api.slack.com/reference/block-kit/blocks#rich_text_section>
32 RichTextSection(RichTextSection),
33
34 /// List element: `rich_text_list`.
35 ///
36 /// <https://api.slack.com/reference/block-kit/blocks#rich_text_list>
37 RichTextList(RichTextList),
38
39 /// Preformatted code block element: `rich_text_preformatted`.
40 ///
41 /// <https://api.slack.com/reference/block-kit/blocks#rich_text_preformatted>
42 RichTextPreformatted(RichTextPreformatted),
43
44 /// Quote element: `rich_text_quote`.
45 ///
46 /// <https://api.slack.com/reference/block-kit/blocks#rich_text_quote>
47 RichTextQuote(RichTextQuote),
48}
49
50/// Section element: `rich_text_section`.
51///
52/// <https://api.slack.com/reference/block-kit/blocks#rich_text_section>
53#[derive(Serialize, Debug, Clone)]
54#[serde(rename_all = "snake_case")]
55pub struct RichTextSection {
56 /// An array of [rich text elements](https://api.slack.com/reference/block-kit/blocks#element-types).
57 pub elements: Vec<RichTextElement>,
58}
59
60/// List element: `rich_text_list`.
61///
62/// <https://api.slack.com/reference/block-kit/blocks#rich_text_list>
63#[derive(Serialize, Debug, Clone)]
64#[serde(rename_all = "snake_case")]
65pub struct RichTextList {
66 /// Either `bullet` or `ordered`, the latter meaning a numbered list.
67 pub style: RichTextListStyle,
68
69 /// 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).
70 pub elements: Vec<RichTextSection>,
71
72 /// Number of pixels to indent the list.
73 #[serde(skip_serializing_if = "Option::is_none")]
74 pub indent: Option<u64>,
75
76 /// Number of pixels to offset the list.
77 #[serde(skip_serializing_if = "Option::is_none")]
78 pub offset: Option<u64>,
79
80 /// Number of pixels of border thickness.
81 #[serde(skip_serializing_if = "Option::is_none")]
82 pub border: Option<u64>,
83}
84
85/// The value of the `style` field in [`RichTextList`].
86#[derive(Serialize, Debug, Clone)]
87#[serde(rename_all = "lowercase")]
88pub enum RichTextListStyle {
89 /// `bullet`.
90 Bullet,
91
92 /// `ordered`.
93 Ordered,
94}
95
96/// Preformatted code block element: `rich_text_preformatted`.
97///
98/// <https://api.slack.com/reference/block-kit/blocks#rich_text_preformatted>
99#[derive(Serialize, Debug, Clone)]
100#[serde(rename_all = "snake_case")]
101pub struct RichTextPreformatted {
102 /// An array of [rich text elements](https://api.slack.com/reference/block-kit/blocks#element-types).
103 pub elements: Vec<RichTextElement>,
104
105 /// Number of pixels of border thickness.
106 #[serde(skip_serializing_if = "Option::is_none")]
107 pub border: Option<u64>,
108}
109
110/// Quote element: `rich_text_quote`.
111///
112/// <https://api.slack.com/reference/block-kit/blocks#rich_text_quote>
113#[derive(Serialize, Debug, Clone)]
114#[serde(rename_all = "snake_case")]
115pub struct RichTextQuote {
116 /// An array of [rich text elements](https://api.slack.com/reference/block-kit/blocks#element-types).
117 pub elements: Vec<RichTextElement>,
118
119 /// Number of pixels of border thickness.
120 #[serde(skip_serializing_if = "Option::is_none")]
121 pub border: Option<u64>,
122}
123
124/// Rich text element types.
125///
126/// <https://api.slack.com/reference/block-kit/blocks#element-types>
127#[derive(Serialize, Debug, Clone)]
128#[serde(tag = "type", rename_all = "snake_case")]
129pub enum RichTextElement {
130 /// The following are the properties of the `broadcast` object type in the `elements` array.
131 Broadcast(RichTextElementBroadcast),
132
133 /// The following are the properties of the `color` object type in the `elements` array.
134 Color(RichTextElementColor),
135
136 /// The following are the properties of the `channel` object type in the `elements` array.
137 Channel(RichTextElementChannel),
138
139 /// The following are the properties of the `date` object type in the `elements` array.
140 Date(RichTextElementDate),
141
142 /// The following are the properties of the `emoji` object type in the `elements` array.
143 Emoji(RichTextElementEmoji),
144
145 /// The following are the properties of the `link` object type in the `elements` array.
146 Link(RichTextElementLink),
147
148 /// The following are the properties of the `text` object type in the `elements` array.
149 Text(RichTextElementText),
150
151 /// The following are the properties of the `user` object type in the `elements` array.
152 User(RichTextElementUser),
153
154 /// The following are the properties of the `usergroup` object type in the `elements` array.
155 Usergroup(RichTextElementUsergroup),
156}
157
158/// The following are the properties of the `broadcast` object type in the `elements` array.
159#[derive(Serialize, Debug, Clone)]
160#[serde(rename_all = "snake_case")]
161pub struct RichTextElementBroadcast {
162 /// The range of the broadcast; value can be `here`, `channel`, or `everyone`.
163 pub range: RichTextElementBroadcastRange,
164}
165
166/// The range of the broadcast; value can be `here`, `channel`, or `everyone`.
167#[derive(Serialize, Debug, Clone)]
168#[serde(rename_all = "lowercase")]
169pub enum RichTextElementBroadcastRange {
170 /// `here`.
171 Here,
172
173 /// `channel`.
174 Channel,
175
176 /// `everyone`.
177 Everyone,
178}
179
180/// The following are the properties of the `color` object type in the `elements` array.
181#[derive(Serialize, Debug, Clone)]
182#[serde(rename_all = "snake_case")]
183pub struct RichTextElementColor {
184 /// The hex value for the color.
185 pub value: String,
186}
187
188/// The following are the properties of the `channel` object type in the `elements` array.
189#[derive(Serialize, Debug, Clone)]
190#[serde(rename_all = "snake_case")]
191pub struct RichTextElementChannel {
192 /// The ID of the channel to be mentioned.
193 pub channel_id: String,
194
195 /// An object of six optional boolean properties that dictate style: `bold`, `italic`, `strike`, `highlight`, `client_highlight`, and `unlink`.
196 #[serde(skip_serializing_if = "Option::is_none")]
197 pub style: Option<RichTextStyle2>,
198}
199
200/// An object of six optional boolean properties that dictate style: `bold`, `italic`, `strike`, `highlight`, `client_highlight`, and `unlink`.
201///
202/// like <https://github.com/slackapi/node-slack-sdk/blob/220da721c04d37dacf06c4b6c6630dc3b451b583/packages/types/src/block-kit/extensions.ts#L82>
203#[derive(Serialize, Debug, Clone)]
204#[serde(rename_all = "snake_case")]
205pub struct RichTextStyle2 {
206 /// When `true`, boldens the text in this element. Defaults to `false`.
207 #[serde(skip_serializing_if = "Option::is_none")]
208 pub bold: Option<bool>,
209
210 /// When `true`, italicizes the text in this element. Defaults to `false`.
211 #[serde(skip_serializing_if = "Option::is_none")]
212 pub italic: Option<bool>,
213
214 /// When `true`, strikes through the text in this element. Defaults to `false`.
215 #[serde(skip_serializing_if = "Option::is_none")]
216 pub strike: Option<bool>,
217
218 /// Defaults to `false`.
219 #[serde(skip_serializing_if = "Option::is_none")]
220 pub highlight: Option<bool>,
221
222 /// Defaults to `false`.
223 #[serde(skip_serializing_if = "Option::is_none")]
224 pub client_highlight: Option<bool>,
225
226 /// Defaults to `false`.
227 #[serde(skip_serializing_if = "Option::is_none")]
228 pub unlink: Option<bool>,
229}
230
231/// The following are the properties of the `date` object type in the `elements` array.
232#[derive(Serialize, Debug, Clone)]
233#[serde(rename_all = "snake_case")]
234pub struct RichTextElementDate {
235 /// A Unix timestamp for the date to be displayed in seconds.
236 pub timestamp: u64,
237
238 /// A template string containing curly-brace-enclosed tokens to substitute your provided `timestamp`.
239 pub format: String,
240
241 /// URL to link the entire `format` string to.
242 #[serde(skip_serializing_if = "Option::is_none")]
243 pub url: Option<String>,
244
245 /// Text to display in place of the date should parsing, formatting or displaying fail.
246 pub fallback: Option<String>,
247}
248
249/// The following are the properties of the `emoji` object type in the `elements` array.
250#[derive(Serialize, Debug, Clone)]
251#[serde(rename_all = "snake_case")]
252pub struct RichTextElementEmoji {
253 /// The name of the emoji; i.e. "wave" or "wave::skin-tone-2".
254 pub name: String,
255}
256
257/// The following are the properties of the `link` object type in the `elements` array.
258#[derive(Serialize, Debug, Clone)]
259#[serde(rename_all = "snake_case")]
260pub struct RichTextElementLink {
261 /// The link's url.
262 pub url: String,
263
264 /// The text shown to the user (instead of the url).
265 #[serde(skip_serializing_if = "Option::is_none")]
266 pub text: Option<String>,
267
268 /// Indicates whether the link is safe.
269 #[serde(skip_serializing_if = "Option::is_none", rename = "unsafe")]
270 pub unsafe_: Option<bool>,
271
272 /// An object containing four boolean properties: bold, italic, strike, and code.
273 #[serde(skip_serializing_if = "Option::is_none")]
274 pub style: Option<RichTextStyle>,
275}
276
277/// An object containing four boolean properties: `bold`, `italic`, `strike`, and `code`.
278///
279/// <https://github.com/slackapi/node-slack-sdk/blob/220da721c04d37dacf06c4b6c6630dc3b451b583/packages/types/src/block-kit/extensions.ts#L82>
280#[derive(Serialize, Debug, Clone)]
281#[serde(rename_all = "snake_case")]
282pub struct RichTextStyle {
283 /// When `true`, boldens the text in this element. Defaults to `false`.
284 #[serde(skip_serializing_if = "Option::is_none")]
285 pub bold: Option<bool>,
286
287 /// When `true`, the text is preformatted in an inline code style. Defaults to `false.
288 #[serde(skip_serializing_if = "Option::is_none")]
289 pub code: Option<bool>,
290
291 /// When `true`, italicizes the text in this element. Defaults to `false`.
292 #[serde(skip_serializing_if = "Option::is_none")]
293 pub italic: Option<bool>,
294
295 /// When `true`, strikes through the text in this element. Defaults to `false`.
296 #[serde(skip_serializing_if = "Option::is_none")]
297 pub strike: Option<bool>,
298}
299
300/// The following are the properties of the `text` object type in the `elements` array.
301#[derive(Serialize, Debug, Clone)]
302#[serde(rename_all = "snake_case")]
303pub struct RichTextElementText {
304 /// The text shown to the user.
305 pub text: String,
306
307 /// An object containing four boolean fields, none of which are required: `bold`, `italic`, `strike`, and `code`.
308 #[serde(skip_serializing_if = "Option::is_none")]
309 pub style: Option<RichTextStyle>,
310}
311
312/// The following are the properties of the `user` object type in the `elements` array.
313#[derive(Serialize, Debug, Clone)]
314#[serde(rename_all = "snake_case")]
315pub struct RichTextElementUser {
316 /// The ID of the user to be mentioned.
317 pub user_id: String,
318
319 /// An object of six optional boolean properties that dictate style: `bold`, `italic`, `strike`, `highlight`, `client_highlight`, and `unlink`.
320 #[serde(skip_serializing_if = "Option::is_none")]
321 pub style: Option<RichTextStyle2>,
322}
323
324/// The following are the properties of the `usergroup` object type in the `elements` array.
325#[derive(Serialize, Debug, Clone)]
326#[serde(rename_all = "snake_case")]
327pub struct RichTextElementUsergroup {
328 /// The ID of the user group to be mentioned.
329 pub usergroup_id: String,
330
331 /// An object of six optional boolean properties that dictate style: `bold`, `italic`, `strike`, `highlight`, `client_highlight`, and `unlink`.
332 #[serde(skip_serializing_if = "Option::is_none")]
333 pub style: Option<RichTextStyle2>,
334}