Skip to content
Merged
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).
- **[Carousel](https://docs.slack.dev/reference/block-kit/blocks/carousel-block)**: Displays related card blocks in a horizontally-scrolling container. [Implementation](./src/main/java/blocks/Carousel.java).
- **[Card](https://docs.slack.dev/reference/block-kit/blocks/card-block)**: Displays content in a card. [Implementation](./src/main/java/blocks/Card.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).
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 block.
*/
public static AlertBlock example01() {
AlertBlock block =
Blocks.alert(a -> a.text(BlockCompositions.markdownText("The work is mysterious and important."))
.level("info"));
Comment on lines +17 to +18

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦆 praise: Indeed it said.

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."
},
Comment on lines +18 to +21

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁️‍🗨️ question: I notice the verbatim field from plain JSON example isn't included here or in earlier changes of python which makes me wonder if it's another field of mrkdwn text for follow up?

🔗 https://github.com/slack-samples/bolt-python-examples/blob/2f3a1b70c08c5d794c93b5dce602795098b343e1/block-kit/tests/blocks/test_alert.py#L6

"level": "info"
}
""";
assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual));
}
}