mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
fixes in LinkPreviewOptions
This commit is contained in:
parent
bdae774c62
commit
86c86dfb8a
@ -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(
|
||||
|
@ -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<LinkPreviewOptions> {
|
||||
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
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user