Skip to content

Commit 4f69294

Browse files
authored
feat: add new Block Kit blocks and elements (alert, card, carousel, context_actions, workflow button, file input) (#363)
* feat: add new Block Kit blocks and elements (alert, card, carousel, context_actions, workflow button, file input) - Add SlackAlertBlock with SlackAlertLevel enum - Add SlackCardBlock with title, subtitle, body, hero_image, icon, actions - Add SlackCarouselBlock - Add SlackContextActionsBlock with SlackBlockIconButtonElement and SlackBlockFeedbackButtonsElement - Add SlackBlockFileInputElement and SlackInputBlockElement::FileInput variant - Add workflow button types in new workflow.rs module (SlackWorkflow, SlackWorkflowTrigger, SlackBlockWorkflowButtonElement) - Add WorkflowButton variant to SlackSectionBlockElement and SlackActionBlockElement - Add SlackBlockButtonStyle enum (Primary, Danger) replacing Option<String> on button elements - Add SlackAccessibilityLabel newtype used on button and icon button elements - Add SlackDispatchActionConfig and dispatch_action_config field on SlackBlockPlainTextInputElement - Add expand field to SlackSectionBlock - Add accessibility_label field to SlackBlockButtonElement - Add fixture JSON files and roundtrip tests for all new blocks - Update socket_mode example to exercise new types * fix: use SlackDispatchActionTrigger enum for trigger_actions_on instead of Vec<String>
1 parent de21e8a commit 4f69294

8 files changed

Lines changed: 548 additions & 63 deletions

File tree

examples/socket_mode.rs

Lines changed: 80 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -36,71 +36,89 @@ async fn test_command_events_function(
3636

3737
println!("{:#?}", user_info_resp);
3838

39+
let blocks: Vec<SlackBlock> = slack_blocks![
40+
some_into(SlackSectionBlock::new().with_text(md!(
41+
"Working section for {}. Team ID: {:?}",
42+
event.user_id.to_slack_format(),
43+
user_info_resp.user.team_id
44+
))),
45+
some_into(SlackActionsBlock::new(slack_blocks![
46+
some_into(
47+
SlackBlockButtonElement::new(
48+
"my-simple-action-button".into(),
49+
pt!("Action button")
50+
)
51+
.with_style(SlackBlockButtonStyle::Primary)
52+
.with_accessibility_label(SlackAccessibilityLabel(
53+
"Perform the main action".into()
54+
))
55+
),
56+
some_into(
57+
SlackBlockStaticSelectElement::new("my-simple-static-menu".into()).with_options(
58+
vec![SlackBlockChoiceItem::new(
59+
pt!("my-option1"),
60+
"my-option1-value".to_string()
61+
)]
62+
)
63+
)
64+
])),
65+
some_into(
66+
SlackCardBlock::new()
67+
.with_title(md!("Library status"))
68+
.with_body(md!("slack-morphism is up and running."))
69+
),
70+
some_into(SlackContextActionsBlock::new(vec![
71+
SlackBlockIconButtonElement::new("delete_card".into(), "trash".into(), pt!("Delete"))
72+
.with_value("delete_item".into())
73+
.with_accessibility_label(SlackAccessibilityLabel("Delete this item".into()))
74+
.into()
75+
])),
76+
some_into(
77+
SlackTableBlock::new(vec![
78+
vec![
79+
SlackTableCell::RawText(SlackTableRawTextCell::new("Name".into())),
80+
SlackTableCell::RawText(SlackTableRawTextCell::new("Status".into())),
81+
],
82+
vec![
83+
SlackTableCell::RawText(SlackTableRawTextCell::new("Slack Morphism".into())),
84+
SlackTableCell::RichText(SlackTableRichTextCell::new(vec![
85+
SlackRichTextSection::new(vec![SlackRichTextInlineElement::Text(
86+
SlackRichTextText::new("Active".into())
87+
.with_style(SlackRichTextStyle::new().with_bold(true))
88+
)])
89+
.into()
90+
])),
91+
],
92+
])
93+
.with_column_settings(vec![
94+
SlackTableColumnSetting::new(),
95+
SlackTableColumnSetting::new().with_align(SlackTableColumnAlign::Right),
96+
])
97+
),
98+
some_into(
99+
SlackTaskCardBlock::new("task_demo".into(), "Checking library status".into())
100+
.with_status(SlackTaskCardStatus::Complete)
101+
.with_output(
102+
SlackRichTextBlock::new(vec![SlackRichTextSection::new(vec![
103+
SlackRichTextInlineElement::Text(SlackRichTextText::new(
104+
"All systems operational".into()
105+
))
106+
])
107+
.into()])
108+
.into()
109+
)
110+
.with_sources(vec![SlackUrlSourceElement::new(
111+
Url::parse("https://slack-rust.abdolence.dev").expect("A proper url"),
112+
"slack-morphism docs".into()
113+
)
114+
.into()])
115+
)
116+
];
117+
39118
Ok(SlackCommandEventResponse::new(
40119
SlackMessageContent::new()
41120
.with_text(format!("Working on it: {:?}", user_info_resp.user.team_id).into())
42-
.with_blocks(slack_blocks![
43-
some_into(SlackSectionBlock::new().with_text(md!(
44-
"Working section for {}. Team ID: {:?}",
45-
event.user_id.to_slack_format(),
46-
user_info_resp.user.team_id
47-
))),
48-
some_into(SlackActionsBlock::new(slack_blocks![
49-
some_into(SlackBlockButtonElement::new(
50-
"my-simple-action-button".into(),
51-
pt!("Action button")
52-
)),
53-
some_into(
54-
SlackBlockStaticSelectElement::new("my-simple-static-menu".into())
55-
.with_options(vec![SlackBlockChoiceItem::new(
56-
pt!("my-option1"),
57-
"my-option1-value".to_string()
58-
)])
59-
)
60-
])),
61-
some_into(
62-
SlackTableBlock::new(vec![
63-
vec![
64-
SlackTableCell::RawText(SlackTableRawTextCell::new("Name".into())),
65-
SlackTableCell::RawText(SlackTableRawTextCell::new("Status".into())),
66-
],
67-
vec![
68-
SlackTableCell::RawText(SlackTableRawTextCell::new(
69-
"Slack Morphism".into()
70-
)),
71-
SlackTableCell::RichText(SlackTableRichTextCell::new(vec![
72-
SlackRichTextSection::new(vec![SlackRichTextInlineElement::Text(
73-
SlackRichTextText::new("Active".into())
74-
.with_style(SlackRichTextStyle::new().with_bold(true))
75-
)])
76-
.into()
77-
])),
78-
],
79-
])
80-
.with_column_settings(vec![
81-
SlackTableColumnSetting::new(),
82-
SlackTableColumnSetting::new().with_align(SlackTableColumnAlign::Right),
83-
])
84-
),
85-
some_into(
86-
SlackTaskCardBlock::new("task_demo".into(), "Checking library status".into())
87-
.with_status(SlackTaskCardStatus::Complete)
88-
.with_output(
89-
SlackRichTextBlock::new(vec![SlackRichTextSection::new(vec![
90-
SlackRichTextInlineElement::Text(SlackRichTextText::new(
91-
"All systems operational".into()
92-
))
93-
])
94-
.into()])
95-
.into()
96-
)
97-
.with_sources(vec![SlackUrlSourceElement::new(
98-
Url::parse("https://slack-rust.abdolence.dev").expect("A proper url"),
99-
"slack-morphism docs".into()
100-
)
101-
.into()])
102-
)
103-
]),
121+
.with_blocks(blocks),
104122
))
105123
}
106124

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "alert",
3+
"block_id": "alert_block_1",
4+
"text": {
5+
"type": "mrkdwn",
6+
"text": "Your disk is almost full. Please free up space."
7+
},
8+
"level": "warning"
9+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"type": "card",
3+
"block_id": "card_block_1",
4+
"title": {
5+
"type": "mrkdwn",
6+
"text": "My Card"
7+
},
8+
"subtitle": {
9+
"type": "mrkdwn",
10+
"text": "A short subtitle."
11+
},
12+
"body": {
13+
"type": "mrkdwn",
14+
"text": "A short description of the card."
15+
},
16+
"hero_image": {
17+
"type": "image",
18+
"image_url": "https://example.com/hero.png",
19+
"alt_text": "hero image"
20+
},
21+
"actions": [
22+
{
23+
"type": "button",
24+
"action_id": "card_action_1",
25+
"text": {
26+
"type": "plain_text",
27+
"text": "Open"
28+
},
29+
"style": "primary",
30+
"value": "open"
31+
}
32+
]
33+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"type": "context_actions",
3+
"block_id": "context_actions_1",
4+
"elements": [
5+
{
6+
"type": "icon_button",
7+
"action_id": "delete_action",
8+
"icon": "trash",
9+
"text": {
10+
"type": "plain_text",
11+
"text": "Delete"
12+
},
13+
"value": "delete_item"
14+
}
15+
]
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"type": "actions",
3+
"block_id": "workflow_actions",
4+
"elements": [
5+
{
6+
"type": "workflow_button",
7+
"action_id": "start_workflow",
8+
"text": {
9+
"type": "plain_text",
10+
"text": "Start Workflow"
11+
},
12+
"workflow": {
13+
"trigger": {
14+
"url": "https://slack.com/shortcuts/Ft0ABC123/xyz",
15+
"customizable_input_parameters": [
16+
{
17+
"name": "user_input",
18+
"value": "hello"
19+
}
20+
]
21+
}
22+
},
23+
"style": "primary"
24+
}
25+
]
26+
}

0 commit comments

Comments
 (0)