diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/AbstractRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/AbstractRequestCallFactory.kt index f950f30e5b..9a633f38a5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/AbstractRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/AbstractRequestCallFactory.kt @@ -9,6 +9,7 @@ import dev.inmo.tgbotapi.bot.exceptions.newRequestException import dev.inmo.tgbotapi.requests.GetUpdatesRequest import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.Response +import dev.inmo.tgbotapi.types.message.textsources.pre import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import io.ktor.client.HttpClient @@ -16,6 +17,7 @@ import io.ktor.client.plugins.timeout import io.ktor.client.request.* import io.ktor.client.statement.bodyAsText import io.ktor.http.ContentType +import io.ktor.http.content.* import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json import kotlin.collections.set @@ -33,7 +35,14 @@ abstract class AbstractRequestCallFactory( jsonFormatter: Json ): T? { val preparedBody = prepareCallBody(client, urlsKeeper, request) ?: return null - logger.v { "Prepared body for $request: $preparedBody" } + logger.v { + val bodyValue = if (preparedBody is TextContent) { + preparedBody.text + } else { + preparedBody.toString() + } + "Prepared body for $request: $bodyValue" + } client.post { url( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/LinkPreviewOptions.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/LinkPreviewOptions.kt index c998468b48..5890f7d686 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/LinkPreviewOptions.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/LinkPreviewOptions.kt @@ -13,7 +13,7 @@ sealed interface LinkPreviewOptions { val preferLargeMedia: Boolean val showAboveText: Boolean - @Serializable + @Serializable(LinkPreviewOptions.Companion::class) data object Disabled : LinkPreviewOptions { @Required @EncodeDefault @@ -29,7 +29,7 @@ sealed interface LinkPreviewOptions { get() = false } - @Serializable + @Serializable(LinkPreviewOptions.Companion::class) data class Large( @SerialName(urlField) override val url: String?, @@ -48,7 +48,7 @@ sealed interface LinkPreviewOptions { get() = false } - @Serializable + @Serializable(LinkPreviewOptions.Companion::class) data class Small( @SerialName(urlField) override val url: String?, @@ -67,7 +67,7 @@ sealed interface LinkPreviewOptions { get() = false } - @Serializable + @Serializable(LinkPreviewOptions.Companion::class) data class Default( @SerialName(urlField) override val url: String?, @@ -96,9 +96,7 @@ sealed interface LinkPreviewOptions { val preferLargeMedia: Boolean = false, @SerialName(showAboveTextField) val showAboveText: Boolean = false, - ) { - - } + ) companion object : KSerializer { override val descriptor: SerialDescriptor @@ -116,13 +114,16 @@ sealed interface LinkPreviewOptions { } override fun serialize(encoder: Encoder, value: LinkPreviewOptions) { - when (value) { - is Disabled -> Disabled.serializer().serialize(encoder, value) - is Large -> Large.serializer().serialize(encoder, value) - is Default -> Default.serializer().serialize(encoder, value) - is Small -> Small.serializer().serialize(encoder, value) - } + Surrogate.serializer().serialize( + encoder, + Surrogate( + isDisabled = value.isDisabled, + url = value.url, + preferSmallMedia = value.preferSmallMedia, + preferLargeMedia = value.preferLargeMedia, + showAboveText = value.showAboveText + ) + ) } - } } \ No newline at end of file