Skip to content
Draft
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 @@ -10,6 +10,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes

- **[Actions](https://docs.slack.dev/reference/block-kit/blocks/actions-block)**: Holds multiple interactive elements. [Implementation](./src/main/java/blocks/Actions.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).
- **[Context actions](https://docs.slack.dev/reference/block-kit/blocks/context-actions-block)**: Displays interactive elements at the message level. [Implementation](./src/main/java/blocks/ContextActions.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).
- **[Header](https://docs.slack.dev/reference/block-kit/blocks/header-block)**: Displays a larger-sized text. [Implementation](./src/main/java/blocks/Header.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 interactive elements at the message level.
* {@link https://docs.slack.dev/reference/block-kit/blocks/context-actions-block/}
*/
public class ContextActions {
/**
* A 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;
}

/**
* A 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