[NO-ISSUE] Fix bug
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.sender.controller;
|
||||
|
||||
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.SimpleMessageDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
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;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.SimpleMessageDTO;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.util.ObjectMapperFactory;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
@@ -27,9 +34,24 @@ public class MessageSenderAPIController {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@PostMapping("/messages/sendMessage/messengers/slack")
|
||||
public Mono<APIResponse<SimpleMessageDTO>> sendMessageToSlack(@RequestBody SimpleMessageDTO dto) {
|
||||
@PostMapping("/messages/sendSimpleMessage/messengers/slack")
|
||||
public Mono<APIResponse<SimpleMessageDTO>> sendSimpleMessageToSlack(@RequestBody SimpleMessageDTO dto) {
|
||||
return sender.sendMessage(sender.ofMessage(dto.getBody()))
|
||||
.then(Mono.just(APIResponse.success(dto)));
|
||||
}
|
||||
|
||||
@PostMapping("/messages/sendBlockMessage/messengers/slack")
|
||||
public Mono<APIResponse<BlockMessageDTO>> sendBlockMessageToSlack(@RequestBody BlockMessageDTO dto) {
|
||||
if (dto.getBlocks().isEmpty()) {
|
||||
return Mono.just(APIResponse.fail(dto, "empty blocks"));
|
||||
}
|
||||
SlackMessageDTO slackMessageDTO = sender.ofBlockMessageBased();
|
||||
dto.getBlocks().forEach(slackMessageDTO::addBlock);
|
||||
slackMessageDTO.addBlock(SlackBaseMessageBlock.ofDivider());
|
||||
|
||||
return sender.sendMessage(slackMessageDTO)
|
||||
.doOnNext(e -> log.info("[sendBlockMessageToSlack] slackMessageDTO: {}",
|
||||
ObjectMapperFactory.writeAsString(slackMessageDTO)))
|
||||
.then(Mono.just(APIResponse.success(dto)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.sender.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import lombok.Builder;
|
||||
@@ -17,29 +15,29 @@ import lombok.NoArgsConstructor;
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SlackMessageBlock implements Serializable {
|
||||
public class SlackBaseMessageBlock implements SlackMessageBlock {
|
||||
private static final long serialVersionUID = 1597984001727808419L;
|
||||
|
||||
private SlackMessageBlockType type;
|
||||
private String text;
|
||||
|
||||
@Builder
|
||||
private SlackMessageBlock(SlackMessageBlockType type, String text) {
|
||||
private SlackBaseMessageBlock(SlackMessageBlockType type, String text) {
|
||||
this.type = type;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static SlackMessageBlock ofMarkDown(String message) {
|
||||
return SlackMessageBlock.builder()
|
||||
.type(SlackMessageBlockType.MARKDOWN)
|
||||
.text(message)
|
||||
.build();
|
||||
public static SlackBaseMessageBlock ofMarkDown(String message) {
|
||||
return SlackBaseMessageBlock.builder()
|
||||
.type(SlackMessageBlockType.MARKDOWN)
|
||||
.text(message)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static SlackMessageBlock ofDivider() {
|
||||
return SlackMessageBlock.builder()
|
||||
.type(SlackMessageBlockType.DIVIDER)
|
||||
.build();
|
||||
public static SlackBaseMessageBlock ofDivider() {
|
||||
return SlackBaseMessageBlock.builder()
|
||||
.type(SlackMessageBlockType.DIVIDER)
|
||||
.build();
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.sender.dto;/**
|
||||
package com.myoa.engineering.crawl.ppomppu.sender.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* SlackMessageBlock
|
||||
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
||||
* @since 2021-12-01
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface SlackMessageBlock {
|
||||
public interface SlackMessageBlock extends Serializable {
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum BlockType {
|
||||
public enum SlackMessageBlockType {
|
||||
SECTION("section"),
|
||||
MARKDOWN("mrkdwn"),
|
||||
DIVIDER("divider"),
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.sender.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Builder;
|
||||
@@ -14,6 +17,7 @@ import lombok.NoArgsConstructor;
|
||||
*/
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SlackMessageDTO implements MessageDTO {
|
||||
|
||||
private final static long serialVersionUID = 4737608709660494713L;
|
||||
@@ -21,19 +25,31 @@ public class SlackMessageDTO implements MessageDTO {
|
||||
private String text;
|
||||
private String channel;
|
||||
private String username;
|
||||
private List<SlackMessageBlock> blocks;
|
||||
|
||||
@JsonProperty("icon_emoji")
|
||||
private String iconEmoji;
|
||||
|
||||
@Builder
|
||||
public SlackMessageDTO(String text, String channel, String username, String iconEmoji) {
|
||||
public SlackMessageDTO(String text, String channel, String username,
|
||||
List<SlackMessageBlock> blocks, String iconEmoji) {
|
||||
this.text = text;
|
||||
this.channel = channel;
|
||||
this.username = username;
|
||||
this.blocks = blocks;
|
||||
this.iconEmoji = iconEmoji;
|
||||
}
|
||||
|
||||
public void applyText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void addBlock(String blockRawMessage) {
|
||||
addBlock(SlackSectionMessageBlock.ofMarkDown(blockRawMessage));
|
||||
}
|
||||
|
||||
public void addBlock(SlackMessageBlock block) {
|
||||
blocks.add(block);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.sender.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import lombok.Builder;
|
||||
@@ -17,30 +15,23 @@ import lombok.NoArgsConstructor;
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SlackSectionBlock implements Serializable {
|
||||
public class SlackSectionMessageBlock implements SlackMessageBlock {
|
||||
private static final long serialVersionUID = -7600944576753160168L;
|
||||
|
||||
private SlackMessageBlockType type;
|
||||
private SlackMessageBlock text;
|
||||
private SlackBaseMessageBlock text;
|
||||
|
||||
@Builder
|
||||
private SlackSectionBlock(SlackMessageBlockType type, SlackMessageBlock text) {
|
||||
private SlackSectionMessageBlock(SlackMessageBlockType type, SlackBaseMessageBlock text) {
|
||||
this.type = type;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static SlackSectionBlock ofMarkDown(String message) {
|
||||
return SlackSectionBlock.builder()
|
||||
.type(SlackMessageBlockType.SECTION)
|
||||
.text(SlackMessageBlock.ofMarkDown(message))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static SlackSectionBlock ofDivider() {
|
||||
return SlackSectionBlock.builder()
|
||||
.type(SlackMessageBlockType.SECTION)
|
||||
.text(SlackMessageBlock.ofDivider())
|
||||
.build();
|
||||
public static SlackSectionMessageBlock ofMarkDown(String message) {
|
||||
return SlackSectionMessageBlock.builder()
|
||||
.type(SlackMessageBlockType.SECTION)
|
||||
.text(SlackBaseMessageBlock.ofMarkDown(message))
|
||||
.build();
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.sender.infrastructure.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.configuration.properties.SlackSecretProperties;
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.configuration.properties.SlackSecretProperties.SlackSecretPropertiesUnit;
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.dto.SlackMessageDTO;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -35,4 +39,14 @@ public class MongeShoppingBotSlackMessageSender extends SlackMessageSender {
|
||||
.text(text)
|
||||
.build();
|
||||
}
|
||||
|
||||
public SlackMessageDTO ofBlockMessageBased() {
|
||||
return SlackMessageDTO.builder()
|
||||
.channel(slackProperties.getChannel())
|
||||
.iconEmoji(slackProperties.getIconEmoji())
|
||||
.username(slackProperties.getUsername())
|
||||
.blocks(new ArrayList<>())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class SlackMessageSender implements MessageSender<SlackMessageDTO> {
|
||||
.exchangeStrategies(WebFluxExchangeStragiesFactory.ofDefault())
|
||||
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
.defaultHeader(HttpHeaders.ACCEPT_CHARSET, "UTF-8")
|
||||
.filter(WebClientFilterFactory.logRequest())
|
||||
.filter(WebClientFilterFactory.logResponse())
|
||||
.build();
|
||||
}
|
||||
@@ -47,7 +48,8 @@ public class SlackMessageSender implements MessageSender<SlackMessageDTO> {
|
||||
.onErrorResume(WebClientRequestException.class, t -> {
|
||||
log.info("Exception occured, ignoring. : {}", t.getClass().getSimpleName());
|
||||
return Mono.empty();
|
||||
});
|
||||
})
|
||||
.doOnNext(e -> log.info("[sendMessage] {}", e));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,4 +22,4 @@ management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: refresh, env
|
||||
include: refresh,health
|
||||
|
||||
Reference in New Issue
Block a user