This commit is contained in:
lunaticbum 2024-09-19 18:08:45 +09:00
parent 3fae93db8e
commit 5360a7ad13

View File

@ -35,38 +35,38 @@ class TelegramBotGetter : BaseGetter {
try { try {
try { try {
val url = "https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/getUpdates" // val url = "https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/getUpdates"
//"https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=안녕하세요." // //"https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=안녕하세요."
//7068729507 // //7068729507
// OkHttp 클라이언트 객체 생성 // // OkHttp 클라이언트 객체 생성
val client = OkHttpClient.Builder().connectionPool(ConnectionPool(5,60,TimeUnit.SECONDS)).build() // val client = OkHttpClient.Builder().connectionPool(ConnectionPool(5,60,TimeUnit.SECONDS)).build()
//
// GET 요청 객체 생성 // // GET 요청 객체 생성
val builder: Request.Builder = Request.Builder().url(url).addHeader("Content-Type", "application/json").get() // val builder: Request.Builder = Request.Builder().url(url).addHeader("Content-Type", "application/json").get()
//
val request: Request = builder.build() // val request: Request = builder.build()
//
BLog.LOGE("telegram before request ") // BLog.LOGE("telegram before request ")
// OkHttp 클라이언트로 GET 요청 객체 전송 // // OkHttp 클라이언트로 GET 요청 객체 전송
val response: Response = client.newCall(request).execute() // val response: Response = client.newCall(request).execute()
if (response.isSuccessful()) { // if (response.isSuccessful()) {
// 응답 받아서 처리 // // 응답 받아서 처리
val body: ResponseBody? = response.body() // val body: ResponseBody? = response.body()
if (body != null) { // if (body != null) {
Gson().fromJson<TelegramBotUpdate>(body.string(),TelegramBotUpdate::class.java)?.let { telegramUpdates -> // Gson().fromJson<TelegramBotUpdate>(body.string(),TelegramBotUpdate::class.java)?.let { telegramUpdates ->
telegramUpdates.fill() // telegramUpdates.fill()
telegramUpdates.list.forEach { // telegramUpdates.list.forEach {
if (it.message?.text?.startsWith("/") == true) { // if (it.message?.text?.startsWith("/") == true) {
BLog.LOGE("telegram telegramUpdates >>>> ${Gson().toJson(it)}") // BLog.LOGE("telegram telegramUpdates >>>> ${Gson().toJson(it)}")
}
}
// BLog.LOGE("telegram telegramUpdates >>>> ${Gson().toJson(telegramUpdates)}")
// WorkersDb.getRealm().writeBlocking {
// copyToRealm(telegramUpdates)
// } // }
} // }
} //// BLog.LOGE("telegram telegramUpdates >>>> ${Gson().toJson(telegramUpdates)}")
} else BLog.LOGE("telegram Error Occurred") //// WorkersDb.getRealm().writeBlocking {
//// copyToRealm(telegramUpdates)
//// }
// }
// }
// } else BLog.LOGE("telegram Error Occurred")
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
e.printStackTrace() e.printStackTrace()