1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +00:00

Merge pull request #83 from InsanusMokrassar/0.26.4

0.26.4
This commit is contained in:
InsanusMokrassar 2020-04-22 15:08:35 +06:00 committed by GitHub
commit 1facfbc2b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 71 additions and 35 deletions

View File

@ -38,6 +38,16 @@
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
* `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
* `CallbackGameInlineKeyboardButton` now will not accept `callbackGame` as income object
* Now it is possible to pass exception handler in webhook
### 0.26.3
* `TelegramBotAPI`:

View File

@ -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

View File

@ -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(

View File

@ -3,8 +3,4 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.games
import kotlinx.serialization.Serializable
@Serializable
class CallbackGame {
init {
TODO()
}
}
object CallbackGame

View File

@ -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
}

View File

@ -18,7 +18,7 @@ data class UnknownUpdateType(
val rawJson: JsonElement
) : Update
internal object UpdateSerializerWithoutDeserialization : KSerializer<Update> {
internal object UpdateSerializerWithoutSerialization : KSerializer<Update> {
override val descriptor: SerialDescriptor = JsonElementSerializer.descriptor
override fun deserialize(decoder: Decoder): Update = UpdateDeserializationStrategy.deserialize(decoder)

View File

@ -4,15 +4,11 @@ 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
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 +41,7 @@ suspend fun RequestsExecutor.setWebhook(
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
allowedUpdates: List<String>? = null,
maxAllowedConnections: Int? = null,
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
block: UpdateReceiver<Update>
): Job {
val executeDeferred = certificate ?.let {
@ -74,12 +71,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(
UpdateDeserializationStrategy,
asJson
)
updatesChannel.send(update)
}
call.respond("Ok")
}
}
@ -113,11 +116,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 +137,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<String>? = null,
maxAllowedConnections: Int? = null,
block: UpdateReceiver<Update>
) = setWebhook(
url,
port,
engineFactory,
listenHost,
listenRoute,
certificate,
privateKeyConfig,
scope,
allowedUpdates,
maxAllowedConnections,
null,
block
)
suspend fun RequestsExecutor.setWebhook(
url: String,
port: Int,

View File

@ -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