From 94f8c971c5f1be760ba18f71e4ec31e461c49488 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Apr 2020 13:01:17 +0600 Subject: [PATCH 1/6] started 0.26.4 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae543f5dec..0babb1e0ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ and size of retrieved updates is equal to 100 (max count of retrieved updates) * Extensions `getUpdates` now will receive only not nullable `limit` parameter +### 0.26.4 + ### 0.26.3 * `TelegramBotAPI`: diff --git a/gradle.properties b/gradle.properties index 019b89b8dd..991a298c71 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,6 +7,6 @@ uuid_version=0.1.0 ktor_version=1.3.2 library_group=com.github.insanusmokrassar -library_version=0.26.3 +library_version=0.26.4 gradle_bintray_plugin_version=1.8.4 From 3f896c22404fdbd310acbb479286e02697052293 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Apr 2020 13:05:57 +0600 Subject: [PATCH 2/6] fix not implemented error thrown --- CHANGELOG.md | 4 ++++ .../TelegramBotAPI/types/update/RawUpdate.kt | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0babb1e0ed..ba88d7b936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,10 @@ ### 0.26.4 +* `TelegramBotAPI`: + * Now any getting of updates will return `UnknownUpdateType` when inside of deserialization will be + `SerializationException` or `NotImplemented` error + ### 0.26.3 * `TelegramBotAPI`: diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt index f96d60bdb2..e27b840986 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt @@ -64,12 +64,16 @@ internal data class RawUpdate constructor( raw ) } - } catch (e: SerializationException) { - UnknownUpdateType( - updateId, - raw.toString(), - raw - ) + } catch (e: Error) { + when (e) { + is SerializationException, + is NotImplementedError -> UnknownUpdateType( + updateId, + raw.toString(), + raw + ) + else -> throw e + } }.also { initedUpdate = it } From 17f64f9b48f7705dcd6f283b235ba63d7634b430 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Apr 2020 13:08:05 +0600 Subject: [PATCH 3/6] CallbackGame update --- CHANGELOG.md | 2 ++ .../TelegramBotAPI/types/games/CallbackGame.kt | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba88d7b936..60358d2838 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ * `TelegramBotAPI`: * Now any getting of updates will return `UnknownUpdateType` when inside of deserialization will be `SerializationException` or `NotImplemented` error + * `CallbackGame` currently is an object + * It is possible to use `CallbackGame` for now ### 0.26.3 diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/games/CallbackGame.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/games/CallbackGame.kt index 1d74fd18ff..32da936cf7 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/games/CallbackGame.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/games/CallbackGame.kt @@ -3,8 +3,4 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.games import kotlinx.serialization.Serializable @Serializable -class CallbackGame { - init { - TODO() - } -} +object CallbackGame From 459942de36f7b108959197a4d527f525885e3b59 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Apr 2020 13:16:46 +0600 Subject: [PATCH 4/6] webhook update handling enhancement --- CHANGELOG.md | 1 + .../utils/extensions/Webhooks.kt | 54 ++++++++++++++----- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60358d2838..a25cf9aaa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ `SerializationException` or `NotImplemented` error * `CallbackGame` currently is an object * It is possible to use `CallbackGame` for now + * Now it is possible to pass exception handler in webhook ### 0.26.3 diff --git a/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt b/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt index fd995cde3d..b79136f8fc 100644 --- a/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt +++ b/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt @@ -11,8 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdateReceiver import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.webhook.WebhookPrivateKeyConfig -import com.github.insanusmokrassar.TelegramBotAPI.utils.convertWithMediaGroupUpdates -import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat +import com.github.insanusmokrassar.TelegramBotAPI.utils.* import io.ktor.application.call import io.ktor.request.receiveText import io.ktor.response.respond @@ -45,6 +44,7 @@ suspend fun RequestsExecutor.setWebhook( scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), allowedUpdates: List? = null, maxAllowedConnections: Int? = null, + exceptionsHandler: (suspend (Exception) -> Unit)? = null, block: UpdateReceiver ): Job { val executeDeferred = certificate ?.let { @@ -74,12 +74,18 @@ suspend fun RequestsExecutor.setWebhook( module { routing { post(listenRoute) { - val asJson = nonstrictJsonFormat.parseJson(call.receiveText()) - val update = nonstrictJsonFormat.fromJson( - RawUpdate.serializer(), - asJson - ) - updatesChannel.send(update.asUpdate(asJson)) + handleSafely( + { + exceptionsHandler ?.invoke(it) + } + ) { + val asJson = nonstrictJsonFormat.parseJson(call.receiveText()) + val update = nonstrictJsonFormat.fromJson( + RawUpdate.serializer(), + asJson + ) + updatesChannel.send(update.asUpdate(asJson)) + } call.respond("Ok") } } @@ -113,11 +119,6 @@ suspend fun RequestsExecutor.setWebhook( launch { for (update in updatesChannel) { val data = update.data - if (data is MediaGroupUpdate) { - - } else { - - } when (data) { is MediaGroupMessage -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate) else -> block(update) @@ -139,6 +140,33 @@ suspend fun RequestsExecutor.setWebhook( } } +suspend fun RequestsExecutor.setWebhook( + url: String, + port: Int, + engineFactory: ApplicationEngineFactory<*, *>, + listenHost: String = "0.0.0.0", + listenRoute: String = "/", + certificate: InputFile? = null, + privateKeyConfig: WebhookPrivateKeyConfig? = null, + scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), + allowedUpdates: List? = null, + maxAllowedConnections: Int? = null, + block: UpdateReceiver +) = setWebhook( + url, + port, + engineFactory, + listenHost, + listenRoute, + certificate, + privateKeyConfig, + scope, + allowedUpdates, + maxAllowedConnections, + null, + block +) + suspend fun RequestsExecutor.setWebhook( url: String, port: Int, From eda3003b7d2fb26db3e7301a9c2dfb6b5f776be2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Apr 2020 13:20:15 +0600 Subject: [PATCH 5/6] change the way how we are deserializing updates in webhooks --- .../TelegramBotAPI/requests/GetUpdates.kt | 4 ++-- .../TelegramBotAPI/types/update/abstracts/Update.kt | 2 +- .../TelegramBotAPI/utils/extensions/Webhooks.kt | 9 +++------ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt index 3169c63936..bb682b4063 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt @@ -3,12 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update -import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateSerializerWithoutDeserialization +import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateSerializerWithoutSerialization import kotlinx.serialization.* import kotlinx.serialization.builtins.ListSerializer private val updatesListSerializer = ListSerializer( - UpdateSerializerWithoutDeserialization + UpdateSerializerWithoutSerialization ) @Serializable diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt index d361301b31..fa2129f854 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt @@ -18,7 +18,7 @@ data class UnknownUpdateType( val rawJson: JsonElement ) : Update -internal object UpdateSerializerWithoutDeserialization : KSerializer { +internal object UpdateSerializerWithoutSerialization : KSerializer { override val descriptor: SerialDescriptor = JsonElementSerializer.descriptor override fun deserialize(decoder: Decoder): Update = UpdateDeserializationStrategy.deserialize(decoder) diff --git a/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt b/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt index b79136f8fc..64aaf9caf8 100644 --- a/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt +++ b/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt @@ -4,10 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile import com.github.insanusmokrassar.TelegramBotAPI.requests.webhook.SetWebhook import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage -import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.MediaGroupUpdate -import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate -import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate -import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update +import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdateReceiver import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.webhook.WebhookPrivateKeyConfig @@ -81,10 +78,10 @@ suspend fun RequestsExecutor.setWebhook( ) { val asJson = nonstrictJsonFormat.parseJson(call.receiveText()) val update = nonstrictJsonFormat.fromJson( - RawUpdate.serializer(), + UpdateDeserializationStrategy, asJson ) - updatesChannel.send(update.asUpdate(asJson)) + updatesChannel.send(update) } call.respond("Ok") } From 914a0662a97ff953e361d1426e9e1aa9421be649 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Apr 2020 14:11:46 +0600 Subject: [PATCH 6/6] CallbackGameInlineKeyboardButton now have only one income parameter --- CHANGELOG.md | 1 + .../buttons/InlineKeyboardButtons/InlineKeyboardButton.kt | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a25cf9aaa0..ccdc4a2965 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ `SerializationException` or `NotImplemented` error * `CallbackGame` currently is an object * It is possible to use `CallbackGame` for now + * `CallbackGameInlineKeyboardButton` now will not accept `callbackGame` as income object * Now it is possible to pass exception handler in webhook ### 0.26.3 diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt index 0e5c18508e..c8ea32297b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt @@ -36,10 +36,11 @@ data class CallbackDataInlineKeyboardButton( @Serializable data class CallbackGameInlineKeyboardButton( @SerialName(textField) - override val text: String, + override val text: String +) : InlineKeyboardButton() { @SerialName(callbackGameField) - val callbackGame: CallbackGame -) : InlineKeyboardButton() + private val callbackGame = CallbackGame +} @Serializable data class LoginURLInlineKeyboardButton(