diff --git a/CHANGELOG.md b/CHANGELOG.md index c5b2c89ac4..bd8c73e817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ * `Ktor`: `3.1.1` -> `3.1.3` * `MicroUtils`: `0.25.3` -> `0.25.7` * `Core`: - * **BREAKING CHANGE** `RequestsExecutor` got property `RequestsExecutor.Log: KSLog?` + * **POTENTIALLY BREAKING CHANGE** Long polling has been reworked a bit + * **BREAKING CHANGE** `RequestsExecutor` got property `RequestsExecutor.Log: KSLog` * `BehaviourContext`: * **BREAKING CHANGE** All triggers and waiters become non-suspend functions * **BREAKING CHANGE** Behaviour of counted extensions (commands, data callback queries, etc.) has been changed a bit: now each one will diff --git a/build.gradle b/build.gradle index be8faa1661..9a2c2db4dc 100644 --- a/build.gradle +++ b/build.gradle @@ -38,9 +38,9 @@ if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != n // temporal crutch until legacy tests will be stabled or legacy target will be removed allprojects { repositories { - maven { url "https://nexus.inmo.dev/repository/maven-releases/" } mavenCentral() google() +// maven { url "https://nexus.inmo.dev/repository/maven-releases/" } mavenLocal() } if (it != rootProject.findProject("docs")) { diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt index 09f1e8c076..839753c6ff 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt @@ -217,7 +217,7 @@ fun BC.launchInNewSubContext( updatesUpstreamFlow = updatesUpstreamFlow, subcontextInitialAction = subcontextInitialAction ).apply { - this@apply.launchLoggingDropExceptions(logger = Log ?: KSLog) { + this@apply.launchLoggingDropExceptions(logger = Log) { behaviourContextReceiver() } }.coroutineContext.job diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/CombinedSubcontextInitialAction.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/CombinedSubcontextInitialAction.kt index 5057b1d486..3b78756291 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/CombinedSubcontextInitialAction.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/CombinedSubcontextInitialAction.kt @@ -40,7 +40,7 @@ class CombinedSubcontextInitialAction( runCatching { invoke(update) }.onFailure { - (Log ?: logger).error(it) { + Log.error(it) { "Unable to execute $subaction for update $update. Will try on next round" } }.onSuccess { @@ -50,7 +50,7 @@ class CombinedSubcontextInitialAction( } leftSubActions.removeAll(successSubActions) if (successSubActions.isEmpty()) { - (Log ?: logger).error { + Log.error { "Some SubActions have been unable to complete successfully:${leftSubActions.joinToString("\n") { it.toString() }}" } break diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/RequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/RequestsExecutor.kt index 3c3756f568..8c56f0c4b3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/RequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/RequestsExecutor.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.bot import dev.inmo.kslog.common.KSLog import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog import io.ktor.utils.io.core.Closeable /** @@ -12,8 +13,8 @@ import io.ktor.utils.io.core.Closeable * @see dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutor */ interface RequestsExecutor : Closeable { - val Log: KSLog? - get() = null + val Log: KSLog + get() = DefaultKTgBotAPIKSLog /** * Unsafe execution of incoming [request]. Can throw almost any exception. So, it is better to use * something like [dev.inmo.tgbotapi.extensions.utils.shortcuts.executeAsync] or diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/KtorRequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/KtorRequestsExecutor.kt index cc9da7da74..0c5a507fef 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/KtorRequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/KtorRequestsExecutor.kt @@ -29,7 +29,7 @@ expect class KtorRequestsExecutor internal constructor( logger: KSLog, diff: Unit // just a diff property to know where constructor and where calling function with defaults ) : BaseRequestsExecutor { - override val Log: KSLog? + override val Log: KSLog override suspend fun execute(request: Request): T override fun close() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor.kt index e0deb6f658..cd6a745ff8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor.kt @@ -30,7 +30,7 @@ class DefaultKtorRequestsExecutor internal constructor( private val logger: KSLog, diff: Unit ) : BaseRequestsExecutor(telegramAPIUrlsKeeper) { - override val Log: KSLog? = logger + override val Log: KSLog = logger private val callsFactories: List = callsFactories.run { if (!excludeDefaultFactories) { this@DefaultKtorRequestsExecutor.logger.v { "Installing default factories" } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/MultipleClientKtorRequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/MultipleClientKtorRequestsExecutor.kt index 98e566a2fc..05bb7d18ba 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/MultipleClientKtorRequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/MultipleClientKtorRequestsExecutor.kt @@ -49,7 +49,7 @@ class MultipleClientKtorRequestsExecutor( logger: KSLog, clientFactory: () -> HttpClient, ) : BaseRequestsExecutor(telegramAPIUrlsKeeper) { - override val Log: KSLog? = logger + override val Log: KSLog = logger private val requestExecutors = (0 until requestExecutorsCount).map { DefaultKtorRequestsExecutor( telegramAPIUrlsKeeper, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/multiserver/SimpleMultiServerRequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/multiserver/SimpleMultiServerRequestsExecutor.kt index e4395c73e7..ab1b485758 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/multiserver/SimpleMultiServerRequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/multiserver/SimpleMultiServerRequestsExecutor.kt @@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.bot.ktor.telegramBot import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import kotlinx.coroutines.* import kotlin.js.JsName @@ -30,8 +31,8 @@ class SimpleMultiServerRequestsExecutor( bots.forEach(TelegramBot::close) } ) : RequestsExecutor { - override val Log: KSLog? - get() = bots.firstNotNullOfOrNull { it.Log } + override val Log: KSLog + get() = bots.firstNotNullOfOrNull { it.Log } ?: DefaultKTgBotAPIKSLog override suspend fun execute(request: Request): T { var currentBot = bots.botSelector(-1, null) while (currentCoroutineContext().isActive) { diff --git a/tgbotapi.utils/api/tgbotapi.utils.api b/tgbotapi.utils/api/tgbotapi.utils.api index affaab9b56..6f40c07f8d 100644 --- a/tgbotapi.utils/api/tgbotapi.utils.api +++ b/tgbotapi.utils/api/tgbotapi.utils.api @@ -3609,20 +3609,21 @@ public final class dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPol } public final class dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluderKt { - public static final fun updateHandlerWithMediaGroupsAdaptation (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; - public static final fun updateHandlerWithMediaGroupsAdaptation (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;J)Lkotlin/jvm/functions/Function2; - public static synthetic fun updateHandlerWithMediaGroupsAdaptation$default (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JILjava/lang/Object;)Lkotlin/jvm/functions/Function2; + public static final fun updateHandlerWithMediaGroupsAdaptation (Lkotlinx/coroutines/CoroutineScope;Ldev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; + public static final fun updateHandlerWithMediaGroupsAdaptation (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JLdev/inmo/kslog/common/KSLog;)Lkotlin/jvm/functions/Function2; + public static synthetic fun updateHandlerWithMediaGroupsAdaptation$default (Lkotlinx/coroutines/CoroutineScope;Ldev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkotlin/jvm/functions/Function2; + public static synthetic fun updateHandlerWithMediaGroupsAdaptation$default (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JLdev/inmo/kslog/common/KSLog;ILjava/lang/Object;)Lkotlin/jvm/functions/Function2; } public final class dev/inmo/tgbotapi/extensions/utils/updates/retrieving/WebhookKt { - public static final fun includeWebhookHandlingInRoute (Lio/ktor/server/routing/Route;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V - public static synthetic fun includeWebhookHandlingInRoute$default (Lio/ktor/server/routing/Route;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V - public static final fun includeWebhookHandlingInRouteWithFlows (Lio/ktor/server/routing/Route;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function1;)V - public static synthetic fun includeWebhookHandlingInRouteWithFlows$default (Lio/ktor/server/routing/Route;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function1;ILjava/lang/Object;)V - public static final fun setWebhookInfoAndStartListenWebhooks (Ldev/inmo/tgbotapi/bot/RequestsExecutor;ILio/ktor/server/engine/ApplicationEngineFactory;Ldev/inmo/tgbotapi/requests/webhook/SetWebhookRequest;Lkotlin/jvm/functions/Function2;Ljava/lang/String;Ljava/lang/String;Ldev/inmo/tgbotapi/updateshandlers/webhook/WebhookPrivateKeyConfig;Lkotlinx/coroutines/CoroutineScope;JLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun setWebhookInfoAndStartListenWebhooks$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;ILio/ktor/server/engine/ApplicationEngineFactory;Ldev/inmo/tgbotapi/requests/webhook/SetWebhookRequest;Lkotlin/jvm/functions/Function2;Ljava/lang/String;Ljava/lang/String;Ldev/inmo/tgbotapi/updateshandlers/webhook/WebhookPrivateKeyConfig;Lkotlinx/coroutines/CoroutineScope;JLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun startListenWebhooks (ILio/ktor/server/engine/ApplicationEngineFactory;Lkotlin/jvm/functions/Function2;Ljava/lang/String;Ljava/lang/String;Ldev/inmo/tgbotapi/updateshandlers/webhook/WebhookPrivateKeyConfig;Lkotlinx/coroutines/CoroutineScope;JLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lio/ktor/server/engine/EmbeddedServer; - public static synthetic fun startListenWebhooks$default (ILio/ktor/server/engine/ApplicationEngineFactory;Lkotlin/jvm/functions/Function2;Ljava/lang/String;Ljava/lang/String;Ldev/inmo/tgbotapi/updateshandlers/webhook/WebhookPrivateKeyConfig;Lkotlinx/coroutines/CoroutineScope;JLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lio/ktor/server/engine/EmbeddedServer; + public static final fun includeWebhookHandlingInRoute (Lio/ktor/server/routing/Route;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JLdev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function2;)V + public static synthetic fun includeWebhookHandlingInRoute$default (Lio/ktor/server/routing/Route;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JLdev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V + public static final fun includeWebhookHandlingInRouteWithFlows (Lio/ktor/server/routing/Route;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JLdev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function1;)V + public static synthetic fun includeWebhookHandlingInRouteWithFlows$default (Lio/ktor/server/routing/Route;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function2;JLdev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V + public static final fun setWebhookInfoAndStartListenWebhooks (Ldev/inmo/tgbotapi/bot/RequestsExecutor;ILio/ktor/server/engine/ApplicationEngineFactory;Ldev/inmo/tgbotapi/requests/webhook/SetWebhookRequest;Lkotlin/jvm/functions/Function2;Ljava/lang/String;Ljava/lang/String;Ldev/inmo/tgbotapi/updateshandlers/webhook/WebhookPrivateKeyConfig;Lkotlinx/coroutines/CoroutineScope;JLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Ldev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun setWebhookInfoAndStartListenWebhooks$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;ILio/ktor/server/engine/ApplicationEngineFactory;Ldev/inmo/tgbotapi/requests/webhook/SetWebhookRequest;Lkotlin/jvm/functions/Function2;Ljava/lang/String;Ljava/lang/String;Ldev/inmo/tgbotapi/updateshandlers/webhook/WebhookPrivateKeyConfig;Lkotlinx/coroutines/CoroutineScope;JLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Ldev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun startListenWebhooks (ILio/ktor/server/engine/ApplicationEngineFactory;Lkotlin/jvm/functions/Function2;Ljava/lang/String;Ljava/lang/String;Ldev/inmo/tgbotapi/updateshandlers/webhook/WebhookPrivateKeyConfig;Lkotlinx/coroutines/CoroutineScope;JLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Ldev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function2;)Lio/ktor/server/engine/EmbeddedServer; + public static synthetic fun startListenWebhooks$default (ILio/ktor/server/engine/ApplicationEngineFactory;Lkotlin/jvm/functions/Function2;Ljava/lang/String;Ljava/lang/String;Ldev/inmo/tgbotapi/updateshandlers/webhook/WebhookPrivateKeyConfig;Lkotlinx/coroutines/CoroutineScope;JLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Ldev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lio/ktor/server/engine/EmbeddedServer; } public final class dev/inmo/tgbotapi/types/files/PathedFileAsStreamKt { diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt index f1fcb4c938..d7d2a071b1 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt @@ -14,6 +14,7 @@ import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.* +import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog import io.ktor.client.plugins.HttpRequestTimeoutException import io.ktor.utils.io.CancellationException import kotlinx.coroutines.* @@ -33,20 +34,20 @@ fun TelegramBot.longPollingFlow( mediaGroupsDebounceTimeMillis: Long? = 1000L, ): Flow = channelFlow { if (autoDisableWebhooks) { - runCatching { + runCatchingLogging(logger = Log) { execute(DeleteWebhook()) } } - val contextSafelyExceptionHandler = coroutineContext[ContextSafelyExceptionHandlerKey] - val contextToWork = if (contextSafelyExceptionHandler == null || !autoSkipTimeoutExceptions) { + val contextSafelyExceptionHandler = coroutineContext[ContextSafelyExceptionHandlerKey] ?.handler ?: defaultSafelyExceptionHandler + val contextToWork = if (!autoSkipTimeoutExceptions) { coroutineContext } else { coroutineContext + ContextSafelyExceptionHandler { e -> if (e is HttpRequestTimeoutException || (e is CommonBotException && e.cause is HttpRequestTimeoutException)) { return@ContextSafelyExceptionHandler } else { - contextSafelyExceptionHandler.handler(e) + contextSafelyExceptionHandler(e) } } } @@ -61,7 +62,8 @@ fun TelegramBot.longPollingFlow( send(it) } }, - mediaGroupsDebounceTimeMillis + mediaGroupsDebounceTimeMillis, + logger = Log ); { originalUpdates: List -> originalUpdates.forEach { diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt index b2c4df5376..8a5fe97650 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt @@ -1,11 +1,14 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving +import dev.inmo.kslog.common.KSLog +import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver +import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog import dev.inmo.tgbotapi.utils.extensions.accumulateByKey import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.Channel @@ -19,7 +22,8 @@ import kotlinx.coroutines.launch */ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation( output: UpdateReceiver, - debounceTimeMillis: Long = 1000L + debounceTimeMillis: Long = 1000L, + logger: KSLog = DefaultKTgBotAPIKSLog ): UpdateReceiver { val updatesChannel = Channel(Channel.UNLIMITED) val mediaGroupChannel = Channel>(Channel.UNLIMITED) @@ -29,7 +33,7 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation( ) launch { - launchSafelyWithoutExceptions { + launchLoggingDropExceptions(logger = logger) { for (update in updatesChannel) { val data = update.data when { @@ -40,7 +44,7 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation( } } } - launchSafelyWithoutExceptions { + launchLoggingDropExceptions(logger = logger) { for ((_, mediaGroup) in mediaGroupAccumulatedChannel) { mediaGroup.convertWithMediaGroupUpdates().forEach { output(it) @@ -59,5 +63,6 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation( * @see UpdateReceiver */ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation( + logger: KSLog = DefaultKTgBotAPIKSLog, output: UpdateReceiver -) = updateHandlerWithMediaGroupsAdaptation(output, 1000L) +) = updateHandlerWithMediaGroupsAdaptation(output, 1000L, logger = logger) diff --git a/tgbotapi.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt b/tgbotapi.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt index 09b2271aae..aec99e21aa 100644 --- a/tgbotapi.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt +++ b/tgbotapi.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving +import dev.inmo.kslog.common.KSLog import dev.inmo.micro_utils.coroutines.ExceptionHandler import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.tgbotapi.bot.RequestsExecutor @@ -12,6 +13,7 @@ import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver import dev.inmo.tgbotapi.updateshandlers.UpdatesFilter import dev.inmo.tgbotapi.updateshandlers.webhook.WebhookPrivateKeyConfig +import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog import io.ktor.http.* import io.ktor.server.engine.* import io.ktor.server.request.* @@ -40,9 +42,10 @@ fun Route.includeWebhookHandlingInRoute( scope: CoroutineScope, exceptionsHandler: ExceptionHandler? = null, mediaGroupsDebounceTimeMillis: Long = 1000L, + logger: KSLog = DefaultKTgBotAPIKSLog, block: UpdateReceiver, ) { - val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block, mediaGroupsDebounceTimeMillis) + val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block, mediaGroupsDebounceTimeMillis, logger = logger) post { try { runCatchingSafely { @@ -71,11 +74,13 @@ fun Route.includeWebhookHandlingInRouteWithFlows( scope: CoroutineScope, exceptionsHandler: ExceptionHandler? = null, mediaGroupsDebounceTimeMillis: Long = 1000L, + logger: KSLog = DefaultKTgBotAPIKSLog, block: FlowsUpdatesFilter.() -> Unit, ) = includeWebhookHandlingInRoute( scope, exceptionsHandler, mediaGroupsDebounceTimeMillis, + logger, flowsUpdatesFilter(block = block).asUpdateReceiver ) @@ -105,6 +110,7 @@ fun Unit = {}, additionalEngineConfigurator: TConfiguration.() -> Unit = {}, + logger: KSLog = DefaultKTgBotAPIKSLog, block: UpdateReceiver, ): EmbeddedServer = embeddedServer( @@ -134,12 +140,19 @@ fun Unit = {}, additionalEngineConfigurator: TConfiguration.() -> Unit = {}, + logger: KSLog = Log, block: UpdateReceiver, ): EmbeddedServer = try { execute(setWebhookRequest) startListenWebhooks( - listenPort, - engineFactory, - exceptionsHandler, - listenHost, - listenRoute, - privateKeyConfig, - scope, - mediaGroupsDebounceTimeMillis, - additionalApplicationEnvironmentConfigurator, - additionalEngineConfigurator, - block + listenPort = listenPort, + engineFactory = engineFactory, + exceptionsHandler = exceptionsHandler, + listenHost = listenHost, + listenRoute = listenRoute, + privateKeyConfig = privateKeyConfig, + scope = scope, + mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis, + additionalApplicationEnvironmentConfigurator = additionalApplicationEnvironmentConfigurator, + additionalEngineConfigurator = additionalEngineConfigurator, + logger = logger, + block = block ) } catch (e: Exception) { throw e