From b945a0d6771f8dd6574a17794e2b7ae77e2eba78 Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Sat, 5 Oct 2024 17:14:07 +0900 Subject: [PATCH] . --- .../kr/lunaticbum/back/lun/LunApplication.kt | 8 ++++ .../back/lun/controllers/Telegram.kt | 37 +++++++++++++++---- src/main/resources/application.properties | 5 +++ 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/LunApplication.kt b/src/main/kotlin/kr/lunaticbum/back/lun/LunApplication.kt index fbd7c63..d9aff09 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/LunApplication.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/LunApplication.kt @@ -16,6 +16,14 @@ import java.util.* @EnableScheduling // 추가 @SpringBootApplication class LunApplication { + init { + val client = WebClient.create() + client.get() + .uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=SERVER_START") + .retrieve() + .bodyToMono(String::class.java).block() ?: "FAIL" + } + @Scheduled(cron = "0 0 0/4 * * *") // fun runJob() { try { 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 d539441..4da476d 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Telegram.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Telegram.kt @@ -13,15 +13,36 @@ class Telegram { } @ResponseBody - @GetMapping("webhook") - fun test(@PathVariable path : String) { - println("path >>> $path") - val client = WebClient.create() - client.get() - .uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/getUpdates") - .retrieve() - .bodyToMono(String::class.java).block() ?: "FAIL" + @PostMapping("webhook") + fun test(httpServletRequest: HttpServletRequest, @RequestBody update : TelegramUpdate?) { + try { + logger.log("test strat ${update}") + logger.log("test strat ${httpServletRequest.requestURI}") +// val client0 = WebClient.create() +// client0.get() +// .uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/getUpdates") +// .retrieve() +// .bodyToMono(String::class.java).subscribe { result -> + logger.log("test $httpServletRequest.requestURI") +// var sss = Gson().fromJson(jsonString, TelegramUpdate::class.java) +// if (sss.ok) { +// var doSend = false +// sss.result?.forEach { +// if (!doSend) doSend = it.message?.text?.contains("어디") ?: false +// } +// if (doSend) { +// val client = WebClient.create() +// client.get() +// .uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=OK") +// .retrieve() +// .bodyToMono(String::class.java).block() ?: "FAIL" +// } +// logger.log("test OK") +// } +// } + } catch (e : Exception) { + } } // @ResponseBody diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 64b48f2..7ad2d22 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -8,6 +8,11 @@ spring.data.mongodb.host=nas.lunaticbum.kr #spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 spring.data.mongodb.database=lun_db +#SSL +server.ssl.key-store=classpath:prv.p12 +server.ssl.key-store-type=PKCS12 +server.ssl.key-store-password=VioPup*383 +server.http2.enabled=true #spring.main.web-application-type=SERVLET #logging.level.org.springframework.boot.autoconfigure=ERROR #spring.mvc.view.prefix=/templates