Skip to content

Commit 740c37a

Browse files
authored
feat(model): add markdown block (#1521)
1 parent 9504d94 commit 740c37a

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

slack-api-model/src/main/java/com/slack/api/model/block/Blocks.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ public static InputBlock input(ModelConfigurator<InputBlock.InputBlockBuilder> c
8787
return configurator.configure(InputBlock.builder()).build();
8888
}
8989

90+
// MarkdownBlock
91+
92+
public static MarkdownBlock markdown(ModelConfigurator<MarkdownBlock.MarkdownBlockBuilder> configurator) {
93+
return configurator.configure(MarkdownBlock.builder()).build();
94+
}
95+
9096
// RichTextBlock
9197

9298
public static RichTextBlock richText(ModelConfigurator<RichTextBlock.RichTextBlockBuilder> configurator) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.slack.api.model.block;
2+
3+
import com.slack.api.model.File;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* https://docs.slack.dev/reference/block-kit/blocks/markdown-block
11+
*/
12+
@Data
13+
@Builder
14+
@NoArgsConstructor
15+
@AllArgsConstructor
16+
public class MarkdownBlock implements LayoutBlock {
17+
public static final String TYPE = "markdown";
18+
/**
19+
* The type of block. For a markdown block, type is always markdown.
20+
*/
21+
private final String type = TYPE;
22+
/**
23+
* The standard markdown-formatted text. Limit 12,000 characters max.
24+
*/
25+
private String text;
26+
/**
27+
* The block_id is ignored in markdown blocks and will not be retained.
28+
*/
29+
private String blockId;
30+
}

slack-api-model/src/main/java/com/slack/api/util/json/GsonLayoutBlockFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ private Class<? extends LayoutBlock> getLayoutClassInstance(String typeName) {
5151
return InputBlock.class;
5252
case HeaderBlock.TYPE:
5353
return HeaderBlock.class;
54+
case MarkdownBlock.TYPE:
55+
return MarkdownBlock.class;
5456
case VideoBlock.TYPE:
5557
return VideoBlock.class;
5658
case RichTextBlock.TYPE:

slack-api-model/src/test/java/test_locally/api/model/block/BlockKitTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ public void parseInputOnes() {
5555
assertThat(inputBlock.getHint(), is(notNullValue()));
5656
}
5757

58+
@Test
59+
public void parseMarkdownBlock() {
60+
String blocks = "[{\n" +
61+
" \"type\": \"markdown\",\n" +
62+
" \"text\": \"**this is bold**\"\n" +
63+
"}]";
64+
String json = "{blocks: " + blocks + "}";
65+
Message message = GsonFactory.createSnakeCase().fromJson(json, Message.class);
66+
assertThat(message, is(notNullValue()));
67+
assertThat(message.getBlocks().size(), is(1));
68+
MarkdownBlock markdownBlock = (MarkdownBlock) message.getBlocks().get(0);
69+
assertThat(markdownBlock.getText(), is("**this is bold**"));
70+
}
71+
5872
@Test
5973
public void parseMultiSelectOnes() {
6074
String blocks = "[\n" +

slack-api-model/src/test/java/test_locally/api/model/block/BlocksTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public void testHeader() {
8686
assertThat(header(h -> h.blockId("block-id").text(plainText("This is the headline!"))), is(notNullValue()));
8787
}
8888

89+
@Test
90+
public void testMarkdown() {
91+
assertThat(markdown(h -> h.text("**this is bold**")), is(notNullValue()));
92+
}
93+
8994
@Test
9095
public void testRichText() {
9196
assertThat(richText(i -> i
@@ -123,4 +128,4 @@ public void testWorkflowButton() {
123128
), is(notNullValue()));
124129
}
125130

126-
}
131+
}

0 commit comments

Comments
 (0)