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
@@ -0,0 +1,41 @@
package com.slack.api.model.block;

import com.slack.api.model.block.composition.TextObject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* https://docs.slack.dev/reference/block-kit/blocks/alert-block
* <p>
* Displays an inline alert message. Alert blocks are currently only supported in modals.
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AlertBlock implements LayoutBlock {
public static final String TYPE = "alert";
private final String type = TYPE;

/**
* The message content of the alert, as a plain_text or mrkdwn text object.
* Maximum length for the text in this field is 200 characters.
*/
private TextObject text;

/**
* The severity level of the alert. One of default, info, warning, error, or success.
* Will be default if omitted.
*/
private String level;

/**
* A string acting as a unique identifier for a block. If not specified, one will be generated.
* Maximum length for this field is 255 characters.
* block_id should be unique for each message and each iteration of a message.
* If a message is updated, use a new block_id.
*/
private String blockId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,22 @@ public static ShareShortcutBlock shareShortcut() {
return ShareShortcutBlock.builder().build();
}

// AlertBlock

public static AlertBlock alert(ModelConfigurator<AlertBlock.AlertBlockBuilder> configurator) {
return configurator.configure(AlertBlock.builder()).build();
}

// CardBlock

public static CardBlock card(ModelConfigurator<CardBlock.CardBlockBuilder> configurator) {
return configurator.configure(CardBlock.builder()).build();
}

// CarouselBlock

public static CarouselBlock carousel(ModelConfigurator<CarouselBlock.CarouselBlockBuilder> configurator) {
return configurator.configure(CarouselBlock.builder()).build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.slack.api.model.block;

import com.slack.api.model.block.composition.SlackIconObject;
import com.slack.api.model.block.composition.TextObject;
import com.slack.api.model.block.element.BlockElement;
import com.slack.api.model.block.element.ImageElement;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* A card is a layout block used to display a compact, structured summary of content. It can be used on
* its own or grouped together inside a {@link CarouselBlock carousel}. At least one of {@code heroImage},
* {@code title}, {@code actions}, or {@code body} must be provided.
*
* https://docs.slack.dev/reference/block-kit/blocks/card-block
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CardBlock implements LayoutBlock {
public static final String TYPE = "card";
private final String type = TYPE;

/**
* A top banner image for the card in the form of an image element.
* The image URL may be up to 3000 characters and the alt text up to 2000 characters.
*/
private ImageElement heroImage;

/**
* A small icon displayed next to the title and subtitle in the form of an image element.
* The image URL may be up to 3000 characters and the alt text up to 2000 characters.
* Mutually exclusive with {@code slackIcon}.
*/
private ImageElement icon;

/**
* A built-in Slack icon displayed next to the title and subtitle.
* Mutually exclusive with {@code icon}.
*/
private SlackIconObject slackIcon;

/**
* The title of the card. Maximum length for the text in this field is 150 characters.
*/
private TextObject title;

/**
* The subtitle of the card. Maximum length for the text in this field is 150 characters.
*/
private TextObject subtitle;

/**
* The body text of the card. Maximum length for the text in this field is 200 characters.
*/
private TextObject body;

/**
* Secondary text displayed beneath the body of the card. Maximum length for the text in this field
* is 200 characters.
*/
private TextObject subtext;

/**
* Interactive elements (such as buttons) displayed at the bottom of the card. Up to 3 buttons.
*/
private List<BlockElement> actions;

private String blockId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.slack.api.model.block;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* A carousel is a layout block used to display a horizontally scrollable collection of
* {@link CardBlock cards}. It must contain between 1 and 10 cards.
*
* https://docs.slack.dev/reference/block-kit/blocks/carousel-block
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CarouselBlock implements LayoutBlock {
public static final String TYPE = "carousel";
private final String type = TYPE;

/**
* An array of {@link CardBlock card} blocks. Must contain between 1 and 10 cards.
*/
private List<CardBlock> elements;

private String blockId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,14 @@ public static FeedbackButtonObject feedbackButton(ModelConfigurator<FeedbackButt
public static SlackFileObject slackFile(ModelConfigurator<SlackFileObject.SlackFileObjectBuilder> configurator) {
return configurator.configure(SlackFileObject.builder()).build();
}

// SlackIconObject

public static SlackIconObject slackIcon(ModelConfigurator<SlackIconObject.SlackIconObjectBuilder> configurator) {
return configurator.configure(SlackIconObject.builder()).build();
}

public static SlackIconObject slackIcon(String name) {
return SlackIconObject.builder().name(name).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.slack.api.model.block.composition;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* Defines a built-in Slack icon that can be displayed next to the title and subtitle of a card block.
*
* @see <a href="https://docs.slack.dev/reference/block-kit/composition-objects/slack-icon-object">document</a>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SlackIconObject {
public static final String TYPE = "icon";
private final String type = TYPE;

/**
* The name of the built-in Slack icon.
*/
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ private Class<? extends LayoutBlock> getLayoutClassInstance(String typeName) {
return RichTextBlock.class;
case ShareShortcutBlock.TYPE:
return ShareShortcutBlock.class;
case AlertBlock.TYPE:
return AlertBlock.class;
case CardBlock.TYPE:
return CardBlock.class;
case CarouselBlock.TYPE:
return CarouselBlock.class;
Comment on lines +64 to +69

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice 🚀

default:
if (failOnUnknownProperties) {
throw new JsonParseException("Unsupported layout block type: " + typeName);
Expand Down
Loading
Loading