-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathKakaoWorkClient.java
More file actions
52 lines (41 loc) · 1.75 KB
/
KakaoWorkClient.java
File metadata and controls
52 lines (41 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package clap.server.adapter.outbound.api;
import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
import clap.server.application.port.outbound.webhook.SendKaKaoWorkPort;
import clap.server.common.annotation.architecture.ExternalApiAdapter;
import clap.server.exception.AdapterException;
import clap.server.exception.code.NotificationErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.web.client.RestTemplate;
@ExternalApiAdapter
@RequiredArgsConstructor
public class KakaoWorkClient implements SendKaKaoWorkPort {
@Value("${webhook.kakaowork.url}")
private String kakaworkUrl;
@Value("${webhook.kakaowork.auth}")
private String kakaworkAuth;
private final KakaoWorkBlockBuilder kakaoWorkBlockBuilder;
@Override
public void sendKakaoWork(SendWebhookRequest request) {
RestTemplate restTemplate = new RestTemplate();
// Payload 생성
String payload = kakaoWorkBlockBuilder.makeObjectBlock(request);
// HTTP 요청 헤더 설정
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
headers.add("Authorization", kakaworkAuth);
// HTTP 요청 엔터티 생성
HttpEntity<String> entity = new HttpEntity<>(payload, headers);
try {
// Post 요청 전송
restTemplate.exchange(
kakaworkUrl, HttpMethod.POST, entity, String.class
);
} catch (Exception e) {
throw new AdapterException(NotificationErrorCode.KAKAO_SEND_FAILED);
}
}
}