diff --git a/CHANGELOG.md b/CHANGELOG.md index 717ffefd83..05ef3ecbc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 1.0.0 +* `Core`: + * Constructor of `UnknownInlineKeyboardButton` is not internal and can be created with any `json` + ## 0.38.13 * `Core`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt index 098e8c582a..85f65a2b13 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.games.CallbackGame import kotlinx.serialization.* -import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.* /** * Some button of [dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup]. See inheritors and visit @@ -15,10 +15,14 @@ sealed interface InlineKeyboardButton { } @Serializable -data class UnknownInlineKeyboardButton internal constructor( - override val text: String, +data class UnknownInlineKeyboardButton ( val rawData: JsonElement -) : InlineKeyboardButton +) : InlineKeyboardButton { + override val text: String + get() = runCatching { + rawData.jsonObject[textField] ?.jsonPrimitive ?.content + }.getOrNull() ?: "" +} /** * This type of button must always be the first button in the first row. Visit diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt index 86695d33b0..1beef89dd8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt @@ -37,7 +37,7 @@ object InlineKeyboardButtonSerializer : KSerializer { return (json as? JsonObject) ?.let { resolveSerializer(it) } ?.let { nonstrictJsonFormat.decodeFromJsonElement(it, json) - } ?: UnknownInlineKeyboardButton("", json) + } ?: UnknownInlineKeyboardButton(json) } override fun serialize(encoder: Encoder, value: InlineKeyboardButton) {