mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
UnknownCallbackQueryType
This commit is contained in:
parent
cf814fcecb
commit
f4fe680cac
@ -84,6 +84,7 @@ while they can work incorrectly
|
||||
* `UnknownUpdateType`
|
||||
* `UnknownMessageType`
|
||||
* `UnknownChatType`
|
||||
* `UnknownCallbackQueryType`
|
||||
|
||||
## 0.21.0 TelegramBotAPI 4.5
|
||||
|
||||
|
@ -8,3 +8,10 @@ interface CallbackQuery {
|
||||
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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user