ShoppingCrawler/sender/src/main/java/com/myoa/engineering/crawl/ppomppu/sender/dto/SlackMessageDTO.java

63 lines
1.8 KiB
Java
Raw Normal View History

package com.myoa.engineering.crawl.ppomppu.sender.dto;
2021-11-30 16:16:15 +00:00
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
2021-12-03 16:07:42 +00:00
import com.myoa.engineering.crawl.ppomppu.support.dto.BlockMessageDTO;
import com.myoa.engineering.crawl.ppomppu.support.dto.BlockMessageDTO.Block;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* SlackMessageDTO
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
* @since 2021-11-14
*
*/
@Getter
@NoArgsConstructor
2021-11-30 16:16:15 +00:00
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SlackMessageDTO implements MessageDTO {
private final static long serialVersionUID = 4737608709660494713L;
private String text;
private String channel;
private String username;
2021-11-30 16:16:15 +00:00
private List<SlackMessageBlock> blocks;
@JsonProperty("icon_emoji")
private String iconEmoji;
@Builder
2021-11-30 16:16:15 +00:00
public SlackMessageDTO(String text, String channel, String username,
List<SlackMessageBlock> blocks, String iconEmoji) {
this.text = text;
this.channel = channel;
this.username = username;
2021-11-30 16:16:15 +00:00
this.blocks = blocks;
this.iconEmoji = iconEmoji;
}
2021-11-21 11:53:20 +00:00
public void applyText(String text) {
this.text = text;
}
2021-11-30 16:16:15 +00:00
2021-12-03 16:07:42 +00:00
public void addSectionBlock(BlockMessageDTO.Block block) {
SlackSectionMessageBlock slackSectionMessageBlock = SlackSectionMessageBlock.ofMarkDown(block.getText());
slackSectionMessageBlock.applyImageaccessory(block.getImageUrl(), block.getAltText());
addBlock(slackSectionMessageBlock);
2021-11-30 16:16:15 +00:00
}
2021-12-03 16:29:32 +00:00
public void addSectionBlock(String rawBlockMessage) {
addBlock(SlackSectionMessageBlock.ofMarkDown(rawBlockMessage));
}
2021-11-30 16:16:15 +00:00
public void addBlock(SlackMessageBlock block) {
blocks.add(block);
}
}