slack_rust/block/
block_input.rs

1//! A block that collects information from users - it can hold a plain-text input element, a checkbox element, a radio button element, a select menu element, a multi-select menu element, or a datepicker.
2
3use crate::block::block_elements::BlockElement;
4use crate::block::block_object::TextBlockObject;
5use serde::{Deserialize, Serialize};
6use serde_with::skip_serializing_none;
7
8/// A block that collects information from users - it can hold a plain-text input element, a checkbox element, a radio button element, a select menu element, a multi-select menu element, or a datepicker.  
9/// See: <https://api.slack.com/reference/block-kit/blocks#input>
10#[skip_serializing_none]
11#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
12pub struct InputBlock {
13    pub label: TextBlockObject,
14    pub element: BlockElement,
15    pub dispatch_action: Option<bool>,
16    pub block_id: Option<String>,
17    pub hint: Option<TextBlockObject>,
18    pub optional: Option<bool>,
19}
20
21impl InputBlock {
22    pub fn builder(label: TextBlockObject, element: BlockElement) -> InputBlockBuilder {
23        InputBlockBuilder::new(label, element)
24    }
25}
26
27#[derive(Debug, Default)]
28pub struct InputBlockBuilder {
29    pub label: TextBlockObject,
30    pub element: BlockElement,
31    pub dispatch_action: Option<bool>,
32    pub block_id: Option<String>,
33    pub hint: Option<TextBlockObject>,
34    pub optional: Option<bool>,
35}
36
37impl InputBlockBuilder {
38    pub fn new(label: TextBlockObject, element: BlockElement) -> InputBlockBuilder {
39        InputBlockBuilder {
40            label,
41            element,
42            ..Default::default()
43        }
44    }
45    pub fn dispatch_action(mut self, dispatch_action: bool) -> InputBlockBuilder {
46        self.dispatch_action = Some(dispatch_action);
47        self
48    }
49    pub fn block_id(mut self, block_id: String) -> InputBlockBuilder {
50        self.block_id = Some(block_id);
51        self
52    }
53    pub fn hint(mut self, hint: TextBlockObject) -> InputBlockBuilder {
54        self.hint = Some(hint);
55        self
56    }
57    pub fn optional(mut self, optional: bool) -> InputBlockBuilder {
58        self.optional = Some(optional);
59        self
60    }
61    pub fn build(self) -> InputBlock {
62        InputBlock {
63            label: self.label,
64            element: self.element,
65            dispatch_action: self.dispatch_action,
66            block_id: self.block_id,
67            hint: self.hint,
68            optional: self.optional,
69        }
70    }
71}