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 context;
21mod context_actions;
22mod divider;
23mod file;
24mod header;
25mod image;
26mod input;
27mod markdown;
28mod plan;
29mod section;
30mod task_card;
31mod video;
32
33pub use actions::{Actions, ActionsElement};
34pub use alert::{Alert, AlertLevel};
35pub use card::Card;
36pub use carousel::Carousel;
37pub use context::{Context, ContextElement};
38pub use context_actions::{ContextActions, ContextActionsElement};
39pub use data_table::DataTable;
40pub use data_visualization::DataVisualization;
41pub use divider::Divider;
42pub use file::{File, FileSource};
43pub use header::Header;
44pub use image::Image;
45pub use input::{Input, InputElement};
46pub use markdown::Markdown;
47pub use plan::Plan;
48pub use rich_text::RichText;
49pub use section::{Accessory, Section};
50pub use table::Table;
51pub use task_card::{TaskCard, TaskStatus};
52pub use video::Video;
53
54#[derive(Debug, Clone, Serialize, PartialEq)]
56#[serde(untagged)]
57pub enum Block {
58 Actions(Box<Actions>),
60
61 Alert(Box<Alert>),
63
64 Card(Box<Card>),
67
68 Carousel(Box<Carousel>),
71
72 Context(Box<Context>),
74
75 ContextActions(Box<ContextActions>),
77
78 DataTable(Box<DataTable>),
80
81 DataVisualization(Box<DataVisualization>),
85
86 Divider(Box<Divider>),
88
89 File(Box<File>),
91
92 Header(Box<Header>),
94
95 Image(Box<Image>),
97
98 Input(Box<Input>),
100
101 Markdown(Box<Markdown>),
103
104 Plan(Box<Plan>),
106
107 RichText(Box<RichText>),
109
110 Section(Box<Section>),
112
113 Table(Box<Table>),
115
116 TaskCard(Box<TaskCard>),
119
120 Video(Box<Video>),
122}
123
124macro_rules! block_from {
125 ($($ty:ident,)*) => {
126 $(
127 impl From<$ty> for Block {
128 fn from(value: $ty) -> Self {
129 Self::$ty(Box::new(value))
130 }
131 }
132 )*
133 }
134}
135
136block_from! {
137 Actions,
138 Alert,
139 Card,
140 Carousel,
141 Context,
142 ContextActions,
143 DataTable,
144 DataVisualization,
145 Divider,
146 File,
147 Header,
148 Image,
149 Input,
150 Markdown,
151 Plan,
152 RichText,
153 Section,
154 Table,
155 TaskCard,
156 Video,
157}
158
159#[cfg(test)]
160pub mod test_helpers {
161 use super::rich_text::test_helpers as rich_text_helper;
162 use super::rich_text::types::test_helpers::*;
163 use super::*;
164 use crate::composition_objects::test_helpers::*;
165
166 pub fn header(text: impl Into<String>) -> Header {
167 Header {
168 block_id: None,
169 text: Some(plain_text(text)),
170 }
171 }
172
173 pub fn section(text: impl Into<String>) -> Section {
174 Section {
175 block_id: None,
176 text: Some(mrkdwn_text(text).into()),
177 fields: None,
178 accessory: None,
179 expand: None,
180 }
181 }
182
183 pub fn rich_text() -> RichText {
184 RichText {
185 block_id: Some("rich_text_0".into()),
186 elements: Some(vec![rich_text_helper::section(vec![el_text("foo")]).into()]),
187 }
188 }
189
190 pub fn task_card() -> TaskCard {
191 TaskCard {
192 task_id: Some("task_0".into()),
193 title: Some("Fetching weather data".into()),
194 status: Some(TaskStatus::Pending),
195 output: None,
196 details: None,
197 sources: None,
198 block_id: None,
199 }
200 }
201}