Skip to content

Commit 2796dce

Browse files
authored
Merge pull request #34 from DevKor-github/feature/kakao-api
Feature/kakao api
2 parents 4f60205 + fad9d9b commit 2796dce

29 files changed

Lines changed: 1088 additions & 972 deletions

.github/workflows/deploy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- feature/kakao-api
78
jobs:
89
deploy:
910
runs-on: ubuntu-latest
@@ -60,6 +61,8 @@ jobs:
6061
6162
export DB_PASSWORD='${{ secrets.DB_PASSWORD }}'
6263
export DISCORD_TOKEN='${{ secrets.DISCORD_TOKEN }}'
64+
export KAKAO_REST_API_KEY='${{ secrets.KAKAO_REST_API_KEY }}'
65+
export KAKAO_EVENT_API_KEY='${{ secrets.KAKAO_EVENT_API_KEY }}'
6366
6467
nohup java -jar build/libs/workingdead-0.0.1-SNAPSHOT.jar > app.log 2>&1 &
6568

src/main/java/com/workingdead/chatbot/discord/service/DiscordWendyServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void addParticipant(String channelId, String memberId, String memberName)
101101
return;
102102
}
103103

104-
ParticipantRes pRes = participantService.add(voteId, memberName);
104+
ParticipantRes pRes = participantService.add(voteId, null, memberName);
105105
System.out.println("[Discord When:D] Participant added AFTER vote: " + memberName
106106
+ " (discordId=" + memberId + ", participantId=" + pRes.id() + ")");
107107
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.workingdead.chatbot.kakao.client;
2+
3+
import java.util.List;
4+
5+
public interface KakaoChatClient {
6+
List<KakaoChatUser> fetchChatUsers(String botGroupKey);
7+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.workingdead.chatbot.kakao.client;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.http.HttpHeaders;
5+
import org.springframework.stereotype.Component;
6+
import org.springframework.web.client.RestClient;
7+
8+
import java.util.List;
9+
10+
@Component
11+
public class KakaoChatClientImpl implements KakaoChatClient {
12+
13+
private final RestClient restClient;
14+
private final String botId;
15+
16+
public KakaoChatClientImpl(
17+
RestClient.Builder builder,
18+
@Value("${kakao.bot-base-url}") String baseUrl,
19+
@Value("${kakao.bot-id}") String botId,
20+
@Value("${kakao.rest-api-key}") String restApiKey
21+
) {
22+
this.botId = botId;
23+
this.restClient = builder
24+
.baseUrl(baseUrl)
25+
.defaultHeader(HttpHeaders.AUTHORIZATION, "KakaoAK " + restApiKey)
26+
.defaultHeader(HttpHeaders.CONTENT_TYPE, "application/json")
27+
.build();
28+
}
29+
30+
@Override
31+
public List<KakaoChatUser> fetchChatUsers(String botGroupKey) {
32+
KakaoChatMembersResponse res = restClient.get()
33+
.uri("/v2/bots/{botId}/group-chat-rooms/{botGroupKey}/members", botId, botGroupKey)
34+
.retrieve()
35+
.body(KakaoChatMembersResponse.class);
36+
37+
if (res == null || res.users() == null) return List.of();
38+
39+
return res.users().stream()
40+
.map(KakaoChatUser::new) // botUserKey 그대로
41+
.toList();
42+
}
43+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.workingdead.chatbot.kakao.client;
2+
3+
import java.util.List;
4+
5+
public record KakaoChatMembersResponse(List<String> users) {
6+
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.workingdead.chatbot.kakao.client;
2+
3+
public record KakaoChatUser(String botUserKey) {
4+
5+
}

0 commit comments

Comments
 (0)