11package clap .server .adapter .outbound .api ;
22
3- import clap .server .adapter .outbound .api .dto .SendWebhookRequest ;
4- import clap .server .adapter .outbound .persistense .entity .notification .constant .NotificationType ;
3+ import clap .server .adapter .outbound .api .dto .PushNotificationTemplate ;
54import com .fasterxml .jackson .core .JsonProcessingException ;
65import com .fasterxml .jackson .databind .ObjectMapper ;
76import lombok .RequiredArgsConstructor ;
@@ -15,36 +14,25 @@ public class KakaoWorkBlockBuilder {
1514
1615 private final ObjectMapper objectMapper ;
1716
18- public String makeObjectBlock (SendWebhookRequest request ){
19- String payload ;
20- if (request .notificationType () == NotificationType .TASK_REQUESTED ) {
21- payload = makeTaskRequestBlock (request );
22- }
23- else if (request .notificationType () == NotificationType .PROCESSOR_ASSIGNED ) {
24- payload = makeNewProcessorBlock (request );
25- }
26- else if (request .notificationType () == NotificationType .PROCESSOR_CHANGED ) {
27- payload = makeProcessorChangeBlock (request );
28- }
29- else if (request .notificationType () == NotificationType .STATUS_SWITCHED ) {
30- payload = makeTaskStatusBlock (request );
31- }
32- else {
33- payload = makeCommentBlock (request );
34- }
35- return payload ;
17+ public String makeObjectBlock (PushNotificationTemplate request ){
18+ String taskDetailUrl = "https://www.naver.com" ;
19+ return switch (request .notificationType ()) {
20+ case TASK_REQUESTED -> makeTaskRequestBlock (request , taskDetailUrl );
21+ case STATUS_SWITCHED -> makeTaskStatusBlock (request , taskDetailUrl );
22+ case PROCESSOR_CHANGED -> makeProcessorChangeBlock (request , taskDetailUrl );
23+ case PROCESSOR_ASSIGNED -> makeNewProcessorBlock (request , taskDetailUrl );
24+ case COMMENT -> makeCommentBlock (request , taskDetailUrl );
25+ default -> null ;
26+ };
3627 }
3728
38- private String makeTaskRequestBlock (SendWebhookRequest request ) {
39- // Blocks 데이터 생성
29+ private String makeTaskRequestBlock (PushNotificationTemplate request , String taskDetailUrl ) {
4030 Object [] blocks = new Object []{
41- // Header 블록
4231 Map .of (
4332 "type" , "header" ,
4433 "text" , "TaskFlow 작업 요청 알림" ,
4534 "style" , "blue"
4635 ),
47- // Text 블록 1
4836 Map .of (
4937 "type" , "text" ,
5038 "text" , "TaskFlow 작업 요청 알림" ,
@@ -56,7 +44,6 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
5644 )
5745 }
5846 ),
59- // Text 블록 2: 제목 변수 사용
6047 Map .of (
6148 "type" , "text" ,
6249 "text" , "TaskFlow 작업 요청 알림" ,
@@ -68,7 +55,6 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
6855 )
6956 }
7057 ),
71- // Text 블록 3: 요청자 변수 사용
7258 Map .of (
7359 "type" , "text" ,
7460 "text" , "TaskFlow 작업 요청 알림" ,
@@ -80,15 +66,14 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
8066 )
8167 }
8268 ),
83- // Button 블록
8469 Map .of (
8570 "type" , "button" ,
8671 "text" , "확인하기" ,
8772 "style" , "default" ,
8873 "action" , Map .of (
8974 "type" , "open_system_browser" ,
9075 "name" , "button1" ,
91- "value" , "http://example.com/details/999"
76+ "value" , taskDetailUrl
9277 )
9378 )
9479 };
@@ -97,7 +82,7 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
9782 try {
9883 payload = "{" +
9984 "\" email\" :\" " + request .email () + "\" ," +
100- "\" text\" : \" 신규 작업 요청 알림\" ," + // fallback 메시지
85+ "\" text\" : \" 신규 작업 요청 알림\" ," +
10186 "\" blocks\" :" + objectMapper .writeValueAsString (blocks ) +
10287 "}" ;
10388 } catch (JsonProcessingException e ) {
@@ -107,7 +92,7 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
10792 return payload ;
10893 }
10994
110- private String makeNewProcessorBlock (SendWebhookRequest request ) {
95+ private String makeNewProcessorBlock (PushNotificationTemplate request , String taskDetailUrl ) {
11196 Object [] blocks = new Object []{
11297 Map .of (
11398 "type" , "header" ,
@@ -154,7 +139,7 @@ private String makeNewProcessorBlock(SendWebhookRequest request) {
154139 "action" , Map .of (
155140 "type" , "open_system_browser" ,
156141 "name" , "button1" ,
157- "value" , "http://example.com/details/999"
142+ "value" , taskDetailUrl
158143 )
159144 )
160145 };
@@ -163,7 +148,7 @@ private String makeNewProcessorBlock(SendWebhookRequest request) {
163148 try {
164149 payload = "{" +
165150 "\" email\" :\" " + request .email () + "\" ," +
166- "\" text\" :\" 작업 담당자 선정 알림\" ," + // fallback 메시지
151+ "\" text\" :\" 작업 담당자 선정 알림\" ," +
167152 "\" blocks\" :" + objectMapper .writeValueAsString (blocks ) +
168153 "}" ;
169154 } catch (JsonProcessingException e ) {
@@ -173,7 +158,7 @@ private String makeNewProcessorBlock(SendWebhookRequest request) {
173158 return payload ;
174159 }
175160
176- private String makeProcessorChangeBlock (SendWebhookRequest request ) {
161+ private String makeProcessorChangeBlock (PushNotificationTemplate request , String taskDetailUrl ) {
177162 Object [] blocks = new Object []{
178163 Map .of (
179164 "type" , "header" ,
@@ -220,7 +205,7 @@ private String makeProcessorChangeBlock(SendWebhookRequest request) {
220205 "action" , Map .of (
221206 "type" , "open_system_browser" ,
222207 "name" , "button1" ,
223- "value" , "http://example.com/details/999"
208+ "value" , taskDetailUrl
224209 )
225210 )
226211 };
@@ -229,7 +214,7 @@ private String makeProcessorChangeBlock(SendWebhookRequest request) {
229214 try {
230215 payload = "{" +
231216 "\" email\" :\" " + request .email () + "\" ," +
232- "\" text\" :\" 작업 담당자 변경 알림\" ," + // fallback 메시지
217+ "\" text\" :\" 작업 담당자 변경 알림\" ," +
233218 "\" blocks\" :" + objectMapper .writeValueAsString (blocks ) +
234219 "}" ;
235220 } catch (JsonProcessingException e ) {
@@ -240,7 +225,7 @@ private String makeProcessorChangeBlock(SendWebhookRequest request) {
240225 return payload ;
241226 }
242227
243- private String makeCommentBlock (SendWebhookRequest request ) {
228+ private String makeCommentBlock (PushNotificationTemplate request , String taskDetailUrl ) {
244229 Object [] blocks = new Object []{
245230 Map .of (
246231 "type" , "header" ,
@@ -298,7 +283,7 @@ private String makeCommentBlock(SendWebhookRequest request) {
298283 "action" , Map .of (
299284 "type" , "open_system_browser" ,
300285 "name" , "button1" ,
301- "value" , "http://example.com/details/999"
286+ "value" , taskDetailUrl
302287 )
303288 )
304289 };
@@ -307,7 +292,7 @@ private String makeCommentBlock(SendWebhookRequest request) {
307292 try {
308293 payload = "{" +
309294 "\" email\" :\" " + request .email () + "\" ," +
310- "\" text\" :\" 댓글 알림\" ," + // fallback 메시지
295+ "\" text\" :\" 댓글 알림\" ," +
311296 "\" blocks\" :" + objectMapper .writeValueAsString (blocks ) +
312297 "}" ;
313298 } catch (JsonProcessingException e ) {
@@ -317,7 +302,7 @@ private String makeCommentBlock(SendWebhookRequest request) {
317302 return payload ;
318303 }
319304
320- private String makeTaskStatusBlock (SendWebhookRequest request ) {
305+ private String makeTaskStatusBlock (PushNotificationTemplate request , String taskDetailUrl ) {
321306 Object [] blocks = new Object []{
322307 Map .of (
323308 "type" , "header" ,
@@ -364,7 +349,7 @@ private String makeTaskStatusBlock(SendWebhookRequest request) {
364349 "action" , Map .of (
365350 "type" , "open_system_browser" ,
366351 "name" , "button1" ,
367- "value" , "http://example.com/details/999"
352+ "value" , taskDetailUrl
368353 )
369354 )
370355 };
@@ -373,7 +358,7 @@ private String makeTaskStatusBlock(SendWebhookRequest request) {
373358 try {
374359 payload = "{" +
375360 "\" email\" :\" " + request .email () + "\" ," +
376- "\" text\" :\" 작업 상태 변경 알림\" ," + // fallback 메시지
361+ "\" text\" :\" 작업 상태 변경 알림\" ," +
377362 "\" blocks\" :" + objectMapper .writeValueAsString (blocks ) +
378363 "}" ;
379364 } catch (JsonProcessingException e ) {
0 commit comments