Struct slack_messaging::blocks::Input
source · pub struct Input { /* private fields */ }Expand description
Input block representation.
Example
use slack_messaging::blocks::Input;
use slack_messaging::blocks::elements::PlainTextInput;
use serde_json::json;
let input = Input::new()
.set_block_id("input_1")
.label("label text")
.set_element(
PlainTextInput::new()
.set_action_id("text_area_1")
.multiline()
.placeholder("Enter some plain text.")
)
.optional();
let expected = json!({
"type": "input",
"block_id": "input_1",
"label": {
"type": "plain_text",
"text": "label text",
"emoji": true
},
"element": {
"type": "plain_text_input",
"action_id": "text_area_1",
"multiline": true,
"placeholder": {
"type": "plain_text",
"text": "Enter some plain text.",
"emoji": true
}
},
"optional": true
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);Implementations§
source§impl Input
impl Input
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs an Input block.
use slack_messaging::blocks::Input;
use serde_json::json;
let input = Input::new();
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "",
"emoji": true
},
"element": null
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn set_label(self, label: Text) -> Self
pub fn set_label(self, label: Text) -> Self
Sets label field.
use slack_messaging::blocks::Input;
use slack_messaging::blocks::elements::Text;
use serde_json::json;
let input = Input::new()
.set_label(Text::plain("label text"));
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "label text",
"emoji": true
},
"element": null
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn label<T: Into<String>>(self, label: T) -> Self
pub fn label<T: Into<String>>(self, label: T) -> Self
Sets label field from string. This is a shorthand for set_label method.
use slack_messaging::blocks::Input;
use serde_json::json;
let input = Input::new().label("label text");
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "label text",
"emoji": true
},
"element": null
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn set_element<T: Into<InputElement>>(self, element: T) -> Self
pub fn set_element<T: Into<InputElement>>(self, element: T) -> Self
Sets an object to element field. The argument is an any object that can transform into the enum InputElement.
use slack_messaging::blocks::Input;
use slack_messaging::blocks::elements::PlainTextInput;
use serde_json::json;
let input = Input::new()
.set_element(
PlainTextInput::new().set_action_id("input_1")
);
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "",
"emoji": true
},
"element": {
"type": "plain_text_input",
"action_id": "input_1"
},
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn set_dispatch_action(self, dispatch_action: bool) -> Self
pub fn set_dispatch_action(self, dispatch_action: bool) -> Self
Sets dispatch_action field.
use slack_messaging::blocks::Input;
use serde_json::json;
let input = Input::new()
.set_dispatch_action(true);
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "",
"emoji": true
},
"element": null,
"dispatch_action": true
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn dispatch_action(self) -> Self
pub fn dispatch_action(self) -> Self
Sets true to dispatch_action field.
use slack_messaging::blocks::Input;
use serde_json::json;
let input = Input::new().dispatch_action();
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "",
"emoji": true
},
"element": null,
"dispatch_action": true
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn set_block_id<T: Into<String>>(self, block_id: T) -> Self
pub fn set_block_id<T: Into<String>>(self, block_id: T) -> Self
Sets block_id field.
use slack_messaging::blocks::Input;
use serde_json::json;
let input = Input::new().set_block_id("input_1");
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "",
"emoji": true
},
"element": null,
"block_id": "input_1"
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn set_hint(self, hint: Text) -> Self
pub fn set_hint(self, hint: Text) -> Self
Sets hint field.
use slack_messaging::blocks::Input;
use slack_messaging::blocks::elements::Text;
use serde_json::json;
let input = Input::new()
.set_hint(Text::plain("Some hints for input"));
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "",
"emoji": true
},
"element": null,
"hint": {
"type": "plain_text",
"text": "Some hints for input",
"emoji": true
},
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn hint<T: Into<String>>(self, hint: T) -> Self
pub fn hint<T: Into<String>>(self, hint: T) -> Self
Sets hint field from string. This is a shorthand for set_hint method.
use slack_messaging::blocks::Input;
use serde_json::json;
let input = Input::new().hint("Some hints for input");
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "",
"emoji": true
},
"element": null,
"hint": {
"type": "plain_text",
"text": "Some hints for input",
"emoji": true
},
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn set_optional(self, optional: bool) -> Self
pub fn set_optional(self, optional: bool) -> Self
Sets optional field.
use slack_messaging::blocks::Input;
use serde_json::json;
let input = Input::new().set_optional(true);
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "",
"emoji": true
},
"element": null,
"optional": true
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn optional(self) -> Self
pub fn optional(self) -> Self
Sets true to optional field.
use slack_messaging::blocks::Input;
use serde_json::json;
let input = Input::new().optional();
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "",
"emoji": true
},
"element": null,
"optional": true
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);sourcepub fn required(self) -> Self
pub fn required(self) -> Self
Sets false to optional field.
use slack_messaging::blocks::Input;
use serde_json::json;
let input = Input::new().required();
let expected = json!({
"type": "input",
"label": {
"type": "plain_text",
"text": "",
"emoji": true
},
"element": null,
"optional": false
});
let input_json = serde_json::to_value(input).unwrap();
assert_eq!(input_json, expected);