mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
commit
56a8804e99
@ -1,5 +1,10 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 1.1.0
|
||||||
|
|
||||||
|
* `Utils`:
|
||||||
|
* New parameter `additionalApplicationEngineEnvironmentConfigurator` in `RequestsExecutor#setWebhookInfoAndStartListenWebhooks` and `startListenWebhooks`
|
||||||
|
|
||||||
## 1.0.1
|
## 1.0.1
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@ -20,6 +20,6 @@ javax_activation_version=1.1.1
|
|||||||
dokka_version=1.6.21
|
dokka_version=1.6.21
|
||||||
|
|
||||||
library_group=dev.inmo
|
library_group=dev.inmo
|
||||||
library_version=1.0.1
|
library_version=1.1.0
|
||||||
|
|
||||||
github_release_plugin_version=2.3.7
|
github_release_plugin_version=2.3.7
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.utils.updates.retrieving
|
package dev.inmo.tgbotapi.extensions.utils.updates.retrieving
|
||||||
|
|
||||||
import dev.inmo.micro_utils.coroutines.ExceptionHandler
|
import dev.inmo.micro_utils.coroutines.*
|
||||||
import dev.inmo.micro_utils.coroutines.safely
|
|
||||||
import dev.inmo.tgbotapi.bot.RequestsExecutor
|
import dev.inmo.tgbotapi.bot.RequestsExecutor
|
||||||
import dev.inmo.tgbotapi.extensions.utils.nonstrictJsonFormat
|
import dev.inmo.tgbotapi.extensions.utils.nonstrictJsonFormat
|
||||||
import dev.inmo.tgbotapi.extensions.utils.updates.flowsUpdatesFilter
|
import dev.inmo.tgbotapi.extensions.utils.updates.flowsUpdatesFilter
|
||||||
@ -10,6 +9,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update
|
|||||||
import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy
|
import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy
|
||||||
import dev.inmo.tgbotapi.updateshandlers.*
|
import dev.inmo.tgbotapi.updateshandlers.*
|
||||||
import dev.inmo.tgbotapi.updateshandlers.webhook.WebhookPrivateKeyConfig
|
import dev.inmo.tgbotapi.updateshandlers.webhook.WebhookPrivateKeyConfig
|
||||||
|
import io.ktor.http.HttpStatusCode
|
||||||
import io.ktor.server.application.call
|
import io.ktor.server.application.call
|
||||||
import io.ktor.server.engine.*
|
import io.ktor.server.engine.*
|
||||||
import io.ktor.server.request.receiveText
|
import io.ktor.server.request.receiveText
|
||||||
@ -39,18 +39,22 @@ fun Route.includeWebhookHandlingInRoute(
|
|||||||
) {
|
) {
|
||||||
val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block, mediaGroupsDebounceTimeMillis)
|
val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block, mediaGroupsDebounceTimeMillis)
|
||||||
post {
|
post {
|
||||||
safely(
|
try {
|
||||||
exceptionsHandler ?: {}
|
runCatchingSafely {
|
||||||
) {
|
val asJson = nonstrictJsonFormat.parseToJsonElement(call.receiveText())
|
||||||
val asJson =
|
|
||||||
nonstrictJsonFormat.parseToJsonElement(call.receiveText())
|
|
||||||
val update = nonstrictJsonFormat.decodeFromJsonElement(
|
val update = nonstrictJsonFormat.decodeFromJsonElement(
|
||||||
UpdateDeserializationStrategy,
|
UpdateDeserializationStrategy,
|
||||||
asJson
|
asJson
|
||||||
)
|
)
|
||||||
transformer(update)
|
transformer(update)
|
||||||
|
}.onSuccess {
|
||||||
|
call.respond(HttpStatusCode.OK)
|
||||||
|
}.onFailure {
|
||||||
|
call.respond(HttpStatusCode.InternalServerError)
|
||||||
|
}.getOrThrow()
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
exceptionsHandler ?.invoke(e)
|
||||||
}
|
}
|
||||||
call.respond("Ok")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +91,7 @@ fun startListenWebhooks(
|
|||||||
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||||
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||||
mediaGroupsDebounceTimeMillis: Long = 1000L,
|
mediaGroupsDebounceTimeMillis: Long = 1000L,
|
||||||
|
additionalApplicationEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||||
block: UpdateReceiver<Update>
|
block: UpdateReceiver<Update>
|
||||||
): ApplicationEngine {
|
): ApplicationEngine {
|
||||||
val env = applicationEngineEnvironment {
|
val env = applicationEngineEnvironment {
|
||||||
@ -98,6 +103,7 @@ fun startListenWebhooks(
|
|||||||
} ?: includeWebhookHandlingInRoute(scope, exceptionsHandler, mediaGroupsDebounceTimeMillis, block)
|
} ?: includeWebhookHandlingInRoute(scope, exceptionsHandler, mediaGroupsDebounceTimeMillis, block)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
privateKeyConfig ?.let {
|
privateKeyConfig ?.let {
|
||||||
sslConnector(
|
sslConnector(
|
||||||
privateKeyConfig.keyStore,
|
privateKeyConfig.keyStore,
|
||||||
@ -113,6 +119,7 @@ fun startListenWebhooks(
|
|||||||
port = listenPort
|
port = listenPort
|
||||||
}
|
}
|
||||||
|
|
||||||
|
additionalApplicationEngineEnvironmentConfigurator()
|
||||||
}
|
}
|
||||||
|
|
||||||
return embeddedServer(engineFactory, env).also {
|
return embeddedServer(engineFactory, env).also {
|
||||||
@ -142,10 +149,11 @@ suspend fun RequestsExecutor.setWebhookInfoAndStartListenWebhooks(
|
|||||||
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||||
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||||
mediaGroupsDebounceTimeMillis: Long = 1000L,
|
mediaGroupsDebounceTimeMillis: Long = 1000L,
|
||||||
|
additionalApplicationEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||||
block: UpdateReceiver<Update>
|
block: UpdateReceiver<Update>
|
||||||
): ApplicationEngine = try {
|
): ApplicationEngine = try {
|
||||||
execute(setWebhookRequest)
|
execute(setWebhookRequest)
|
||||||
startListenWebhooks(listenPort, engineFactory, exceptionsHandler, listenHost, listenRoute, privateKeyConfig, scope, mediaGroupsDebounceTimeMillis, block)
|
startListenWebhooks(listenPort, engineFactory, exceptionsHandler, listenHost, listenRoute, privateKeyConfig, scope, mediaGroupsDebounceTimeMillis, additionalApplicationEngineEnvironmentConfigurator, block)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user