slack_messaging/blocks/
mod.rs1use serde::Serialize;
2
3pub mod builders;
5pub mod elements;
7pub mod rich_text;
9pub mod table;
11pub mod data_visualization;
13pub mod data_table;
15
16mod actions;
17mod alert;
18mod card;
19mod carousel;
20mod container;
21mod context;
22mod context_actions;
23mod divider;
24mod file;
25mod header;
26mod image;
27mod input;
28mod markdown;
29mod plan;
30mod section;
31mod task_card;
32mod video;
33
34pub use actions::{Actions, ActionsElement};
35pub use alert::{Alert, AlertLevel};
36pub use card::Card;
37pub use carousel::Carousel;
38pub use container::{Container, ContainerChildBlock, ContainerWidth};
39pub use context::{Context, ContextElement};
40pub use context_actions::{ContextActions, ContextActionsElement};
41pub use data_table::DataTable;
42pub use data_visualization::DataVisualization;
43pub use divider::Divider;
44pub use file::{File, FileSource};
45pub use header::Header;
46pub use image::Image;
47pub use input::{Input, InputElement};
48pub use markdown::Markdown;
49pub use plan::Plan;
50pub use rich_text::RichText;
51pub use section::{Accessory, Section};
52pub use table::Table;
53pub use task_card::{TaskCard, TaskStatus};
54pub use video::Video;
55
56#[derive(Debug, Clone, Serialize, PartialEq)]
58#[serde(untagged)]
59pub enum Block {
60 Actions(Box<Actions>),
62
63 Alert(Box<Alert>),
65
66 Card(Box<Card>),
69
70 Carousel(Box<Carousel>),
73
74 Context(Box<Context>),
76
77 ContextActions(Box<ContextActions>),
79
80 DataTable(Box<DataTable>),
82
83 DataVisualization(Box<DataVisualization>),
87
88 Divider(Box<Divider>),
90
91 File(Box<File>),
93
94 Header(Box<Header>),
96
97 Image(Box<Image>),
99
100 Input(Box<Input>),
102
103 Markdown(Box<Markdown>),
105
106 Plan(Box<Plan>),
108
109 RichText(Box<RichText>),
111
112 Section(Box<Section>),
114
115 Table(Box<Table>),
117
118 TaskCard(Box<TaskCard>),
121
122 Video(Box<Video>),
124}
125
126macro_rules! block_from {
127 ($($ty:ident,)*) => {
128 $(
129 impl From<$ty> for Block {
130 fn from(value: $ty) -> Self {
131 Self::$ty(Box::new(value))
132 }
133 }
134 )*
135 }
136}
137
138block_from! {
139 Actions,
140 Alert,
141 Card,
142 Carousel,
143 Context,
144 ContextActions,
145 DataTable,
146 DataVisualization,
147 Divider,
148 File,
149 Header,
150 Image,
151 Input,
152 Markdown,
153 Plan,
154 RichText,
155 Section,
156 Table,
157 TaskCard,
158 Video,
159}
160
161#[cfg(test)]
162pub mod test_helpers {
163 use super::rich_text::test_helpers as rich_text_helper;
164 use super::rich_text::types::test_helpers::*;
165 use super::*;
166 use crate::composition_objects::test_helpers::*;
167
168 pub fn header(text: impl Into<String>) -> Header {
169 Header {
170 block_id: None,
171 text: Some(plain_text(text)),
172 }
173 }
174
175 pub fn section(text: impl Into<String>) -> Section {
176 Section {
177 block_id: None,
178 text: Some(mrkdwn_text(text).into()),
179 fields: None,
180 accessory: None,
181 expand: None,
182 }
183 }
184
185 pub fn rich_text() -> RichText {
186 RichText {
187 block_id: Some("rich_text_0".into()),
188 elements: Some(vec![rich_text_helper::section(vec![el_text("foo")]).into()]),
189 }
190 }
191
192 pub fn task_card() -> TaskCard {
193 TaskCard {
194 task_id: Some("task_0".into()),
195 title: Some("Fetching weather data".into()),
196 status: Some(TaskStatus::Pending),
197 output: None,
198 details: None,
199 sources: None,
200 block_id: None,
201 }
202 }
203}