mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
commit
1facfbc2b7
10
CHANGELOG.md
10
CHANGELOG.md
@ -38,6 +38,16 @@
|
|||||||
and size of retrieved updates is equal to 100 (max count of retrieved updates)
|
and size of retrieved updates is equal to 100 (max count of retrieved updates)
|
||||||
* Extensions `getUpdates` now will receive only not nullable `limit` parameter
|
* 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
|
### 0.26.3
|
||||||
|
|
||||||
* `TelegramBotAPI`:
|
* `TelegramBotAPI`:
|
||||||
|
@ -3,12 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
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.*
|
||||||
import kotlinx.serialization.builtins.ListSerializer
|
import kotlinx.serialization.builtins.ListSerializer
|
||||||
|
|
||||||
private val updatesListSerializer = ListSerializer(
|
private val updatesListSerializer = ListSerializer(
|
||||||
UpdateSerializerWithoutDeserialization
|
UpdateSerializerWithoutSerialization
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -36,10 +36,11 @@ data class CallbackDataInlineKeyboardButton(
|
|||||||
@Serializable
|
@Serializable
|
||||||
data class CallbackGameInlineKeyboardButton(
|
data class CallbackGameInlineKeyboardButton(
|
||||||
@SerialName(textField)
|
@SerialName(textField)
|
||||||
override val text: String,
|
override val text: String
|
||||||
|
) : InlineKeyboardButton() {
|
||||||
@SerialName(callbackGameField)
|
@SerialName(callbackGameField)
|
||||||
val callbackGame: CallbackGame
|
private val callbackGame = CallbackGame
|
||||||
) : InlineKeyboardButton()
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class LoginURLInlineKeyboardButton(
|
data class LoginURLInlineKeyboardButton(
|
||||||
|
@ -3,8 +3,4 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.games
|
|||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class CallbackGame {
|
object CallbackGame
|
||||||
init {
|
|
||||||
TODO()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -64,12 +64,16 @@ internal data class RawUpdate constructor(
|
|||||||
raw
|
raw
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (e: SerializationException) {
|
} catch (e: Error) {
|
||||||
UnknownUpdateType(
|
when (e) {
|
||||||
updateId,
|
is SerializationException,
|
||||||
raw.toString(),
|
is NotImplementedError -> UnknownUpdateType(
|
||||||
raw
|
updateId,
|
||||||
)
|
raw.toString(),
|
||||||
|
raw
|
||||||
|
)
|
||||||
|
else -> throw e
|
||||||
|
}
|
||||||
}.also {
|
}.also {
|
||||||
initedUpdate = it
|
initedUpdate = it
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ data class UnknownUpdateType(
|
|||||||
val rawJson: JsonElement
|
val rawJson: JsonElement
|
||||||
) : Update
|
) : Update
|
||||||
|
|
||||||
internal object UpdateSerializerWithoutDeserialization : KSerializer<Update> {
|
internal object UpdateSerializerWithoutSerialization : KSerializer<Update> {
|
||||||
override val descriptor: SerialDescriptor = JsonElementSerializer.descriptor
|
override val descriptor: SerialDescriptor = JsonElementSerializer.descriptor
|
||||||
|
|
||||||
override fun deserialize(decoder: Decoder): Update = UpdateDeserializationStrategy.deserialize(decoder)
|
override fun deserialize(decoder: Decoder): Update = UpdateDeserializationStrategy.deserialize(decoder)
|
||||||
|
@ -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.abstracts.InputFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.webhook.SetWebhook
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.webhook.SetWebhook
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
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.abstracts.*
|
||||||
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.updateshandlers.UpdateReceiver
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdateReceiver
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.webhook.WebhookPrivateKeyConfig
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.webhook.WebhookPrivateKeyConfig
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.convertWithMediaGroupUpdates
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat
|
|
||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
import io.ktor.request.receiveText
|
import io.ktor.request.receiveText
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
@ -45,6 +41,7 @@ suspend fun RequestsExecutor.setWebhook(
|
|||||||
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||||
allowedUpdates: List<String>? = null,
|
allowedUpdates: List<String>? = null,
|
||||||
maxAllowedConnections: Int? = null,
|
maxAllowedConnections: Int? = null,
|
||||||
|
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||||
block: UpdateReceiver<Update>
|
block: UpdateReceiver<Update>
|
||||||
): Job {
|
): Job {
|
||||||
val executeDeferred = certificate ?.let {
|
val executeDeferred = certificate ?.let {
|
||||||
@ -74,12 +71,18 @@ suspend fun RequestsExecutor.setWebhook(
|
|||||||
module {
|
module {
|
||||||
routing {
|
routing {
|
||||||
post(listenRoute) {
|
post(listenRoute) {
|
||||||
val asJson = nonstrictJsonFormat.parseJson(call.receiveText())
|
handleSafely(
|
||||||
val update = nonstrictJsonFormat.fromJson(
|
{
|
||||||
RawUpdate.serializer(),
|
exceptionsHandler ?.invoke(it)
|
||||||
asJson
|
}
|
||||||
)
|
) {
|
||||||
updatesChannel.send(update.asUpdate(asJson))
|
val asJson = nonstrictJsonFormat.parseJson(call.receiveText())
|
||||||
|
val update = nonstrictJsonFormat.fromJson(
|
||||||
|
UpdateDeserializationStrategy,
|
||||||
|
asJson
|
||||||
|
)
|
||||||
|
updatesChannel.send(update)
|
||||||
|
}
|
||||||
call.respond("Ok")
|
call.respond("Ok")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,11 +116,6 @@ suspend fun RequestsExecutor.setWebhook(
|
|||||||
launch {
|
launch {
|
||||||
for (update in updatesChannel) {
|
for (update in updatesChannel) {
|
||||||
val data = update.data
|
val data = update.data
|
||||||
if (data is MediaGroupUpdate) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
when (data) {
|
when (data) {
|
||||||
is MediaGroupMessage -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
|
is MediaGroupMessage -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
|
||||||
else -> block(update)
|
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(
|
suspend fun RequestsExecutor.setWebhook(
|
||||||
url: String,
|
url: String,
|
||||||
port: Int,
|
port: Int,
|
||||||
|
@ -7,6 +7,6 @@ uuid_version=0.1.0
|
|||||||
ktor_version=1.3.2
|
ktor_version=1.3.2
|
||||||
|
|
||||||
library_group=com.github.insanusmokrassar
|
library_group=com.github.insanusmokrassar
|
||||||
library_version=0.26.3
|
library_version=0.26.4
|
||||||
|
|
||||||
gradle_bintray_plugin_version=1.8.4
|
gradle_bintray_plugin_version=1.8.4
|
||||||
|
Loading…
Reference in New Issue
Block a user