1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

UnknownCallbackQueryType

This commit is contained in:
InsanusMokrassar 2020-01-23 03:59:59 +06:00
parent cf814fcecb
commit f4fe680cac
4 changed files with 27 additions and 7 deletions

View File

@ -84,6 +84,7 @@ while they can work incorrectly
* `UnknownUpdateType`
* `UnknownMessageType`
* `UnknownChatType`
* `UnknownCallbackQueryType`
## 0.21.0 TelegramBotAPI 4.5

View File

@ -7,4 +7,11 @@ interface CallbackQuery {
val id: CallbackQueryIdentifier
val user: User
val chatInstance: String
}
}
data class UnknownCallbackQueryType(
override val id: CallbackQueryIdentifier,
override val user: User,
override val chatInstance: String,
val raw: String
) : CallbackQuery

View File

@ -22,13 +22,21 @@ internal data class RawCallbackQuery(
@SerialName("game_short_name")
val gameShortName: String? = null
) {
val asCallbackQuery: CallbackQuery by lazy {
when {
private var inited: CallbackQuery? = null
fun asCallbackQuery(raw: String): CallbackQuery {
return inited ?: when {
message != null && data != null -> MessageDataCallbackQuery(id, from, chatInstance, message, data)
message != null && gameShortName != null -> MessageGameShortNameCallbackQuery(id, from, chatInstance, message, gameShortName)
inlineMessageId != null && data != null -> InlineMessageIdDataCallbackQuery(id, from, chatInstance, inlineMessageId, data)
inlineMessageId != null && gameShortName != null -> InlineMessageIdGameShortNameCallbackQuery(id, from, chatInstance, inlineMessageId, gameShortName)
else -> throw IllegalStateException("Strange answer from server, can't create callback query")
else -> UnknownCallbackQueryType(
id,
from,
chatInstance,
raw
)
}.also {
inited = it
}
}
}

View File

@ -14,6 +14,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement
@Serializable
internal data class RawUpdate constructor(
@ -38,7 +39,7 @@ internal data class RawUpdate constructor(
/**
* @return One of children of [Update] interface or null in case of unknown type of update
*/
fun asUpdate(raw: String): Update {
fun asUpdate(raw: JsonElement): Update {
return initedUpdate ?: when {
edited_message != null -> EditMessageUpdate(updateId, edited_message)
message != null -> MessageUpdate(updateId, message)
@ -47,13 +48,16 @@ internal data class RawUpdate constructor(
chosen_inline_result != null -> ChosenInlineResultUpdate(updateId, chosen_inline_result.asChosenInlineResult)
inline_query != null -> InlineQueryUpdate(updateId, inline_query.asInlineQuery)
callback_query != null -> CallbackQueryUpdate(updateId, callback_query.asCallbackQuery)
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)
else -> UnknownUpdateType(
updateId,
raw
raw.toString()
)
}.also {
initedUpdate = it