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
1 change: 1 addition & 0 deletions block-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
### Blocks

- **[Actions](https://docs.slack.dev/reference/block-kit/blocks/actions-block)**: Holds multiple interactive elements. [Implementation](./src/main/java/blocks/Actions.java).
- **[Alert](https://docs.slack.dev/reference/block-kit/blocks/alert-block)**: Displays alerts, warnings, and informational messages. [Implementation](./src/main/java/blocks/Alert.java).
- **[Context](https://docs.slack.dev/reference/block-kit/blocks/context-block)**: Provides contextual info, which can include both images and text. [Implementation](./src/main/java/blocks/Context.java).
- **[Divider](https://docs.slack.dev/reference/block-kit/blocks/divider-block)**: Visually separates pieces of info inside of a message. [Implementation](./src/main/java/blocks/Divider.java).
- **[File](https://docs.slack.dev/reference/block-kit/blocks/file-block)**: Displays info about remote files. [Implementation](./src/main/java/blocks/File.java).
Expand Down
21 changes: 21 additions & 0 deletions block-kit/src/main/java/blocks/Alert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package blocks;

import com.slack.api.model.block.AlertBlock;
import com.slack.api.model.block.Blocks;
import com.slack.api.model.block.composition.BlockCompositions;

/**
* Displays alerts, warnings, and informational messages.
* {@link https://docs.slack.dev/reference/block-kit/blocks/alert-block/}
*/
public class Alert {
/**
* An informational alert.
*/
public static AlertBlock example01() {
AlertBlock block =
Blocks.alert(a -> a.text(BlockCompositions.markdownText("The work is mysterious and important."))
.level("info"));
return block;
}
}
27 changes: 27 additions & 0 deletions block-kit/src/test/java/blocks/AlertTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package blocks;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.google.gson.JsonParser;
import com.slack.api.model.block.AlertBlock;
import com.slack.api.util.json.GsonFactory;
import org.junit.jupiter.api.Test;

public class AlertTest {
@Test
public void testExample01() {
AlertBlock block = Alert.example01();
String actual = GsonFactory.createSnakeCase().toJson(block);
String expected = """
{
"type": "alert",
"text": {
"type": "mrkdwn",
"text": "The work is mysterious and important."
},
"level": "info"
}
""";
assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual));
}
}