Apply accessory image
This commit is contained in:
@@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.dto.SlackBaseMessageBlock;
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.dto.SlackMessageDTO;
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.dto.SlackSectionMessageBlock;
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.infrastructure.client.MongeShoppingBotSlackMessageSender;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.APIResponse;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.BlockMessageDTO;
|
||||
@@ -46,7 +45,7 @@ public class MessageSenderAPIController {
|
||||
return Mono.just(APIResponse.fail(dto, "empty blocks"));
|
||||
}
|
||||
SlackMessageDTO slackMessageDTO = sender.ofBlockMessageBased();
|
||||
dto.getBlocks().forEach(slackMessageDTO::addBlock);
|
||||
dto.getBlocks().forEach(slackMessageDTO::addSectionBlock);
|
||||
slackMessageDTO.addBlock(SlackBaseMessageBlock.ofDivider());
|
||||
|
||||
return sender.sendMessage(slackMessageDTO)
|
||||
|
||||
@@ -40,6 +40,7 @@ public class SlackBaseMessageBlock implements SlackMessageBlock {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type.getType();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.sender.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* SlackImageMessageBlock
|
||||
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
||||
* @since 2021-11-30
|
||||
*
|
||||
*/
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SlackImageMessageBlock implements SlackMessageBlock {
|
||||
private static final long serialVersionUID = 1597984001727808419L;
|
||||
|
||||
private SlackMessageBlockType type;
|
||||
|
||||
@JsonProperty(value = "image_url", required = true)
|
||||
private String imageUrl;
|
||||
|
||||
@JsonProperty(value = "alt_text", required = true)
|
||||
private String altText;
|
||||
|
||||
@Builder
|
||||
private SlackImageMessageBlock(SlackMessageBlockType type, String imageUrl, String altText) {
|
||||
this.type = type;
|
||||
this.imageUrl = imageUrl;
|
||||
this.altText = altText;
|
||||
}
|
||||
|
||||
public static SlackImageMessageBlock of(String imageUrl, String altText) {
|
||||
return SlackImageMessageBlock.builder()
|
||||
.type(SlackMessageBlockType.IMAGE)
|
||||
.imageUrl(imageUrl)
|
||||
.altText(altText)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type.getType();
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,7 @@ import java.io.Serializable;
|
||||
*
|
||||
*/
|
||||
public interface SlackMessageBlock extends Serializable {
|
||||
|
||||
String getType();
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public enum SlackMessageBlockType {
|
||||
SECTION("section"),
|
||||
MARKDOWN("mrkdwn"),
|
||||
DIVIDER("divider"),
|
||||
IMAGE("image"),
|
||||
;
|
||||
|
||||
private String type;
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
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;
|
||||
@@ -44,8 +46,10 @@ public class SlackMessageDTO implements MessageDTO {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void addBlock(String blockRawMessage) {
|
||||
addBlock(SlackSectionMessageBlock.ofMarkDown(blockRawMessage));
|
||||
public void addSectionBlock(BlockMessageDTO.Block block) {
|
||||
SlackSectionMessageBlock slackSectionMessageBlock = SlackSectionMessageBlock.ofMarkDown(block.getText());
|
||||
slackSectionMessageBlock.applyImageaccessory(block.getImageUrl(), block.getAltText());
|
||||
addBlock(slackSectionMessageBlock);
|
||||
}
|
||||
|
||||
public void addBlock(SlackMessageBlock block) {
|
||||
|
||||
@@ -20,11 +20,14 @@ public class SlackSectionMessageBlock implements SlackMessageBlock {
|
||||
|
||||
private SlackMessageBlockType type;
|
||||
private SlackBaseMessageBlock text;
|
||||
private SlackImageMessageBlock accessory;
|
||||
|
||||
@Builder
|
||||
private SlackSectionMessageBlock(SlackMessageBlockType type, SlackBaseMessageBlock text) {
|
||||
private SlackSectionMessageBlock(SlackMessageBlockType type, SlackBaseMessageBlock text,
|
||||
SlackImageMessageBlock accessory) {
|
||||
this.type = type;
|
||||
this.text = text;
|
||||
this.accessory = accessory;
|
||||
}
|
||||
|
||||
public static SlackSectionMessageBlock ofMarkDown(String message) {
|
||||
@@ -34,6 +37,12 @@ public class SlackSectionMessageBlock implements SlackMessageBlock {
|
||||
.build();
|
||||
}
|
||||
|
||||
public SlackSectionMessageBlock applyImageaccessory(String imageUrl, String altText) {
|
||||
this.accessory = SlackImageMessageBlock.of(imageUrl, altText);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type.getType();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user