Prettify section message
This commit is contained in:
@@ -51,7 +51,7 @@ public class CrawlAPIController {
|
||||
.map(e -> ppomppuArticleService.filterOnlyNewArticles(boardName, e))
|
||||
.map(e -> ppomppuArticleService.save(boardName, e))
|
||||
.filter(e -> !e.isEmpty())
|
||||
.flatMap(messageSenderService::sendBlockMessageToSlack);
|
||||
.flatMap(e -> messageSenderService.sendBlockMessageToSlack(boardName, e));
|
||||
|
||||
return publishedMessages.then(Mono.just(APIResponse.success(result.done())));
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class CrawlAPIController {
|
||||
log.info("got request... {}", boardName);
|
||||
Mono<String> publishedMessages =
|
||||
ppomppuRSSFeedService.getArticles(boardName)
|
||||
.flatMap(messageSenderService::sendBlockMessageToSlack);
|
||||
.flatMap(e -> messageSenderService.sendBlockMessageToSlack(boardName, e));
|
||||
|
||||
return publishedMessages.map(APIResponse::success);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class PpomppuArticleParser {
|
||||
}
|
||||
|
||||
public static String parseTitle(Element td) {
|
||||
return td.getElementsByTag("a").text(); // TODO cdn image extracting
|
||||
return td.getElementsByTag("a").text();
|
||||
}
|
||||
|
||||
public static String parseArticleUrl(Element td) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.stream.Collectors;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
||||
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.dto.code.PpomppuBoardName;
|
||||
|
||||
/**
|
||||
* PpomppuArticleTransformer
|
||||
@@ -22,6 +23,8 @@ public final class PpomppuArticleTransformer {
|
||||
private PpomppuArticleTransformer() {}
|
||||
|
||||
private static final String MESSAGE_FORMAT_V1 = "%s)) <%s|LINK> `%s` ";
|
||||
private static final String MESSAGE_FORMAT_V2 = "%s *<%s|LINK>*\n%s";
|
||||
private static final String TITLE_FORMAT_V1 = "_*:hearts: %s | %s*_";
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
.withZone(ZoneId.of("Asia/Seoul"));
|
||||
@@ -49,7 +52,7 @@ public final class PpomppuArticleTransformer {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static BlockMessageDTO transformToBlockMessage(List<PpomppuArticle> articles) {
|
||||
public static BlockMessageDTO transformToBlockMessage(PpomppuBoardName boardName, List<PpomppuArticle> articles) {
|
||||
Instant requestedAt = Instant.now();
|
||||
List<BlockMessageDTO.Block> body = articles.stream()
|
||||
.map(e -> BlockMessageDTO.createBlock(convertToInlineMessage(e),
|
||||
@@ -57,13 +60,15 @@ public final class PpomppuArticleTransformer {
|
||||
.collect(Collectors.toList());
|
||||
return BlockMessageDTO.builder()
|
||||
.requestedAt(requestedAt)
|
||||
.title(DATE_TIME_FORMATTER.format(requestedAt))
|
||||
.title(String.format(TITLE_FORMAT_V1,
|
||||
boardName.getMenuName(),
|
||||
DATE_TIME_FORMATTER.format(requestedAt)))
|
||||
.blocks(body)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String convertToInlineMessage(PpomppuArticle article) {
|
||||
return String.format(MESSAGE_FORMAT_V1,
|
||||
return String.format(MESSAGE_FORMAT_V2,
|
||||
article.getBoardName().getMenuName(), article.getArticleUrl(), article.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.dto.PpomppuArticleTransformer;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.infrastructure.client.MessageSenderAPIClient;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -35,8 +36,9 @@ public class MessageSenderService {
|
||||
return messageSenderAPIClient.sendSimpleMessageToSlack(PpomppuArticleTransformer.transformToSimpleMessage(articles));
|
||||
}
|
||||
|
||||
public Mono<String> sendBlockMessageToSlack(List<PpomppuArticle> articles) {
|
||||
return messageSenderAPIClient.sendBlockMessageToSlack(PpomppuArticleTransformer.transformToBlockMessage(articles));
|
||||
public Mono<String> sendBlockMessageToSlack(PpomppuBoardName boardName, List<PpomppuArticle> articles) {
|
||||
return messageSenderAPIClient.sendBlockMessageToSlack(
|
||||
PpomppuArticleTransformer.transformToBlockMessage(boardName, articles));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user