Skip to content

Commit 8e4a186

Browse files
zimegClaude
andauthored
feat(block-kit): add plan block example (#108)
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent 96a43da commit 8e4a186

4 files changed

Lines changed: 146 additions & 2 deletions

File tree

‎block-kit/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
2121
- **[Image](https://docs.slack.dev/reference/block-kit/blocks/image-block)**: Displays an image. [Implementation](./src/main/java/blocks/Image.java).
2222
- **[Input](https://docs.slack.dev/reference/block-kit/blocks/input-block)**: Collects information from users via elements. [Implementation](./src/main/java/blocks/Input.java).
2323
- **[Markdown](https://docs.slack.dev/reference/block-kit/blocks/markdown-block)**: Displays formatted markdown. [Implementation](./src/main/java/blocks/Markdown.java).
24+
- **[Plan](https://docs.slack.dev/reference/block-kit/blocks/plan-block)**: Displays a collection of related tasks. [Implementation](./src/main/java/blocks/Plan.java).
2425
- **[Section](https://docs.slack.dev/reference/block-kit/blocks/section-block)**: Displays text, possibly alongside elements. [Implementation](./src/main/java/blocks/Section.java).
2526
- **[Task card](https://docs.slack.dev/reference/block-kit/blocks/task-card-block)**: Displays a single task, representing a single action. [Implementation](./src/main/java/blocks/TaskCard.java).
2627
- **[Video](https://docs.slack.dev/reference/block-kit/blocks/video-block)**: Displays an embedded video player. [Implementation](./src/main/java/blocks/Video.java).

‎block-kit/pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@
6363
<dependency>
6464
<groupId>com.slack.api</groupId>
6565
<artifactId>slack-api-model</artifactId>
66-
<version>1.54.0</version>
66+
<version>1.55.0</version>
6767
</dependency>
6868
<dependency>
6969
<groupId>com.slack.api</groupId>
7070
<artifactId>slack-api-client</artifactId>
71-
<version>1.54.0</version>
71+
<version>1.55.0</version>
7272
<scope>test</scope>
7373
</dependency>
7474
<dependency>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package blocks;
2+
3+
import com.slack.api.model.block.Blocks;
4+
import com.slack.api.model.block.PlanBlock;
5+
import com.slack.api.model.block.RichTextBlock;
6+
import com.slack.api.model.block.element.RichTextSectionElement;
7+
import java.util.List;
8+
9+
/**
10+
* Displays a collection of related tasks.
11+
* {@link https://docs.slack.dev/reference/block-kit/blocks/plan-block/}
12+
*/
13+
public class Plan {
14+
/**
15+
* A plan block with multiple task cards in various states.
16+
*/
17+
public static PlanBlock example01() {
18+
PlanBlock block = Blocks.plan(p -> p.title("Thinking completed")
19+
.tasks(List.of(
20+
Blocks.taskCard(t -> t.taskId("call_001")
21+
.title("Fetched user profile information")
22+
.status("in_progress")
23+
.details(RichTextBlock.builder()
24+
.blockId("viMWO")
25+
.elements(List.of(RichTextSectionElement.builder()
26+
.elements(List.of(RichTextSectionElement.Text.builder()
27+
.text("Searched database...")
28+
.build()))
29+
.build()))
30+
.build())
31+
.output(RichTextBlock.builder()
32+
.blockId("viMWO")
33+
.elements(List.of(RichTextSectionElement.builder()
34+
.elements(List.of(RichTextSectionElement.Text.builder()
35+
.text("Profile data loaded")
36+
.build()))
37+
.build()))
38+
.build())),
39+
Blocks.taskCard(t -> t.taskId("call_002")
40+
.title("Checked user permissions")
41+
.status("in_progress")),
42+
Blocks.taskCard(t -> t.taskId("call_003")
43+
.title("Generated comprehensive user report")
44+
.status("complete")
45+
.output(RichTextBlock.builder()
46+
.blockId("crsk")
47+
.elements(List.of(RichTextSectionElement.builder()
48+
.elements(List.of(RichTextSectionElement.Text.builder()
49+
.text("15 data points compiled")
50+
.build()))
51+
.build()))
52+
.build())))));
53+
return block;
54+
}
55+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package blocks;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.google.gson.JsonParser;
6+
import com.slack.api.model.block.PlanBlock;
7+
import com.slack.api.util.json.GsonFactory;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class PlanTest {
11+
@Test
12+
public void testExample01() {
13+
PlanBlock block = Plan.example01();
14+
String actual = GsonFactory.createSnakeCase().toJson(block);
15+
String expected = """
16+
{
17+
"type": "plan",
18+
"title": "Thinking completed",
19+
"tasks": [
20+
{
21+
"type": "task_card",
22+
"task_id": "call_001",
23+
"title": "Fetched user profile information",
24+
"status": "in_progress",
25+
"details": {
26+
"type": "rich_text",
27+
"block_id": "viMWO",
28+
"elements": [
29+
{
30+
"type": "rich_text_section",
31+
"elements": [
32+
{
33+
"type": "text",
34+
"text": "Searched database..."
35+
}
36+
]
37+
}
38+
]
39+
},
40+
"output": {
41+
"type": "rich_text",
42+
"block_id": "viMWO",
43+
"elements": [
44+
{
45+
"type": "rich_text_section",
46+
"elements": [
47+
{
48+
"type": "text",
49+
"text": "Profile data loaded"
50+
}
51+
]
52+
}
53+
]
54+
}
55+
},
56+
{
57+
"type": "task_card",
58+
"task_id": "call_002",
59+
"title": "Checked user permissions",
60+
"status": "in_progress"
61+
},
62+
{
63+
"type": "task_card",
64+
"task_id": "call_003",
65+
"title": "Generated comprehensive user report",
66+
"status": "complete",
67+
"output": {
68+
"type": "rich_text",
69+
"block_id": "crsk",
70+
"elements": [
71+
{
72+
"type": "rich_text_section",
73+
"elements": [
74+
{
75+
"type": "text",
76+
"text": "15 data points compiled"
77+
}
78+
]
79+
}
80+
]
81+
}
82+
}
83+
]
84+
}
85+
""";
86+
assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual));
87+
}
88+
}

0 commit comments

Comments
 (0)