sfr_types/object.rs
1//! The type that represents a composition object.
2//!
3//! <https://api.slack.com/reference/block-kit/composition-objects>
4
5use crate::ButtonStyle;
6use serde::Serialize;
7
8/// The type that represents a text object.
9///
10/// Defines an object containing some text.
11///
12/// <https://api.slack.com/reference/block-kit/composition-objects#text>
13#[derive(Serialize, Debug, Clone)]
14#[serde(rename_all = "snake_case", tag = "type")]
15pub enum TextObject {
16 /// The `plain_text`.
17 PlainText(PlainTextObject),
18
19 /// The `mrkdwn`.
20 #[serde(rename = "mrkdwn")]
21 Markdown(MarkdownTextObject),
22}
23
24/// A type that represents `plain_text` in [`TextObject`].
25#[derive(Serialize, Debug, Clone)]
26#[serde(rename_all = "snake_case")]
27pub struct PlainTextObject {
28 /// The text for the block.
29 pub text: String,
30
31 /// Indicates whether emojis in a text field should be escaped into the colon emoji format.
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub emoji: Option<bool>,
34}
35
36/// A type that represents `mrkdwn` in [`TextObject`].
37#[derive(Serialize, Debug, Clone)]
38#[serde(rename_all = "snake_case")]
39pub struct MarkdownTextObject {
40 /// The text for the block.
41 pub text: String,
42
43 /// When set to `false` (as is default) URLs will be auto-converted into links, conversation names will be link-ified, and certain mentions will be [automatically parsed](https://api.slack.com/reference/surfaces/formatting#automatic-parsing).
44 #[serde(skip_serializing_if = "Option::is_none")]
45 pub verbatim: Option<bool>,
46}
47
48/// The type that represents a confirmation dialog object.
49///
50/// Defines a dialog that adds a confirmation step to interactive elements.
51///
52/// <https://api.slack.com/reference/block-kit/composition-objects#confirm>
53#[derive(Serialize, Debug, Clone)]
54#[serde(rename_all = "snake_case")]
55pub struct ConfirmObect {
56 /// A plain_text text object that defines the dialog's title.
57 pub title: PlainTextObject,
58
59 /// A plain_text text object that defines the explanatory text that appears in the confirm dialog.
60 pub text: TextObject,
61
62 /// A plain_text text object to define the text of the button that confirms the action.
63 pub confirm: PlainTextObject,
64
65 /// A plain_text text object to define the text of the button that cancels the action.
66 pub deny: PlainTextObject,
67
68 /// Defines the color scheme applied to the confirm button.
69 #[serde(skip_serializing_if = "ButtonStyle::is_default")]
70 pub style: ButtonStyle,
71}
72
73// TODO: not implemented.
74// #[derive(Serialize, Debug, Clone)]
75// #[serde(rename_all = "snake_case")]
76// pub struct OptionObject;
77//
78// #[derive(Serialize, Debug, Clone)]
79// #[serde(rename_all = "snake_case")]
80// pub struct OptionGroupObject;