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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.hubspot.slack.client.models.Metadata;
import java.util.Optional;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Default;

@JsonNaming(SnakeCaseStrategy.class)
public abstract class AbstractChatMessageParams implements MessageParams {
Expand All @@ -34,10 +36,22 @@ public abstract class AbstractChatMessageParams implements MessageParams {

public abstract Optional<Boolean> getUnfurlMedia();

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public abstract Optional<Boolean> getReplyBroadcast();

public abstract Optional<String> getParse();

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public abstract Optional<Metadata> getMetadata();

@Default
public Optional<Boolean> getMrkdwn() {
return Optional.of(true);
}

@Check
public void check() {
MessageParams.super.check();
Preconditions.checkState(
(getText().isPresent() && !Strings.isNullOrEmpty(getText().get())) ||
!getAttachments().isEmpty() ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.hubspot.slack.client.methods.params.chat;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.Metadata;
import java.util.Optional;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Default;
Expand Down Expand Up @@ -42,8 +44,16 @@ default String getThreadTs() {

Optional<Boolean> getUnfurlMedia();

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("reply_broadcast")
Optional<Boolean> getReplyAsBroadcast();

@JsonInclude(JsonInclude.Include.NON_EMPTY)
Optional<Metadata> getMetadata();

@Check
default void check() {
MessageParams.super.check();
Preconditions.checkState(
(getText().isPresent() && !Strings.isNullOrEmpty(getText().get())) ||
!getAttachments().isEmpty() ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.hubspot.slack.client.methods.params.chat;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.common.base.Preconditions;
import com.hubspot.slack.client.methods.interceptor.HasChannel;
import com.hubspot.slack.client.models.Attachment;
import com.hubspot.slack.client.models.blocks.Block;
import com.hubspot.slack.client.models.blocks.BlockElementLengthLimits;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.immutables.value.Value;
import org.immutables.value.Value.Check;

public interface MessageParams extends HasChannel {
Optional<String> getText();
Expand All @@ -17,4 +21,24 @@ public interface MessageParams extends HasChannel {
default List<Block> getBlocks() {
return Collections.emptyList();
}

@JsonInclude(JsonInclude.Include.NON_EMPTY)
Optional<String> getMarkdownText();

@Check
default void check() {
getMarkdownText()
.ifPresent(markdown -> {
Preconditions.checkState(
markdown.length() < BlockElementLengthLimits.MAX_MARKDOWN_LENGTH.getLimit(),
"Markdown text length exceeds the limit of " +
BlockElementLengthLimits.MAX_MARKDOWN_LENGTH.getLimit() +
" characters"
);
Preconditions.checkState(
getText().isEmpty() && getBlocks().isEmpty(),
"Cannot provide text or blocks when providing markdown text"
);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hubspot.slack.client.models;

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

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
public interface MetadataIF {
@Parameter(order = 0)
String getEventType();

@Parameter(order = 1)
Map<String, Object> getEventPayload();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
@JsonSubTypes.Type(value = Image.class, name = Image.TYPE),
@JsonSubTypes.Type(value = Input.class, name = Input.TYPE),
@JsonSubTypes.Type(value = Section.class, name = Section.TYPE),
@JsonSubTypes.Type(value = Markdown.class, name = Markdown.TYPE),
@JsonSubTypes.Type(value = RichText.class, name = RichText.TYPE),
@JsonSubTypes.Type(value = Video.class, name = Video.TYPE),
}
)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public enum BlockElementLengthLimits {
MAX_OPTION_GROUP_LABEL_LENGTH(75),
MAX_OPTION_VALUE_LENGTH(75),
MAX_CHECKBOXES_NUMBER(10),
MAX_RADIO_BUTTONS_NUMBER(10);
MAX_RADIO_BUTTONS_NUMBER(10),
MAX_VIDEO_AUTHOR_NAME_LENGTH(50),
MAX_VIDEO_DESCRIPTION_LENGTH(200),
MAX_MARKDOWN_LENGTH(12000);

private final int limit;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.hubspot.slack.client.models.blocks;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.google.common.base.Preconditions;
import com.hubspot.immutables.style.HubSpotStyle;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Derived;
import org.immutables.value.Value.Immutable;
import org.immutables.value.Value.Parameter;

@Immutable
@HubSpotStyle
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public interface MarkdownIF extends Block {
String TYPE = "markdown";

/**
* The type of block. For a markdown block, type is always markdown.
* <br/><br/>
* Type: String
* <br/>
* Required: true
*/
@Override
@Derived
default String getType() {
return TYPE;
}

/**
* The standard markdown-formatted text. Limit 12,000 characters max.
* <br/><br/>
* Type: String
* <br/>
* Required: true
*/
@Parameter
String getText();

@Check
default void check() {
Preconditions.checkState(
getText().length() < BlockElementLengthLimits.MAX_MARKDOWN_LENGTH.getLimit(),
"Text length must be less than " +
BlockElementLengthLimits.MAX_MARKDOWN_LENGTH.getLimit() +
" characters"
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.hubspot.slack.client.models.blocks;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.blocks.elements.richtext.RichTextBlock;
import java.util.List;
import org.immutables.value.Value.Derived;
import org.immutables.value.Value.Immutable;
import org.immutables.value.Value.Parameter;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
public interface RichTextIF extends Block {
String TYPE = "rich_text";

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

/**
* An array of rich text objects - rich_text_section, rich_text_list, rich_text_preformatted, and rich_text_quote.
* <br/><br/>
* Type: Object[] (List of RichTextBlock)
* <br/>
* Required: true
*/
@Parameter
List<RichTextBlock> getElements();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package com.hubspot.slack.client.models.blocks;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.google.common.base.Preconditions;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.blocks.objects.Text;
import com.hubspot.slack.client.models.blocks.objects.TextType;
import java.util.Optional;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Immutable;
import org.immutables.value.Value.Parameter;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
public interface VideoIF extends Block {
String TYPE = "video";

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

/**
* A tooltip for the video. Required for accessibility
* <br/><br/>
* Type: String
* <br/>
* Required: true
*/
@Parameter(order = 0)
String getAltText();

/**
* Author name to be displayed. Must be less than 50 characters.
* <br/><br/>
* Type: String
* <br/>
* Required: false
*/
Optional<String> getAuthorName();

/**
* Description for video in the form of a text object that must have type of plain_text. text within must be less than 200 characters.
* <br/><br/>
* Type: Object (Text)
* <br/>
* Required: false (preferred)
*/
Optional<Text> getDescription();

/**
* Icon for the video provider, e.g. YouTube icon.
* <br/><br/>
* Type: String
* <br/>
* Required: false
*/
Optional<String> getProviderIconUrl();

/**
* The originating application or domain of the video, e.g. YouTube
* <br/><br/>
* Type: String
* <br/>
* Required: false
*/
Optional<String> getProviderName();

/**
* Video title in the form of a text object that must have type of plain_text. text within must be less than 200 characters.
* <br/><br/>
* Type: Object (Text)
* <br/>
* Required: true
*/
@Parameter(order = 1)
Text getTitle();

/**
* Hyperlink for the title text. Must correspond to the non-embeddable URL for the video. Must go to an HTTPS URL.
* <br/><br/>
* Type: String
* <br/>
* Required: false (preferred)
*/
Optional<String> getTitleUrl();

/**
* The thumbnail image URL
* <br/><br/>
* Type: String
* <br/>
* Required: true
*/
@Parameter(order = 2)
String getThumbnailUrl();

/**
* The URL to be embedded. Must match any existing unfurl domains within the app and point to a HTTPS URL.
* <br/><br/>
* Type: String
* <br/>
* Required: true
*/
@Parameter(order = 3)
String getVideoUrl();

@Check
default void check() {
getAuthorName()
.ifPresent(name ->
Preconditions.checkState(
name.length() <
BlockElementLengthLimits.MAX_VIDEO_AUTHOR_NAME_LENGTH.getLimit(),
"Author name must be less than " +
BlockElementLengthLimits.MAX_VIDEO_AUTHOR_NAME_LENGTH.getLimit() +
" characters"
)
);
getDescription()
.ifPresent(description -> {
Preconditions.checkState(
description.getType() == TextType.PLAIN_TEXT,
"The description type of a Video block must be plain_text"
);
Preconditions.checkState(
description.getText().length() <
BlockElementLengthLimits.MAX_VIDEO_DESCRIPTION_LENGTH.getLimit(),
"Description length must be less than " +
BlockElementLengthLimits.MAX_VIDEO_DESCRIPTION_LENGTH.getLimit() +
" characters"
);
});

Preconditions.checkState(
getTitle().getType() == TextType.PLAIN_TEXT,
"The title type of a Video block must be plain_text"
);
Preconditions.checkState(
getTitle().getText().length() <
BlockElementLengthLimits.MAX_VIDEO_DESCRIPTION_LENGTH.getLimit(),
"Title length must be less than " +
BlockElementLengthLimits.MAX_VIDEO_DESCRIPTION_LENGTH.getLimit() +
" characters"
);

getTitleUrl()
.ifPresent(url ->
Preconditions.checkState(
url.toLowerCase().startsWith("https://"),
"Title url must go to a HTTPS URL"
)
);

Preconditions.checkState(
getVideoUrl().toLowerCase().startsWith("https://"),
"Video url must go to a HTTPS URL"
);
}
}
Loading