slack_messaging/composition_objects/
mod.rs

1/// builder objects for composition objects.
2pub mod builders;
3
4/// Additional types to create composition objects.
5pub mod types;
6
7mod confirmation_dialog;
8mod conversation_filter;
9mod dispatch_action_configuration;
10mod option;
11mod option_group;
12mod slack_file;
13mod text;
14mod trigger;
15mod workflow;
16
17pub use confirmation_dialog::ConfirmationDialog;
18pub use conversation_filter::ConversationFilter;
19pub use dispatch_action_configuration::DispatchActionConfiguration;
20pub use option::Opt;
21pub use option_group::OptGroup;
22pub use slack_file::SlackFile;
23pub use text::{Mrkdwn, Plain, Text, TextContent, TextExt};
24pub use trigger::Trigger;
25pub use workflow::Workflow;
26
27#[cfg(test)]
28pub mod test_helpers {
29    use super::types::*;
30    use super::*;
31
32    pub fn plain_text(text: impl Into<String>) -> Text<Plain> {
33        Text::<Plain> {
34            r#type: std::marker::PhantomData,
35            text: Some(text.into()),
36            emoji: None,
37            verbatim: None,
38        }
39    }
40
41    pub fn mrkdwn_text(text: impl Into<String>) -> Text<Mrkdwn> {
42        Text::<Mrkdwn> {
43            r#type: std::marker::PhantomData,
44            text: Some(text.into()),
45            emoji: None,
46            verbatim: None,
47        }
48    }
49
50    pub fn option(text: impl Into<String>, value: impl Into<String>) -> Opt {
51        Opt {
52            phantom: std::marker::PhantomData,
53            text: Some(plain_text(text)),
54            value: Some(value.into()),
55            description: None,
56            url: None,
57        }
58    }
59
60    pub fn option_t(text: impl Into<String>, value: impl Into<String>) -> Opt<TextContent> {
61        Opt {
62            phantom: std::marker::PhantomData,
63            text: Some(mrkdwn_text(text).into()),
64            value: Some(value.into()),
65            description: None,
66            url: None,
67        }
68    }
69
70    pub fn option_group(label: impl Into<String>, options: Vec<Opt>) -> OptGroup {
71        OptGroup {
72            label: Some(plain_text(label)),
73            options: Some(options),
74        }
75    }
76
77    pub fn input_param(name: impl Into<String>, value: impl Into<String>) -> InputParameter {
78        InputParameter {
79            name: Some(name.into()),
80            value: Some(serde_json::Value::String(value.into())),
81        }
82    }
83
84    pub fn trigger() -> Trigger {
85        Trigger {
86            url: Some("https://slack.com/shortcuts/Ft0123ABC456/123...xyz".into()),
87            customizable_input_parameters: Some(vec![
88                input_param("param_0", "value_0"),
89                input_param("param_1", "value_1"),
90            ]),
91        }
92    }
93
94    pub fn confirm() -> ConfirmationDialog {
95        ConfirmationDialog {
96            title: Some(plain_text("Are you sure?")),
97            text: Some(plain_text("Wouldn't you prefer a good game of _chess_?")),
98            confirm: Some(plain_text("Do it")),
99            deny: Some(plain_text("Stop, I've changed my mind!")),
100            style: None,
101        }
102    }
103
104    pub fn dispatch_action_config() -> DispatchActionConfiguration {
105        DispatchActionConfiguration {
106            trigger_actions_on: Some(vec![TriggerAction::OnEnterPressed]),
107        }
108    }
109
110    pub fn slack_file() -> SlackFile {
111        SlackFile {
112            id: Some("F0123456".into()),
113            url: None,
114        }
115    }
116
117    pub fn conversation_filter() -> ConversationFilter {
118        ConversationFilter {
119            include: Some(vec![Conversation::Public]),
120            exclude_external_shared_channels: None,
121            exclude_bot_users: None,
122        }
123    }
124
125    pub fn workflow() -> Workflow {
126        Workflow {
127            trigger: Some(trigger()),
128        }
129    }
130}