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 context;
14mod context_actions;
15mod divider;
16mod file;
17mod header;
18mod image;
19mod input;
20mod markdown;
21mod section;
22mod video;
23
24pub use actions::{Actions, ActionsElement};
25pub use context::{Context, ContextElement};
26pub use context_actions::{ContextActions, ContextActionsElement};
27pub use divider::Divider;
28pub use file::{File, FileSource};
29pub use header::Header;
30pub use image::Image;
31pub use input::{Input, InputElement};
32pub use markdown::Markdown;
33pub use rich_text::RichText;
34pub use section::{Accessory, Section};
35pub use table::Table;
36pub use video::Video;
37
38#[derive(Debug, Clone, Serialize, PartialEq)]
40#[serde(untagged)]
41pub enum Block {
42 Actions(Box<Actions>),
44
45 Context(Box<Context>),
47
48 ContextActions(Box<ContextActions>),
50
51 Divider(Box<Divider>),
53
54 File(Box<File>),
56
57 Header(Box<Header>),
59
60 Image(Box<Image>),
62
63 Input(Box<Input>),
65
66 Markdown(Box<Markdown>),
68
69 RichText(Box<RichText>),
71
72 Section(Box<Section>),
74
75 Table(Box<Table>),
77
78 Video(Box<Video>),
80}
81
82macro_rules! block_from {
83 ($($ty:ident,)*) => {
84 $(
85 impl From<$ty> for Block {
86 fn from(value: $ty) -> Self {
87 Self::$ty(Box::new(value))
88 }
89 }
90 )*
91 }
92}
93
94block_from! {
95 Actions,
96 Context,
97 ContextActions,
98 Divider,
99 File,
100 Header,
101 Image,
102 Input,
103 Markdown,
104 RichText,
105 Section,
106 Table,
107 Video,
108}
109
110#[cfg(test)]
111pub mod test_helpers {
112 use super::rich_text::test_helpers as rich_text_helper;
113 use super::rich_text::types::test_helpers::*;
114 use super::*;
115 use crate::composition_objects::test_helpers::*;
116
117 pub fn header(text: impl Into<String>) -> Header {
118 Header {
119 block_id: None,
120 text: Some(plain_text(text)),
121 }
122 }
123
124 pub fn section(text: impl Into<String>) -> Section {
125 Section {
126 block_id: None,
127 text: Some(mrkdwn_text(text).into()),
128 fields: None,
129 accessory: None,
130 expand: None,
131 }
132 }
133
134 pub fn rich_text() -> RichText {
135 RichText {
136 block_id: Some("rich_text_0".into()),
137 elements: Some(vec![rich_text_helper::section(vec![el_text("foo")]).into()]),
138 }
139 }
140}