mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
UnknownUpdateType even if serialization exception
This commit is contained in:
parent
82d3b3bc48
commit
31f7c7f31b
@ -46,6 +46,9 @@
|
|||||||
[PR-80](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/80))
|
[PR-80](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/80))
|
||||||
* `UnknownInlineKeyboardButton` was added. It is unavailable for creating, but you can receive it, for example, in
|
* `UnknownInlineKeyboardButton` was added. It is unavailable for creating, but you can receive it, for example, in
|
||||||
`InlineQueryResult`
|
`InlineQueryResult`
|
||||||
|
* `Update` now will be created even if was `SerializationException` inside of creating the update instance - in this
|
||||||
|
case will be created `UnknownUpdateType`
|
||||||
|
* `UnknownUpdateType$rawJson` value now is included (`JsonElement`)
|
||||||
|
|
||||||
### 0.26.2
|
### 0.26.2
|
||||||
|
|
||||||
|
@ -13,8 +13,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.polls.PollAnswer
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdateType
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdateType
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import kotlinx.serialization.json.JsonElement
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -42,25 +41,34 @@ internal data class RawUpdate constructor(
|
|||||||
* @return One of children of [Update] interface or null in case of unknown type of update
|
* @return One of children of [Update] interface or null in case of unknown type of update
|
||||||
*/
|
*/
|
||||||
fun asUpdate(raw: JsonElement): Update {
|
fun asUpdate(raw: JsonElement): Update {
|
||||||
return initedUpdate ?: when {
|
return initedUpdate ?: try {
|
||||||
edited_message != null -> EditMessageUpdate(updateId, edited_message)
|
when {
|
||||||
message != null -> MessageUpdate(updateId, message)
|
edited_message != null -> EditMessageUpdate(updateId, edited_message)
|
||||||
edited_channel_post != null -> EditChannelPostUpdate(updateId, edited_channel_post)
|
message != null -> MessageUpdate(updateId, message)
|
||||||
channel_post != null -> ChannelPostUpdate(updateId, channel_post)
|
edited_channel_post != null -> EditChannelPostUpdate(updateId, edited_channel_post)
|
||||||
|
channel_post != null -> ChannelPostUpdate(updateId, channel_post)
|
||||||
|
|
||||||
chosen_inline_result != null -> ChosenInlineResultUpdate(updateId, chosen_inline_result.asChosenInlineResult)
|
chosen_inline_result != null -> ChosenInlineResultUpdate(updateId, chosen_inline_result.asChosenInlineResult)
|
||||||
inline_query != null -> InlineQueryUpdate(updateId, inline_query.asInlineQuery)
|
inline_query != null -> InlineQueryUpdate(updateId, inline_query.asInlineQuery)
|
||||||
callback_query != null -> CallbackQueryUpdate(
|
callback_query != null -> CallbackQueryUpdate(
|
||||||
|
updateId,
|
||||||
|
callback_query.asCallbackQuery(raw.jsonObject["callback_query"].toString())
|
||||||
|
)
|
||||||
|
shipping_query != null -> ShippingQueryUpdate(updateId, shipping_query)
|
||||||
|
pre_checkout_query != null -> PreCheckoutQueryUpdate(updateId, pre_checkout_query)
|
||||||
|
poll != null -> PollUpdate(updateId, poll)
|
||||||
|
poll_answer != null -> PollAnswerUpdate(updateId, poll_answer)
|
||||||
|
else -> UnknownUpdateType(
|
||||||
|
updateId,
|
||||||
|
raw.toString(),
|
||||||
|
raw
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch (e: SerializationException) {
|
||||||
|
UnknownUpdateType(
|
||||||
updateId,
|
updateId,
|
||||||
callback_query.asCallbackQuery(raw.jsonObject["callback_query"].toString())
|
raw.toString(),
|
||||||
)
|
raw
|
||||||
shipping_query != null -> ShippingQueryUpdate(updateId, shipping_query)
|
|
||||||
pre_checkout_query != null -> PreCheckoutQueryUpdate(updateId, pre_checkout_query)
|
|
||||||
poll != null -> PollUpdate(updateId, poll)
|
|
||||||
poll_answer != null -> PollAnswerUpdate(updateId, poll_answer)
|
|
||||||
else -> UnknownUpdateType(
|
|
||||||
updateId,
|
|
||||||
raw.toString()
|
|
||||||
)
|
)
|
||||||
}.also {
|
}.also {
|
||||||
initedUpdate = it
|
initedUpdate = it
|
||||||
|
@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
import kotlinx.serialization.json.JsonElement
|
||||||
import kotlinx.serialization.json.JsonElementSerializer
|
import kotlinx.serialization.json.JsonElementSerializer
|
||||||
|
|
||||||
interface Update {
|
interface Update {
|
||||||
@ -13,7 +14,8 @@ interface Update {
|
|||||||
|
|
||||||
data class UnknownUpdateType(
|
data class UnknownUpdateType(
|
||||||
override val updateId: UpdateIdentifier,
|
override val updateId: UpdateIdentifier,
|
||||||
override val data: String
|
override val data: String,
|
||||||
|
val rawJson: JsonElement
|
||||||
) : Update
|
) : Update
|
||||||
|
|
||||||
internal object UpdateSerializerWithoutDeserialization : KSerializer<Update> {
|
internal object UpdateSerializerWithoutDeserialization : KSerializer<Update> {
|
||||||
|
Loading…
Reference in New Issue
Block a user