slack_messaging/blocks/
mod.rs1use serde::Serialize;
2
3pub mod builders;
5pub mod elements;
7pub mod rich_text;
9pub mod table;
11
12mod actions;
13mod alert;
14mod card;
15mod carousel;
16mod context;
17mod context_actions;
18mod divider;
19mod file;
20mod header;
21mod image;
22mod input;
23mod markdown;
24mod plan;
25mod section;
26mod task_card;
27mod video;
28
29pub use actions::{Actions, ActionsElement};
30pub use alert::{Alert, AlertLevel};
31pub use card::Card;
32pub use carousel::Carousel;
33pub use context::{Context, ContextElement};
34pub use context_actions::{ContextActions, ContextActionsElement};
35pub use divider::Divider;
36pub use file::{File, FileSource};
37pub use header::Header;
38pub use image::Image;
39pub use input::{Input, InputElement};
40pub use markdown::Markdown;
41pub use plan::Plan;
42pub use rich_text::RichText;
43pub use section::{Accessory, Section};
44pub use table::Table;
45pub use task_card::{TaskCard, TaskStatus};
46pub use video::Video;
47
48#[derive(Debug, Clone, Serialize, PartialEq)]
50#[serde(untagged)]
51pub enum Block {
52 Actions(Box<Actions>),
54
55 Alert(Box<Alert>),
57
58 Card(Box<Card>),
61
62 Carousel(Box<Carousel>),
65
66 Context(Box<Context>),
68
69 ContextActions(Box<ContextActions>),
71
72 Divider(Box<Divider>),
74
75 File(Box<File>),
77
78 Header(Box<Header>),
80
81 Image(Box<Image>),
83
84 Input(Box<Input>),
86
87 Markdown(Box<Markdown>),
89
90 Plan(Box<Plan>),
92
93 RichText(Box<RichText>),
95
96 Section(Box<Section>),
98
99 Table(Box<Table>),
101
102 Video(Box<Video>),
104}
105
106macro_rules! block_from {
107 ($($ty:ident,)*) => {
108 $(
109 impl From<$ty> for Block {
110 fn from(value: $ty) -> Self {
111 Self::$ty(Box::new(value))
112 }
113 }
114 )*
115 }
116}
117
118block_from! {
119 Actions,
120 Alert,
121 Card,
122 Carousel,
123 Context,
124 ContextActions,
125 Divider,
126 File,
127 Header,
128 Image,
129 Input,
130 Markdown,
131 Plan,
132 RichText,
133 Section,
134 Table,
135 Video,
136}
137
138#[cfg(test)]
139pub mod test_helpers {
140 use super::rich_text::test_helpers as rich_text_helper;
141 use super::rich_text::types::test_helpers::*;
142 use super::*;
143 use crate::composition_objects::test_helpers::*;
144
145 pub fn header(text: impl Into<String>) -> Header {
146 Header {
147 block_id: None,
148 text: Some(plain_text(text)),
149 }
150 }
151
152 pub fn section(text: impl Into<String>) -> Section {
153 Section {
154 block_id: None,
155 text: Some(mrkdwn_text(text).into()),
156 fields: None,
157 accessory: None,
158 expand: None,
159 }
160 }
161
162 pub fn rich_text() -> RichText {
163 RichText {
164 block_id: Some("rich_text_0".into()),
165 elements: Some(vec![rich_text_helper::section(vec![el_text("foo")]).into()]),
166 }
167 }
168
169 pub fn task_card() -> TaskCard {
170 TaskCard {
171 task_id: Some("task_0".into()),
172 title: Some("Fetching weather data".into()),
173 status: Some(TaskStatus::Pending),
174 output: None,
175 details: None,
176 sources: None,
177 block_id: None,
178 }
179 }
180}