All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.blazar.externalservice.slack.SlackMessage Maven / Gradle / Ivy

The newest version!
package com.hubspot.blazar.externalservice.slack;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;

public class SlackMessage {
  private static final Optional ABSENT_STRING = Optional.absent();
  private final Optional token;
  private final Optional text;
  private final Optional username;
  private final Optional iconEmoji;
  private final String channel;
  private final List attachments;

  @JsonCreator
  public SlackMessage(
      @JsonProperty("token") Optional token,
      @JsonProperty("text") Optional text,
      @JsonProperty("username") Optional username,
      @JsonProperty("icon_emoji") Optional iconEmoji,
      @JsonProperty("channel") String channel,
      @JsonProperty("attachments") List attachments) {

    this.token = Objects.firstNonNull(token, ABSENT_STRING);
    this.text = Objects.firstNonNull(text, ABSENT_STRING);
    this.username = Objects.firstNonNull(username, ABSENT_STRING);
    this.iconEmoji = iconEmoji;
    this.channel = channel;
    this.attachments = attachments;
  }

  public Optional getToken() {
    return token;
  }

  public Optional getText() {
    return text;
  }

  public Optional getUsername() {
    return username;
  }

  @JsonProperty("icon_emoji")
  public Optional getIconEmoji() {
    return iconEmoji;
  }

  public String getChannel() {
    return channel;
  }

  public List getAttachments() {
    return attachments;
  }

  public SlackMessage cloneWithToken(String token) {
    return new SlackMessage(Optional.of(token), text, username, iconEmoji, channel, ImmutableList.copyOf(attachments));
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(this)
        .add("text", text)
        .add("username", username)
        .add("iconEmoji", iconEmoji)
        .add("channel", channel)
        .add("attachments", attachments)
        .toString();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy