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
//! The type that represents a composition object.
//!
//! <https://api.slack.com/reference/block-kit/composition-objects>

use crate::ButtonStyle;
use serde::Serialize;

/// The type that represents a text object.
///
/// Defines an object containing some text.
///
/// <https://api.slack.com/reference/block-kit/composition-objects#text>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum TextObject {
    /// The `plain_text`.
    PlainText(PlainTextObject),

    /// The `mrkdwn`.
    #[serde(rename = "mrkdwn")]
    Markdown(MarkdownTextObject),
}

/// A type that represents `plain_text` in [`TextObject`].
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct PlainTextObject {
    /// The text for the block.
    pub text: String,

    /// Indicates whether emojis in a text field should be escaped into the colon emoji format.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emoji: Option<bool>,
}

/// A type that represents `mrkdwn` in [`TextObject`].
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct MarkdownTextObject {
    /// The text for the block.
    pub text: String,

    /// 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).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub verbatim: Option<bool>,
}

/// The type that represents a confirmation dialog object.
///
/// Defines a dialog that adds a confirmation step to interactive elements.
///
/// <https://api.slack.com/reference/block-kit/composition-objects#confirm>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct ConfirmObect {
    /// A plain_text text object that defines the dialog's title.
    pub title: PlainTextObject,

    /// A plain_text text object that defines the explanatory text that appears in the confirm dialog.
    pub text: TextObject,

    /// A plain_text text object to define the text of the button that confirms the action.
    pub confirm: PlainTextObject,

    /// A plain_text text object to define the text of the button that cancels the action.
    pub deny: PlainTextObject,

    /// Defines the color scheme applied to the confirm button.
    #[serde(skip_serializing_if = "ButtonStyle::is_default")]
    pub style: ButtonStyle,
}

// TODO: not implemented.
// #[derive(Serialize, Debug, Clone)]
// #[serde(rename_all = "snake_case")]
// pub struct OptionObject;
//
// #[derive(Serialize, Debug, Clone)]
// #[serde(rename_all = "snake_case")]
// pub struct OptionGroupObject;