Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public static InputBlock input(ModelConfigurator<InputBlock.InputBlockBuilder> c
return configurator.configure(InputBlock.builder()).build();
}

// MarkdownBlock

public static MarkdownBlock markdown(ModelConfigurator<MarkdownBlock.MarkdownBlockBuilder> configurator) {
return configurator.configure(MarkdownBlock.builder()).build();
}

// RichTextBlock

public static RichTextBlock richText(ModelConfigurator<RichTextBlock.RichTextBlockBuilder> configurator) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.slack.api.model.block;

import com.slack.api.model.File;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* https://docs.slack.dev/reference/block-kit/blocks/markdown-block
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MarkdownBlock implements LayoutBlock {
public static final String TYPE = "markdown";
/**
* The type of block. For a markdown block, type is always markdown.
*/
private final String type = TYPE;
/**
* The standard markdown-formatted text. Limit 12,000 characters max.
*/
private String text;
/**
* The block_id is ignored in markdown blocks and will not be retained.
*/
private String blockId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ private Class<? extends LayoutBlock> getLayoutClassInstance(String typeName) {
return InputBlock.class;
case HeaderBlock.TYPE:
return HeaderBlock.class;
case MarkdownBlock.TYPE:
return MarkdownBlock.class;
case VideoBlock.TYPE:
return VideoBlock.class;
case RichTextBlock.TYPE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ public void parseInputOnes() {
assertThat(inputBlock.getHint(), is(notNullValue()));
}

@Test
public void parseMarkdownBlock() {
String blocks = "[{\n" +
" \"type\": \"markdown\",\n" +
" \"text\": \"**this is bold**\"\n" +
"}]";
String json = "{blocks: " + blocks + "}";
Message message = GsonFactory.createSnakeCase().fromJson(json, Message.class);
assertThat(message, is(notNullValue()));
assertThat(message.getBlocks().size(), is(1));
MarkdownBlock markdownBlock = (MarkdownBlock) message.getBlocks().get(0);
assertThat(markdownBlock.getText(), is("**this is bold**"));
}

@Test
public void parseMultiSelectOnes() {
String blocks = "[\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public void testHeader() {
assertThat(header(h -> h.blockId("block-id").text(plainText("This is the headline!"))), is(notNullValue()));
}

@Test
public void testMarkdown() {
assertThat(markdown(h -> h.text("**this is bold**")), is(notNullValue()));
}

@Test
public void testRichText() {
assertThat(richText(i -> i
Expand Down Expand Up @@ -123,4 +128,4 @@ public void testWorkflowButton() {
), is(notNullValue()));
}

}
}