diff --git a/block-kit/README.md b/block-kit/README.md index 3cd3768..77114fa 100644 --- a/block-kit/README.md +++ b/block-kit/README.md @@ -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). diff --git a/block-kit/src/main/java/blocks/Alert.java b/block-kit/src/main/java/blocks/Alert.java new file mode 100644 index 0000000..ea75d7d --- /dev/null +++ b/block-kit/src/main/java/blocks/Alert.java @@ -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; + } +} diff --git a/block-kit/src/test/java/blocks/AlertTest.java b/block-kit/src/test/java/blocks/AlertTest.java new file mode 100644 index 0000000..4185b99 --- /dev/null +++ b/block-kit/src/test/java/blocks/AlertTest.java @@ -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)); + } +}