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 @@ -13,6 +13,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
- **[Container](https://docs.slack.dev/reference/block-kit/blocks/container-block)**: A general-purpose wrapper for grouping child blocks together, with a configurable size. [Implementation](./src/main/java/blocks/Container.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 actions](https://docs.slack.dev/reference/block-kit/blocks/context-actions-block)**: Displays actions as contextual info, which can include both feedback buttons and icon buttons. [Implementation](./src/main/java/blocks/ContextActions.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
43 changes: 43 additions & 0 deletions block-kit/src/main/java/blocks/ContextActions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package blocks;

import com.slack.api.model.block.Blocks;
import com.slack.api.model.block.ContextActionsBlock;
import com.slack.api.model.block.composition.BlockCompositions;
import com.slack.api.model.block.composition.FeedbackButtonObject;
import com.slack.api.model.block.element.BlockElements;
import java.util.List;

/**
* Displays actions as contextual info, which can include both feedback buttons and icon buttons.
* {@link https://docs.slack.dev/reference/block-kit/blocks/context-actions-block/}
*/
public class ContextActions {
/**
* Context actions block with feedback buttons.
*/
public static ContextActionsBlock example01() {
ContextActionsBlock block = Blocks.contextActions(c ->
c.elements(List.of(BlockElements.feedbackButtons(f -> f.actionId("feedback_buttons_1")
.positiveButton(FeedbackButtonObject.builder()
.text(BlockCompositions.plainText("👍"))
.value("positive_feedback")
.build())
.negativeButton(FeedbackButtonObject.builder()
.text(BlockCompositions.plainText("👎"))
.value("negative_feedback")
.build())))));
return block;
}

/**
* Context actions block with an icon button.
*/
public static ContextActionsBlock example02() {
ContextActionsBlock block =
Blocks.contextActions(c -> c.elements(List.of(BlockElements.iconButton(i -> i.icon("trash")
.text(BlockCompositions.plainText("Delete"))
.actionId("delete_button_1")
.value("delete_item")))));
return block;
}
}
66 changes: 66 additions & 0 deletions block-kit/src/test/java/blocks/ContextActionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package blocks;

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

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

public class ContextActionsTest {
@Test
public void testExample01() {
ContextActionsBlock block = ContextActions.example01();
String actual = GsonFactory.createSnakeCase().toJson(block);
String expected = """
{
"type": "context_actions",
"elements": [
{
"type": "feedback_buttons",
"action_id": "feedback_buttons_1",
"positive_button": {
"text": {
"type": "plain_text",
"text": "👍"
},
"value": "positive_feedback"
},
"negative_button": {
"text": {
"type": "plain_text",
"text": "👎"
},
"value": "negative_feedback"
}
}
]
}
""";
assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual));
}

@Test
public void testExample02() {
ContextActionsBlock block = ContextActions.example02();
String actual = GsonFactory.createSnakeCase().toJson(block);
String expected = """
{
"type": "context_actions",
"elements": [
{
"type": "icon_button",
"icon": "trash",
"text": {
"type": "plain_text",
"text": "Delete"
},
"action_id": "delete_button_1",
"value": "delete_item"
}
]
}
""";
assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual));
}
}
Loading