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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
value = ContextActionsBlock.class,
name = ContextActionsBlock.TYPE
),
@JsonSubTypes.Type(value = Card.class, name = Card.TYPE),
@JsonSubTypes.Type(value = Table.class, name = Table.TYPE),
@JsonSubTypes.Type(value = DataTable.class, name = DataTable.TYPE),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public enum BlockElementLengthLimits {
MAX_OPTION_VALUE_LENGTH(75),
MAX_CHECKBOXES_NUMBER(10),
MAX_RADIO_BUTTONS_NUMBER(10),
MAX_CARD_TITLE_LENGTH(150),
MAX_CARD_BODY_LENGTH(200),
MAX_CARD_ACTIONS_COUNT(3),
MAX_CARD_BLOCK_ID_LENGTH(255),
MAX_TABLE_ROWS(100),
MAX_TABLE_COLUMNS(20),
MAX_TABLE_BLOCK_ID_LENGTH(255),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.hubspot.slack.client.models.blocks;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.blocks.elements.BlockElement;
import com.hubspot.slack.client.models.blocks.elements.Image;
import com.hubspot.slack.client.models.blocks.objects.SlackIconObject;
import com.hubspot.slack.client.models.blocks.objects.Text;
import java.util.Optional;
import org.immutables.value.Value;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface CardIF extends Block {
String TYPE = "card";

@Override
@Value.Derived
default String getType() {
return TYPE;
}

Optional<Image> getHeroImage();
Comment thread
VictorHLi404 marked this conversation as resolved.

Optional<Image> getIcon();

Optional<Text> getTitle();

Optional<Text> getSubtitle();

Optional<Text> getBody();

Optional<Text> getSubtext();

ImmutableList<BlockElement> getActions();

Optional<SlackIconObject> getSlackIcon();

@Check
default void check() {
Preconditions.checkState(
getHeroImage().isPresent() ||
getTitle().isPresent() ||
!getActions().isEmpty() ||
getBody().isPresent(),
"A card block must have at least one of: hero_image, title, actions, or body"
);
Preconditions.checkState(
!(getIcon().isPresent() && getSlackIcon().isPresent()),
"A card block cannot have both icon and slack_icon"
);
getTitle()
.ifPresent(title ->
Preconditions.checkState(
title.getText().length() <=
BlockElementLengthLimits.MAX_CARD_TITLE_LENGTH.getLimit(),
"title cannot exceed %s characters",
BlockElementLengthLimits.MAX_CARD_TITLE_LENGTH.getLimit()
)
);
getSubtitle()
.ifPresent(subtitle ->
Preconditions.checkState(
subtitle.getText().length() <=
BlockElementLengthLimits.MAX_CARD_TITLE_LENGTH.getLimit(),
"subtitle cannot exceed %s characters",
BlockElementLengthLimits.MAX_CARD_TITLE_LENGTH.getLimit()
)
);
getBody()
.ifPresent(body ->
Preconditions.checkState(
body.getText().length() <=
BlockElementLengthLimits.MAX_CARD_BODY_LENGTH.getLimit(),
"body cannot exceed %s characters",
BlockElementLengthLimits.MAX_CARD_BODY_LENGTH.getLimit()
)
);
getSubtext()
.ifPresent(subtext ->
Preconditions.checkState(
subtext.getText().length() <=
BlockElementLengthLimits.MAX_CARD_BODY_LENGTH.getLimit(),
"subtext cannot exceed %s characters",
BlockElementLengthLimits.MAX_CARD_BODY_LENGTH.getLimit()
)
);
Preconditions.checkState(
getActions().size() <= BlockElementLengthLimits.MAX_CARD_ACTIONS_COUNT.getLimit(),
"A card block cannot have more than %s actions",
BlockElementLengthLimits.MAX_CARD_ACTIONS_COUNT.getLimit()
);
getBlockId()
.ifPresent(blockId ->
Preconditions.checkState(
blockId.length() <=
BlockElementLengthLimits.MAX_CARD_BLOCK_ID_LENGTH.getLimit(),
"block_id cannot exceed %s characters",
BlockElementLengthLimits.MAX_CARD_BLOCK_ID_LENGTH.getLimit()
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.hubspot.slack.client.models.blocks.objects;

import com.fasterxml.jackson.annotation.JsonValue;

/**
* Icon names derived from @<a href="https://docs.slack.dev/reference/block-kit/composition-objects/slack-icon-object">slack docs</a>
*/
public enum SlackIconName {
ARCHIVE("archive"),
BOOK("book"),
BOOKMARK("bookmark"),
BOT("bot"),
BUG("bug"),
CALENDAR("calendar"),
CALL("call"),
CARET_LEFT("caret-left"),
CARET_RIGHT("caret-right"),
CHECK("check"),
CLIPBOARD("clipboard"),
CODE("code"),
COMMENT("comment"),
COMPASS("compass"),
COPY("copy"),
CUBE("cube"),
DOWNLOAD("download"),
EDIT("edit"),
EMAIL("email"),
EYE_CLOSED("eye-closed"),
EYE_OPEN("eye-open"),
FILE("file"),
FLAG("flag"),
FOLDER("folder"),
GEAR("gear"),
GLOBE("globe"),
HEART("heart"),
HELP("help"),
IMAGE("image"),
INFO("info"),
KEY("key"),
LIGHTBULB("lightbulb"),
LINK("link"),
MAP("map"),
MOBILE("mobile"),
NEW_WINDOW("new-window"),
PIN("pin"),
PLUS("plus"),
REFINE("refine"),
REFRESH("refresh"),
ROCKET("rocket"),
SAVE("save"),
SCREEN("screen"),
SHARE("share"),
SPARKLE("sparkle"),
STAR("star"),
STAR_FILLED("star-filled"),
TAG("tag"),
THUMBS_DOWN("thumbs-down"),
THUMBS_UP("thumbs-up"),
TRASH("trash"),
UPLOAD("upload"),
USER("user"),
WARNING("warning");

private final String value;

SlackIconName(String value) {
this.value = value;
}

@JsonValue
public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.hubspot.slack.client.models.blocks.objects;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import org.immutables.value.Value;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
public interface SlackIconObjectIF extends CompositionObject {
String TYPE = "icon";

@Value.Derived
default String getType() {
return TYPE;
}

@Value.Parameter
SlackIconName getName();
}
Loading