slack_messaging/blocks/
mod.rs

1/// Builder objects for Blocks.
2pub mod builders;
3
4/// Objects from which blocks are composed.
5pub mod elements;
6
7mod actions;
8mod context;
9mod divider;
10mod file;
11mod header;
12mod image;
13mod input;
14mod markdown;
15mod section;
16mod video;
17
18use super::composition_objects;
19use serde::Serialize;
20
21/// Module for building [`RichText`] block.
22pub mod rich_text;
23/// Module for building [`Table`] block.
24pub mod table;
25
26pub use actions::{Actions, ActionsElement};
27pub use context::{Context, ContextElement};
28pub use divider::Divider;
29pub use file::{File, FileSource};
30pub use header::Header;
31pub use image::Image;
32pub use input::{Input, InputElement};
33pub use markdown::Markdown;
34pub use rich_text::{RichText, RichTextElement};
35pub use section::{Accessory, Section};
36pub use table::Table;
37pub use video::Video;
38
39/// Objects that can be set to blocks in [Message](crate::message::Message).
40#[derive(Debug, Clone, Serialize)]
41#[serde(untagged)]
42pub enum Block {
43    /// [Actions block](https://docs.slack.dev/reference/block-kit/blocks/actions-block) representation
44    Actions(Box<Actions>),
45
46    /// [Context block](https://docs.slack.dev/reference/block-kit/blocks/context-block) representation
47    Context(Box<Context>),
48
49    /// [Divider block](https://docs.slack.dev/reference/block-kit/blocks/divider-block) representation
50    Divider(Box<Divider>),
51
52    /// [File block](https://docs.slack.dev/reference/block-kit/blocks/file-block) representation
53    File(Box<File>),
54
55    /// [Header block](https://docs.slack.dev/reference/block-kit/blocks/header-block) representation
56    Header(Box<Header>),
57
58    /// [Image block](https://docs.slack.dev/reference/block-kit/blocks/image-block) representation
59    Image(Box<Image>),
60
61    /// [Input block](https://docs.slack.dev/reference/block-kit/blocks/input-block) representation
62    Input(Box<Input>),
63
64    /// [Markdown block](https://docs.slack.dev/reference/block-kit/blocks/markdown-block) representation
65    Markdown(Box<Markdown>),
66
67    /// [Rich text block](https://docs.slack.dev/reference/block-kit/blocks/rich-text-block) representation
68    RichText(Box<RichText>),
69
70    /// [Section block](https://docs.slack.dev/reference/block-kit/blocks/section-block) representation
71    Section(Box<Section>),
72
73    /// [Table block](https://docs.slack.dev/reference/block-kit/blocks/table-block) representation
74    Table(Box<Table>),
75
76    /// [Video block](https://docs.slack.dev/reference/block-kit/blocks/video-block) representation
77    Video(Box<Video>),
78}
79
80macro_rules! block_from {
81    ($($ty:ident),*) => {
82        $(
83            impl From<$ty> for Block {
84                fn from(value: $ty) -> Self {
85                    Self::$ty(Box::new(value))
86                }
87            }
88         )*
89    }
90}
91
92block_from! {
93    Actions,
94    Context,
95    Divider,
96    File,
97    Header,
98    Image,
99    Input,
100    Markdown,
101    RichText,
102    Section,
103    Table,
104    Video
105}