-
Notifications
You must be signed in to change notification settings - Fork 3
feat: [NDGL-135] 사용자 컨텐츠 요청 시 디스코드 알림 전송 #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
WooJJam
merged 5 commits into
develop
from
feature/NDGL-135-Server-사용자-컨텐츠-요청-시-discord-알림-전송
May 13, 2026
The head ref may contain hidden characters: "feature/NDGL-135-Server-\uC0AC\uC6A9\uC790-\uCEE8\uD150\uCE20-\uC694\uCCAD-\uC2DC-discord-\uC54C\uB9BC-\uC804\uC1A1"
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ava/com/yapp/ndgl/application/domains/travel/event/UserSuggestedTemplateCreatedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.yapp.ndgl.application.domains.travel.event; | ||
|
|
||
| public record UserSuggestedTemplateCreatedEvent( | ||
| Long templateId, | ||
| String videoId, | ||
| String videoLink, | ||
| String suggesterUuid, | ||
| String category, | ||
| String region, | ||
| String recommendReason | ||
| ) { | ||
| } |
80 changes: 80 additions & 0 deletions
80
...ava/com/yapp/ndgl/application/domains/travel/event/UserSuggestedTemplateNotification.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package com.yapp.ndgl.application.domains.travel.event; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.List; | ||
|
|
||
| import org.springframework.util.StringUtils; | ||
|
|
||
| import com.yapp.ndgl.clients.discord.DiscordChannel; | ||
| import com.yapp.ndgl.clients.discord.DiscordNotification; | ||
| import com.yapp.ndgl.clients.discord.DiscordPayloadConstraints; | ||
| import com.yapp.ndgl.clients.discord.request.DiscordEmbed; | ||
| import com.yapp.ndgl.clients.discord.request.DiscordEmbed.Field; | ||
| import com.yapp.ndgl.clients.discord.request.DiscordEmbed.Image; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public final class UserSuggestedTemplateNotification implements DiscordNotification { | ||
|
|
||
| private static final int EMBED_COLOR = 5763719; | ||
| private static final String CONTENT_HEADER = "## 🎬 새로운 영상이 요청되었어요. 지금 확인해보세요!"; | ||
| private static final String EMBED_TITLE = "영상 보기"; | ||
|
|
||
| private final UserSuggestedTemplateCreatedEvent event; | ||
|
|
||
| public static UserSuggestedTemplateNotification from(final UserSuggestedTemplateCreatedEvent event) { | ||
| return new UserSuggestedTemplateNotification(event); | ||
| } | ||
|
|
||
| @Override | ||
| public DiscordChannel channel() { | ||
| return DiscordChannel.USER_SUGGESTED_TEMPLATE; | ||
| } | ||
|
|
||
| @Override | ||
| public String createContent() { | ||
| return CONTENT_HEADER; | ||
| } | ||
|
|
||
| @Override | ||
| public List<DiscordEmbed> createEmbeds() { | ||
|
|
||
| List<Field> fields = List.of( | ||
| Field.of("카테고리", emptyIfBlank(event.category()), true), | ||
| Field.of("지역", emptyIfBlank(event.region()), true), | ||
| Field.of("템플릿 ID", "#" + event.templateId(), true), | ||
| Field.of("제안자", maskUuid(event.suggesterUuid()), false) | ||
| ); | ||
|
|
||
| String description = StringUtils.hasText(event.recommendReason()) ? event.recommendReason() : null; | ||
| Image image = StringUtils.hasText(event.videoId()) ? | ||
| Image.of(DiscordPayloadConstraints.YOUTUBE_THUMBNAIL_URL_FORMAT.formatted(event.videoId())) : null; | ||
|
|
||
| DiscordEmbed embed = DiscordEmbed.builder() | ||
| .title(EMBED_TITLE) | ||
| .url(event.videoLink()) | ||
| .color(EMBED_COLOR) | ||
| .timestamp(Instant.now().toString()) | ||
| .description(description) | ||
| .image(image) | ||
| .fields(fields) | ||
| .build(); | ||
|
|
||
| return List.of(embed); | ||
| } | ||
|
|
||
| private static String emptyIfBlank(final String value) { | ||
| return StringUtils.hasText(value) ? value : "-"; | ||
| } | ||
|
|
||
| private static String maskUuid(final String uuid) { | ||
| if (!StringUtils.hasText(uuid)) { | ||
| return "-"; | ||
| } | ||
| if (uuid.length() <= 8) { | ||
| return uuid; | ||
| } | ||
| return uuid.substring(0, 8) + "…"; | ||
| } | ||
| } | ||
3 changes: 2 additions & 1 deletion
3
...el/event/TravelTemplateEventListener.java → ...listener/TravelTemplateEventListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...pp/ndgl/application/domains/travel/event/listener/UserSuggestedTemplateEventListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.yapp.ndgl.application.domains.travel.event.listener; | ||
|
|
||
| import org.springframework.context.event.EventListener; | ||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.yapp.ndgl.application.domains.travel.event.UserSuggestedTemplateCreatedEvent; | ||
| import com.yapp.ndgl.application.domains.travel.event.UserSuggestedTemplateNotification; | ||
| import com.yapp.ndgl.clients.discord.DiscordNotifier; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class UserSuggestedTemplateEventListener { | ||
|
|
||
| private final DiscordNotifier discordNotifier; | ||
|
|
||
| @Async | ||
| @EventListener | ||
| public void handleUserSuggestedTemplateCreatedEvent(final UserSuggestedTemplateCreatedEvent event) { | ||
| try { | ||
| UserSuggestedTemplateNotification notification = UserSuggestedTemplateNotification.from(event); | ||
| discordNotifier.notify(notification); | ||
| } catch (Exception e) { | ||
| log.error("사용자 제안 컨텐츠 Discord 알림 처리 중 오류가 발생했습니다. templateId={}", event.templateId(), e); | ||
| } | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
.../ndgl/application/domains/travel/event/publisher/UserSuggestedTemplateEventPublisher.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.yapp.ndgl.application.domains.travel.event.publisher; | ||
|
|
||
| import org.springframework.context.ApplicationEventPublisher; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.yapp.ndgl.application.domains.travel.controller.dto.CreateUserSuggestedTemplateRequest; | ||
| import com.yapp.ndgl.application.domains.travel.event.UserSuggestedTemplateCreatedEvent; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class UserSuggestedTemplateEventPublisher { | ||
|
|
||
| private final ApplicationEventPublisher applicationEventPublisher; | ||
|
|
||
| public void publish( | ||
| final Long templateId, | ||
| final String videoId, | ||
| final String uuid, | ||
| final CreateUserSuggestedTemplateRequest request | ||
| ) { | ||
| String category = request.category() != null ? request.category().name() : null; | ||
| String region = request.region() != null ? request.region().name() : null; | ||
|
|
||
| UserSuggestedTemplateCreatedEvent event = new UserSuggestedTemplateCreatedEvent( | ||
| templateId, | ||
| videoId, | ||
| request.videoLink(), | ||
| uuid, | ||
| category, | ||
| region, | ||
| request.recommendReason() | ||
| ); | ||
|
|
||
| applicationEventPublisher.publishEvent(event); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
clients/src/main/java/com/yapp/ndgl/clients/discord/DiscordChannel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.yapp.ndgl.clients.discord; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum DiscordChannel { | ||
|
|
||
| USER_SUGGESTED_TEMPLATE("user-suggested-template"); | ||
|
|
||
| private final String key; | ||
| } |
27 changes: 27 additions & 0 deletions
27
clients/src/main/java/com/yapp/ndgl/clients/discord/DiscordNotification.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.yapp.ndgl.clients.discord; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import com.yapp.ndgl.clients.discord.request.DiscordEmbed; | ||
|
|
||
| /** | ||
| * Discord 채널에 발송할 알림의 표현 형식. | ||
| * <p>알림 종류별로 구현체를 추가해 확장한다. | ||
| */ | ||
| public interface DiscordNotification { | ||
|
|
||
| /** | ||
| * 알림을 전송할 Discord webhook 채널. | ||
| */ | ||
| DiscordChannel channel(); | ||
|
|
||
| /** | ||
| * 메시지 상단 본문(content). 없으면 {@code null}. | ||
| */ | ||
| String createContent(); | ||
|
|
||
| /** | ||
| * Discord embed 목록. 없으면 {@code null} 또는 빈 리스트. | ||
| */ | ||
| List<DiscordEmbed> createEmbeds(); | ||
| } |
36 changes: 36 additions & 0 deletions
36
clients/src/main/java/com/yapp/ndgl/clients/discord/DiscordNotifier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.yapp.ndgl.clients.discord; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.util.StringUtils; | ||
|
|
||
| import com.yapp.ndgl.clients.discord.config.DiscordWebhookProperties; | ||
| import com.yapp.ndgl.clients.discord.request.DiscordWebhookRequest; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| /** | ||
| * 알림 종류({@link DiscordNotification})를 Discord webhook 페이로드로 감싸 전송한다. | ||
| */ | ||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class DiscordNotifier { | ||
|
|
||
| private final DiscordWebhookClient discordWebhookClient; | ||
| private final DiscordWebhookProperties properties; | ||
|
|
||
| public void notify(final DiscordNotification notification) { | ||
| String webhookUrl = properties.webhookUrl(notification.channel()); | ||
| if (!StringUtils.hasText(webhookUrl)) { | ||
| log.warn("Discord webhook URL이 설정되지 않아 알림을 스킵합니다. channel={}", notification.channel()); | ||
| return; | ||
| } | ||
|
|
||
| DiscordWebhookRequest request = DiscordWebhookRequest.of( | ||
| notification.createContent(), | ||
| notification.createEmbeds() | ||
| ); | ||
| discordWebhookClient.send(webhookUrl, request); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
clients/src/main/java/com/yapp/ndgl/clients/discord/DiscordPayloadConstraints.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.yapp.ndgl.clients.discord; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| /** | ||
| * Discord 페이로드의 길이/개수 제약 상수. | ||
| * <p>Discord API 문서를 기준으로 한 메시지/embed의 한도를 한 곳에서 관리한다. | ||
| */ | ||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public final class DiscordPayloadConstraints { | ||
|
|
||
| public static final int CONTENT_MAX = 2000; | ||
| public static final int EMBED_TITLE_MAX = 256; | ||
| public static final int EMBED_DESCRIPTION_MAX = 4096; | ||
| public static final int FIELD_NAME_MAX = 256; | ||
| public static final int FIELD_VALUE_MAX = 1024; | ||
| public static final int FIELDS_MAX_COUNT = 25; | ||
|
|
||
| public static final String YOUTUBE_THUMBNAIL_URL_FORMAT = "https://img.youtube.com/vi/%s/hqdefault.jpg"; | ||
| } |
32 changes: 32 additions & 0 deletions
32
clients/src/main/java/com/yapp/ndgl/clients/discord/DiscordWebhookClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.yapp.ndgl.clients.discord; | ||
|
|
||
| import org.springframework.http.MediaType; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.web.client.RestClient; | ||
|
|
||
| import com.yapp.ndgl.clients.discord.request.DiscordWebhookRequest; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class DiscordWebhookClient { | ||
|
|
||
| private final RestClient discordWebhookRestClient; | ||
|
|
||
| public void send(final String webhookUrl, final DiscordWebhookRequest request) { | ||
| try { | ||
| discordWebhookRestClient.post() | ||
| .uri(webhookUrl) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .body(request) | ||
| .retrieve() | ||
| .toBodilessEntity(); | ||
| log.debug("Discord 알림 전송 성공"); | ||
| } catch (Exception e) { | ||
| log.error("Discord 알림 전송에 실패했습니다.", e); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.