Skip to content

Commit b803ad1

Browse files
committed
Merge branch 'main' of https://github.com/slackapi/java-slack-sdk into feat-work-objects
2 parents be89303 + 1317675 commit b803ad1

File tree

11 files changed

+753
-1
lines changed

11 files changed

+753
-1
lines changed

json-logs/samples/api/views.open.json

Lines changed: 160 additions & 0 deletions
Large diffs are not rendered by default.

json-logs/samples/api/views.publish.json

Lines changed: 160 additions & 0 deletions
Large diffs are not rendered by default.

json-logs/samples/api/views.push.json

Lines changed: 160 additions & 0 deletions
Large diffs are not rendered by default.

json-logs/samples/api/views.update.json

Lines changed: 160 additions & 0 deletions
Large diffs are not rendered by default.

slack-api-model-kotlin-extension/src/test/kotlin/test_locally/block/RichTextBlockTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ class RichTextBlockTest {
382382
"strike": false,
383383
"highlight": false,
384384
"client_highlight": true,
385+
"underline": false,
385386
"unlink": false
386387
}
387388
}
@@ -474,6 +475,7 @@ class RichTextBlockTest {
474475
"strike": true,
475476
"highlight": false,
476477
"client_highlight": true,
478+
"underline": false,
477479
"unlink": false,
478480
"code": true
479481
}

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/model/block/element/RichTextSectionElement.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public static class TextStyle {
162162
private boolean strike;
163163
private boolean highlight;
164164
private boolean clientHighlight;
165+
private boolean underline;
165166
private boolean unlink;
166167
private boolean code;
167168
}
@@ -176,6 +177,7 @@ public static class LimitedTextStyle {
176177
private boolean strike;
177178
private boolean highlight;
178179
private boolean clientHighlight;
180+
private boolean underline;
179181
private boolean unlink;
180182
}
181183

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: 65 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" +
@@ -265,6 +279,7 @@ public void parseRichTextOnes() {
265279
assertThat(text.getStyle().isBold(), is(true));
266280
assertThat(text.getStyle().isItalic(), is(false));
267281
assertThat(text.getStyle().isStrike(), is(false));
282+
assertThat(text.getStyle().isUnderline(), is(false));
268283
}
269284

270285
@Test
@@ -617,6 +632,56 @@ public void parseRichTextOnes4() {
617632
assertThat(view.getBlocks().size(), is(1));
618633
}
619634

635+
@Test
636+
public void parseRichTextOnes5() {
637+
// https://docs.slack.dev/changelog/2019/09/01/what-they-see-is-what-you-get-and-more-and-less
638+
String json = "{\n" +
639+
" \"user\": \"U111\",\n" +
640+
" \"type\": \"message\",\n" +
641+
" \"ts\": \"1761165621.982069\",\n" +
642+
" \"client_msg_id\": \"d0b7fc31-7456-4e54-9094-b5b1833fca8c\",\n" +
643+
" \"text\": \"this is underline\",\n" +
644+
" \"team\": \"T111\",\n" +
645+
" \"blocks\": [\n" +
646+
" {\n" +
647+
" \"type\": \"rich_text\",\n" +
648+
" \"block_id\": \"sfvOa\",\n" +
649+
" \"elements\": [\n" +
650+
" {\n" +
651+
" \"type\": \"rich_text_section\",\n" +
652+
" \"elements\": [\n" +
653+
" {\n" +
654+
" \"type\": \"text\",\n" +
655+
" \"text\": \"this is underline\",\n" +
656+
" \"style\": {\n" +
657+
" \"underline\": true\n" +
658+
" }\n" +
659+
" }\n" +
660+
" ]\n" +
661+
" }\n" +
662+
" ]\n" +
663+
" }\n" +
664+
" ]\n" +
665+
"}";
666+
667+
Message view = GsonFactory.createSnakeCase().fromJson(json, Message.class);
668+
assertThat(view.getBlocks().size(), is(1));
669+
670+
RichTextBlock richTextBlock = (RichTextBlock) view.getBlocks().get(0);
671+
assertThat(richTextBlock.getElements().size(), is(1));
672+
673+
RichTextSectionElement richTextSection = (RichTextSectionElement) richTextBlock.getElements().get(0);
674+
assertThat(richTextSection.getElements().size(), is(1));
675+
676+
RichTextSectionElement.Text text = (RichTextSectionElement.Text) richTextSection.getElements().get(0);
677+
assertThat(text.getType(), is("text"));
678+
assertThat(text.getText(), is("this is underline"));
679+
assertThat(text.getStyle().isBold(), is(false));
680+
assertThat(text.getStyle().isItalic(), is(false));
681+
assertThat(text.getStyle().isStrike(), is(false));
682+
assertThat(text.getStyle().isUnderline(), is(true));
683+
}
684+
620685
@Test
621686
public void parseRadioButtons() {
622687
String json = "{" +

0 commit comments

Comments
 (0)