slack_rust/block/
block_object.rs

1//! Composition objects can be used inside of block elements and certain message payload fields.   
2//! See: <https://api.slack.com/reference/block-kit/composition-objects>
3
4use serde::{Deserialize, Serialize};
5use serde_with::skip_serializing_none;
6
7/// An object containing some text, formatted either as plain_text or using mrkdwn, our proprietary contribution to the much beloved Markdown standard.  
8/// See: <https://api.slack.com/reference/block-kit/composition-objects#text>
9#[skip_serializing_none]
10#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
11pub struct TextBlockObject {
12    #[serde(rename = "type")]
13    pub type_filed: TextBlockType,
14    pub text: String,
15    pub emoji: Option<bool>,
16    pub verbatim: Option<bool>,
17}
18
19impl TextBlockObject {
20    pub fn builder(text_block_type: TextBlockType, text: String) -> TextBlockObjectBuilder {
21        TextBlockObjectBuilder::new(text_block_type, text)
22    }
23}
24
25#[derive(Debug, Default)]
26pub struct TextBlockObjectBuilder {
27    pub type_filed: TextBlockType,
28    pub text: String,
29    pub emoji: Option<bool>,
30    pub verbatim: Option<bool>,
31}
32
33impl TextBlockObjectBuilder {
34    pub fn new(text_block_type: TextBlockType, text: String) -> TextBlockObjectBuilder {
35        TextBlockObjectBuilder {
36            type_filed: text_block_type,
37            text,
38            ..Default::default()
39        }
40    }
41    pub fn emoji(mut self, emoji: bool) -> TextBlockObjectBuilder {
42        self.emoji = Some(emoji);
43        self
44    }
45    pub fn verbatim(mut self, verbatim: bool) -> TextBlockObjectBuilder {
46        self.verbatim = Some(verbatim);
47        self
48    }
49    pub fn build(self) -> TextBlockObject {
50        TextBlockObject {
51            type_filed: self.type_filed,
52            text: self.text,
53            emoji: self.emoji,
54            verbatim: self.verbatim,
55        }
56    }
57}
58
59#[derive(Deserialize, Serialize, Debug, PartialEq)]
60#[serde(rename_all = "snake_case")]
61pub enum TextBlockType {
62    PlainText,
63    Mrkdwn,
64    #[serde(skip)]
65    None,
66}
67
68impl Default for TextBlockType {
69    fn default() -> Self {
70        TextBlockType::None
71    }
72}
73
74/// An object that represents a single selectable item in a select menu, multi-select menu, checkbox group, radio button group, or overflow menu.  
75/// See: <https://api.slack.com/reference/block-kit/composition-objects#option>
76#[skip_serializing_none]
77#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
78pub struct OptionBlockObject {
79    pub text: TextBlockObject,
80    pub value: Option<String>,
81    pub description: Option<TextBlockObject>,
82    pub url: Option<String>,
83}
84
85impl OptionBlockObject {
86    pub fn builder(text: TextBlockObject) -> OptionBlockObjectBuilder {
87        OptionBlockObjectBuilder::new(text)
88    }
89}
90
91#[derive(Debug, Default)]
92pub struct OptionBlockObjectBuilder {
93    pub text: TextBlockObject,
94    pub value: Option<String>,
95    pub description: Option<TextBlockObject>,
96    pub url: Option<String>,
97}
98
99impl OptionBlockObjectBuilder {
100    pub fn new(text: TextBlockObject) -> OptionBlockObjectBuilder {
101        OptionBlockObjectBuilder {
102            text,
103            ..Default::default()
104        }
105    }
106    pub fn value(mut self, value: String) -> OptionBlockObjectBuilder {
107        self.value = Some(value);
108        self
109    }
110    pub fn description(mut self, description: TextBlockObject) -> OptionBlockObjectBuilder {
111        self.description = Some(description);
112        self
113    }
114    pub fn url(mut self, url: String) -> OptionBlockObjectBuilder {
115        self.url = Some(url);
116        self
117    }
118    pub fn build(self) -> OptionBlockObject {
119        OptionBlockObject {
120            text: self.text,
121            value: self.value,
122            description: self.description,
123            url: self.url,
124        }
125    }
126}
127
128#[skip_serializing_none]
129#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
130pub struct OptionGroupBlockObject {
131    pub label: Option<TextBlockObject>,
132    pub options: Option<Vec<OptionBlockObject>>,
133}
134
135#[skip_serializing_none]
136#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
137pub struct ConfirmationBlockObject {
138    pub title: TextBlockObject,
139    pub text: TextBlockObject,
140    pub confirm: TextBlockObject,
141    pub deny: TextBlockObject,
142    pub style: Option<String>,
143}
144
145impl ConfirmationBlockObject {
146    pub fn builder(
147        title: TextBlockObject,
148        text: TextBlockObject,
149        confirm: TextBlockObject,
150        deny: TextBlockObject,
151    ) -> ConfirmationBlockObjectBuilder {
152        ConfirmationBlockObjectBuilder::new(title, text, confirm, deny)
153    }
154}
155
156#[derive(Debug, Default)]
157pub struct ConfirmationBlockObjectBuilder {
158    pub title: TextBlockObject,
159    pub text: TextBlockObject,
160    pub confirm: TextBlockObject,
161    pub deny: TextBlockObject,
162    pub style: Option<String>,
163}
164
165impl ConfirmationBlockObjectBuilder {
166    pub fn new(
167        title: TextBlockObject,
168        text: TextBlockObject,
169        confirm: TextBlockObject,
170        deny: TextBlockObject,
171    ) -> ConfirmationBlockObjectBuilder {
172        ConfirmationBlockObjectBuilder {
173            title,
174            text,
175            confirm,
176            deny,
177            ..Default::default()
178        }
179    }
180    pub fn style(mut self, style: String) -> ConfirmationBlockObjectBuilder {
181        self.style = Some(style);
182        self
183    }
184    pub fn build(self) -> ConfirmationBlockObject {
185        ConfirmationBlockObject {
186            title: self.title,
187            text: self.text,
188            confirm: self.confirm,
189            deny: self.deny,
190            style: self.style,
191        }
192    }
193}
194
195#[skip_serializing_none]
196#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
197pub struct DispatchActionConfig {
198    pub trigger_actions_on: Option<Vec<String>>,
199}
200
201#[skip_serializing_none]
202#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
203pub struct SelectBlockElementFilter {
204    pub include: Option<Vec<String>>,
205    pub exclude_external_shared_channel: Option<bool>,
206    pub exclude_bot_users: Option<bool>,
207}