pub struct Actions { /* private fields */ }Expand description
Actions block representation.
§Fields and Validations
For more details, see the official documentation.
| Field | Type | Required | Validation |
|---|---|---|---|
| elements | Vec<ActionsElement> | Yes | Maximum of 25 items |
| block_id | String | No | Maximum 255 characters |
§Example
The following is reproduction of the 1st sample actions.
use slack_messaging::plain_text;
use slack_messaging::blocks::Actions;
use slack_messaging::blocks::elements::{Button, SelectMenuStaticOptions};
use slack_messaging::composition_objects::Opt;
let actions = Actions::builder()
.block_id("actions1")
.element(
SelectMenuStaticOptions::builder()
.action_id("select_2")
.placeholder(plain_text!("Which witch is the witchiest witch?")?)
.options(
vec![
Opt::builder()
.text(plain_text!("Matilda")?)
.value("matilda")
.build()?,
Opt::builder()
.text(plain_text!("Glinda")?)
.value("glinda")
.build()?,
Opt::builder()
.text(plain_text!("Granny Weatherwax")?)
.value("grannyWeatherwax")
.build()?,
Opt::builder()
.text(plain_text!("Hermione")?)
.value("hermione")
.build()?,
]
)
.build()?
)
.element(
Button::builder()
.action_id("button_1")
.value("cancel")
.text(plain_text!("Cancel")?)
.build()?
)
.build()?;
let expected = serde_json::json!({
"type": "actions",
"block_id": "actions1",
"elements": [
{
"type": "static_select",
"action_id": "select_2",
"placeholder": {
"type": "plain_text",
"text": "Which witch is the witchiest witch?"
},
"options": [
{
"text": {
"type": "plain_text",
"text": "Matilda"
},
"value": "matilda"
},
{
"text": {
"type": "plain_text",
"text": "Glinda"
},
"value": "glinda"
},
{
"text": {
"type": "plain_text",
"text": "Granny Weatherwax"
},
"value": "grannyWeatherwax"
},
{
"text": {
"type": "plain_text",
"text": "Hermione"
},
"value": "hermione"
}
]
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Cancel"
},
"value": "cancel",
"action_id": "button_1"
}
]
});
let json = serde_json::to_value(actions).unwrap();
assert_eq!(json, expected);And the following is the 2nd sample actions.
use slack_messaging::plain_text;
use slack_messaging::blocks::Actions;
use slack_messaging::blocks::elements::{Button, DatePicker, OverflowMenu};
use slack_messaging::composition_objects::Opt;
let actions = Actions::builder()
.block_id("actionblock789")
.element(
DatePicker::builder()
.action_id("datepicker123")
.initial_date("1990-04-28")
.placeholder(plain_text!("Select a date")?)
.build()?
)
.element(
OverflowMenu::builder()
.action_id("overflow")
.option(
Opt::builder()
.text(plain_text!("*this is plain_text text*")?)
.value("value-0")
.build()?
)
.option(
Opt::builder()
.text(plain_text!("*this is plain_text text*")?)
.value("value-1")
.build()?
)
.option(
Opt::builder()
.text(plain_text!("*this is plain_text text*")?)
.value("value-2")
.build()?
)
.option(
Opt::builder()
.text(plain_text!("*this is plain_text text*")?)
.value("value-3")
.build()?
)
.option(
Opt::builder()
.text(plain_text!("*this is plain_text text*")?)
.value("value-4")
.build()?
)
.build()?
)
.element(
Button::builder()
.action_id("button")
.value("click_me_123")
.text(plain_text!("Click Me")?)
.build()?
)
.build()?;
let expected = serde_json::json!({
"type": "actions",
"block_id": "actionblock789",
"elements": [
{
"type": "datepicker",
"action_id": "datepicker123",
"initial_date": "1990-04-28",
"placeholder": {
"type": "plain_text",
"text": "Select a date"
}
},
{
"type": "overflow",
"action_id": "overflow",
"options": [
{
"text": {
"type": "plain_text",
"text": "*this is plain_text text*"
},
"value": "value-0"
},
{
"text": {
"type": "plain_text",
"text": "*this is plain_text text*"
},
"value": "value-1"
},
{
"text": {
"type": "plain_text",
"text": "*this is plain_text text*"
},
"value": "value-2"
},
{
"text": {
"type": "plain_text",
"text": "*this is plain_text text*"
},
"value": "value-3"
},
{
"text": {
"type": "plain_text",
"text": "*this is plain_text text*"
},
"value": "value-4"
}
]
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Me"
},
"value": "click_me_123",
"action_id": "button"
}
]
});
let json = serde_json::to_value(actions).unwrap();
assert_eq!(json, expected);Implementations§
Source§impl Actions
impl Actions
Sourcepub fn builder() -> ActionsBuilder
pub fn builder() -> ActionsBuilder
constract ActionsBuilder object.
Trait Implementations§
impl StructuralPartialEq for Actions
Auto Trait Implementations§
impl Freeze for Actions
impl RefUnwindSafe for Actions
impl Send for Actions
impl Sync for Actions
impl Unpin for Actions
impl UnsafeUnpin for Actions
impl UnwindSafe for Actions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more