Repository navigation
feat(block-kit): add plan block example #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package blocks; | ||
|
|
||
| import com.slack.api.model.block.Blocks; | ||
| import com.slack.api.model.block.PlanBlock; | ||
|
Check failure on line 4 in block-kit/src/main/java/blocks/Plan.java
|
||
| import com.slack.api.model.block.RichTextBlock; | ||
| import com.slack.api.model.block.element.RichTextSectionElement; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Displays a collection of related tasks. | ||
| * {@link https://docs.slack.dev/reference/block-kit/blocks/plan-block/} | ||
| */ | ||
| public class Plan { | ||
| /** | ||
| * A plan block with multiple task cards in various states. | ||
| */ | ||
| public static PlanBlock example01() { | ||
|
Check failure on line 17 in block-kit/src/main/java/blocks/Plan.java
|
||
| PlanBlock block = Blocks.plan(p -> p.title("Thinking completed") | ||
|
Check failure on line 18 in block-kit/src/main/java/blocks/Plan.java
|
||
| .tasks(List.of( | ||
| Blocks.taskCard(t -> t.taskId("call_001") | ||
| .title("Fetched user profile information") | ||
| .status("in_progress") | ||
| .details(RichTextBlock.builder() | ||
| .blockId("viMWO") | ||
| .elements(List.of(RichTextSectionElement.builder() | ||
| .elements(List.of(RichTextSectionElement.Text.builder() | ||
| .text("Searched database...") | ||
| .build())) | ||
| .build())) | ||
| .build()) | ||
| .output(RichTextBlock.builder() | ||
| .blockId("viMWO") | ||
| .elements(List.of(RichTextSectionElement.builder() | ||
| .elements(List.of(RichTextSectionElement.Text.builder() | ||
| .text("Profile data loaded") | ||
| .build())) | ||
| .build())) | ||
| .build())), | ||
| Blocks.taskCard(t -> t.taskId("call_002") | ||
| .title("Checked user permissions") | ||
| .status("in_progress")), | ||
| Blocks.taskCard(t -> t.taskId("call_003") | ||
| .title("Generated comprehensive user report") | ||
| .status("complete") | ||
| .output(RichTextBlock.builder() | ||
| .blockId("crsk") | ||
| .elements(List.of(RichTextSectionElement.builder() | ||
| .elements(List.of(RichTextSectionElement.Text.builder() | ||
| .text("15 data points compiled") | ||
| .build())) | ||
| .build())) | ||
| .build()))))); | ||
| return block; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package blocks; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import com.google.gson.JsonParser; | ||
| import com.slack.api.model.block.PlanBlock; | ||
| import com.slack.api.util.json.GsonFactory; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class PlanTest { | ||
| @Test | ||
| public void testExample01() { | ||
| PlanBlock block = Plan.example01(); | ||
| String actual = GsonFactory.createSnakeCase().toJson(block); | ||
| String expected = """ | ||
| { | ||
| "type": "plan", | ||
| "title": "Thinking completed", | ||
| "tasks": [ | ||
| { | ||
| "type": "task_card", | ||
| "task_id": "call_001", | ||
| "title": "Fetched user profile information", | ||
| "status": "in_progress", | ||
| "details": { | ||
| "type": "rich_text", | ||
| "block_id": "viMWO", | ||
| "elements": [ | ||
| { | ||
| "type": "rich_text_section", | ||
| "elements": [ | ||
| { | ||
| "type": "text", | ||
| "text": "Searched database..." | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| "output": { | ||
| "type": "rich_text", | ||
| "block_id": "viMWO", | ||
| "elements": [ | ||
| { | ||
| "type": "rich_text_section", | ||
| "elements": [ | ||
| { | ||
| "type": "text", | ||
| "text": "Profile data loaded" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "type": "task_card", | ||
| "task_id": "call_002", | ||
| "title": "Checked user permissions", | ||
| "status": "in_progress" | ||
| }, | ||
| { | ||
| "type": "task_card", | ||
| "task_id": "call_003", | ||
| "title": "Generated comprehensive user report", | ||
| "status": "complete", | ||
| "output": { | ||
| "type": "rich_text", | ||
| "block_id": "crsk", | ||
| "elements": [ | ||
| { | ||
| "type": "rich_text_section", | ||
| "elements": [ | ||
| { | ||
| "type": "text", | ||
| "text": "15 data points compiled" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| """; | ||
| assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Matches the TaskCard example and the docs payload 👌 The
block-kitbuild fails until a java-slack-sdk release withPlanBlocklands and the pom is bumped to it, so let's merge once that's in.