From 2215e97deb79ae02f51b83374d710442344757d6 Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Wed, 6 May 2026 15:54:23 +0900 Subject: [PATCH] ... --- .../back/lun/configs/core/AppConfig.kt | 1 + .../lun/configs/security/SecurityConfig.kt | 9 +++- .../back/lun/controllers/Telegram.kt | 38 ++++++++++++++++- .../back/lun/controllers/view/BumsPrivate.kt | 2 + .../back/lun/service/StockMonitorService.kt | 2 - .../back/lun/service/TelegramBotService.kt | 41 ++++++++++--------- 6 files changed, 69 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/configs/core/AppConfig.kt b/src/main/kotlin/kr/lunaticbum/back/lun/configs/core/AppConfig.kt index fc88c57..cb02c63 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/configs/core/AppConfig.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/configs/core/AppConfig.kt @@ -42,6 +42,7 @@ class AppConfig : WebMvcConfigurer { "/bums/where.bs", "/user/info", // "내 정보" 페이지도 추가하면 좋습니다. "/tlg/repotToMe.bjx", + "/tlg/sendToMe.bjx", "/user/login.bs", "/user/signup.bs", "/user/login.bjx","/bookmarks/**", "/blog/viewer/**", "/blog/posts", "/blog/rankOfViews.bjx", "/blog/recentOfPost.bjx" ) diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/configs/security/SecurityConfig.kt b/src/main/kotlin/kr/lunaticbum/back/lun/configs/security/SecurityConfig.kt index b8d2823..2908b3e 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/configs/security/SecurityConfig.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/configs/security/SecurityConfig.kt @@ -184,7 +184,11 @@ class SecurityConfig( .csrf { csrf -> csrf.ignoringRequestMatchers( "/api/**", // <-- 이 줄을 추가하세요! - "/user/login.bjx", "/user/joinUser.bjx", "/tlg/repotToMe.bjx", + "/user/login.bjx", + "/user/joinUser.bjx", + "/tlg/repotToMe.bjx", + "/tlg/sendToMe.bjx", + "/tlg/webhook", "/api/ranks/submit", "/bums/save/loc.api", "/puzzle/**", @@ -213,6 +217,7 @@ class SecurityConfig( "/bums/face.bs", // [추가] 사이트 소개 페이지 "/bookmarks/**", // [추가] 북마크 목록 페이지 "/ads.txt", + "/tlg/webhook", "/slideshow" ).permitAll() @@ -224,6 +229,8 @@ class SecurityConfig( "/bums/save/loc.api", "/puzzle/**", "/tlg/repotToMe.bjx", + "/tlg/webhook", + "/tlg/sendToMe.bjx", "/blog/post/*/like.bjx", "/blog/post/*/unlike.bjx", "/bookmarks/*/like", // [추가] 북마크 좋아요 diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Telegram.kt b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Telegram.kt index eadf5be..f94f029 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Telegram.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Telegram.kt @@ -1,8 +1,10 @@ package kr.lunaticbum.back.lun.controllers +import com.google.gson.Gson import kr.lunaticbum.back.lun.model.Result // [중요] 서비스 클래스 import 추가 import kr.lunaticbum.back.lun.services.TelegramBotService +import kr.lunaticbum.back.lun.utils.extractModelData import org.springframework.web.bind.annotation.* @RestController @@ -26,4 +28,38 @@ class Telegram( telegramBotService.processWebhookUpdate(update) return "Success" } -} \ No newline at end of file + + @ResponseBody + @PostMapping("repotToMe.bjx") + fun repotToMe(@RequestBody jsonString: String) { + jsonString.extractModelData { exception, originDataString -> + println("jsonString $jsonString $originDataString") + if (exception == null) { + Gson().fromJson(originDataString, ReportModel::class.java)?.let { msg -> + telegramBotService.sendTelegramMessage(null,"${msg.name}:${msg.email}\n${msg.message}") + + } + + } + } + } + + + @ResponseBody + @PostMapping("sendToMe.bjx") + fun sendToMe(@RequestBody jsonString: String) { + println("jsonString $jsonString") + Gson().fromJson(jsonString, SendToMeModel::class.java)?.let { msg -> + telegramBotService.sendTelegramMessage(msg.id,msg.message) + + } + } + +} +data class SendToMeModel(var id : String, var message : String) + +data class ReportModel( + var name : String? = null, + var email : String? = null, + var message : String? = null, +) \ No newline at end of file diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/view/BumsPrivate.kt b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/view/BumsPrivate.kt index a50bede..ba649e8 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/view/BumsPrivate.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/view/BumsPrivate.kt @@ -87,4 +87,6 @@ class BumsPrivate { }) return responce } + + } \ No newline at end of file diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/service/StockMonitorService.kt b/src/main/kotlin/kr/lunaticbum/back/lun/service/StockMonitorService.kt index ad8c439..601e8c9 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/service/StockMonitorService.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/service/StockMonitorService.kt @@ -4,7 +4,6 @@ package kr.lunaticbum.back.lun.service import jakarta.annotation.PostConstruct import kotlinx.coroutines.reactor.awaitSingle -import kotlinx.coroutines.runBlocking import kr.lunaticbum.back.lun.configs.core.GlobalEnvironment import kr.lunaticbum.back.lun.model.AutoTradeEntity import kr.lunaticbum.back.lun.model.KisAuthSession @@ -14,7 +13,6 @@ import kr.lunaticbum.back.lun.repository.AutoTradeRepository import kr.lunaticbum.back.lun.repository.TradeHistoryRepository import kr.lunaticbum.back.lun.services.TelegramBotService import kr.lunaticbum.back.lun.utils.MarketTimeManager -import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Service import java.util.concurrent.CopyOnWriteArrayList diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/service/TelegramBotService.kt b/src/main/kotlin/kr/lunaticbum/back/lun/service/TelegramBotService.kt index fccb22e..0f91869 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/service/TelegramBotService.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/service/TelegramBotService.kt @@ -92,7 +92,7 @@ class TelegramBotService( private fun fetchAndSendWeather(chatId: String, lat: BigDecimal, long: BigDecimal) { WebClient.create().get() - .uri("http://api.weatherapi.com/v1/current.json?key=${globalEvv.weatherApiKey}&q=${lat},${long}&aqi=no") + .uri("https://api.weatherapi.com/v1/current.json?key=${globalEvv.weatherApiKey}&q=${lat},${long}&aqi=no") .retrieve() .bodyToMono(CurrentWeather::class.java) .timeout(Duration.ofSeconds(30L)) @@ -136,23 +136,23 @@ class TelegramBotService( val chatId = msg.from?.id?.toString() ?: return val text = msg.text ?: return - val req = BumlamaReq(text) - CoroutineScope(Dispatchers.IO).launch { - val feedbackUrl = "$telegramApiBaseUrl/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=blama 일시키겠=> '${req.reqMsg}'" - logService.log("AI Req: $feedbackUrl") - WebClient.create().get() - .uri(feedbackUrl) - .retrieve() - .bodyToMono(String::class.java).block() - } - - CoroutineScope(Dispatchers.IO).launch { - val dateContext = SimpleDateFormat("yyyy-MM-dd").format(Date()) - val modifiedQuery = text.replace("오늘", "오늘($dateContext)") - - // [수정] 서비스 객체 이름 변경 (lama -> lamaService) - lamaService.generateResponse(modifiedQuery, chatId) - } +// val req = BumlamaReq(text) +// CoroutineScope(Dispatchers.IO).launch { +// val feedbackUrl = "$telegramApiBaseUrl/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=blama 일시키겠=> '${req.reqMsg}'" +// logService.log("AI Req: $feedbackUrl") +// WebClient.create().get() +// .uri(feedbackUrl) +// .retrieve() +// .bodyToMono(String::class.java).block() +// } +// +// CoroutineScope(Dispatchers.IO).launch { +// val dateContext = SimpleDateFormat("yyyy-MM-dd").format(Date()) +// val modifiedQuery = text.replace("오늘", "오늘($dateContext)") +// +// // [수정] 서비스 객체 이름 변경 (lama -> lamaService) +// lamaService.generateResponse(modifiedQuery, chatId) +// } } private fun sendCurrentLocation(targetChatId: String) { @@ -167,9 +167,10 @@ class TelegramBotService( } } - fun sendTelegramMessage(chatId: String, text: String) { + fun sendTelegramMessage(chatId: String?, text: String) { + val id = chatId ?: globalEvv.telegramMyId ?: return val fullUrl = "$telegramApiBaseUrl/${globalEvv.telegramBotKey}/sendMessage" - val msgObj = TelegramSendMsg(chatId, text) + val msgObj = TelegramSendMsg(id, text) try { WebClient.create(fullUrl)