mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +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.GetUpdatesRequest
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.Response
|
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.DefaultKTgBotAPIKSLog
|
||||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
@ -16,6 +17,7 @@ import io.ktor.client.plugins.timeout
|
|||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.bodyAsText
|
import io.ktor.client.statement.bodyAsText
|
||||||
import io.ktor.http.ContentType
|
import io.ktor.http.ContentType
|
||||||
|
import io.ktor.http.content.*
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
@ -33,7 +35,14 @@ abstract class AbstractRequestCallFactory(
|
|||||||
jsonFormatter: Json
|
jsonFormatter: Json
|
||||||
): T? {
|
): T? {
|
||||||
val preparedBody = prepareCallBody(client, urlsKeeper, request) ?: return null
|
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 {
|
client.post {
|
||||||
url(
|
url(
|
||||||
|
@ -13,7 +13,7 @@ sealed interface LinkPreviewOptions {
|
|||||||
val preferLargeMedia: Boolean
|
val preferLargeMedia: Boolean
|
||||||
val showAboveText: Boolean
|
val showAboveText: Boolean
|
||||||
|
|
||||||
@Serializable
|
@Serializable(LinkPreviewOptions.Companion::class)
|
||||||
data object Disabled : LinkPreviewOptions {
|
data object Disabled : LinkPreviewOptions {
|
||||||
@Required
|
@Required
|
||||||
@EncodeDefault
|
@EncodeDefault
|
||||||
@ -29,7 +29,7 @@ sealed interface LinkPreviewOptions {
|
|||||||
get() = false
|
get() = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable(LinkPreviewOptions.Companion::class)
|
||||||
data class Large(
|
data class Large(
|
||||||
@SerialName(urlField)
|
@SerialName(urlField)
|
||||||
override val url: String?,
|
override val url: String?,
|
||||||
@ -48,7 +48,7 @@ sealed interface LinkPreviewOptions {
|
|||||||
get() = false
|
get() = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable(LinkPreviewOptions.Companion::class)
|
||||||
data class Small(
|
data class Small(
|
||||||
@SerialName(urlField)
|
@SerialName(urlField)
|
||||||
override val url: String?,
|
override val url: String?,
|
||||||
@ -67,7 +67,7 @@ sealed interface LinkPreviewOptions {
|
|||||||
get() = false
|
get() = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable(LinkPreviewOptions.Companion::class)
|
||||||
data class Default(
|
data class Default(
|
||||||
@SerialName(urlField)
|
@SerialName(urlField)
|
||||||
override val url: String?,
|
override val url: String?,
|
||||||
@ -96,9 +96,7 @@ sealed interface LinkPreviewOptions {
|
|||||||
val preferLargeMedia: Boolean = false,
|
val preferLargeMedia: Boolean = false,
|
||||||
@SerialName(showAboveTextField)
|
@SerialName(showAboveTextField)
|
||||||
val showAboveText: Boolean = false,
|
val showAboveText: Boolean = false,
|
||||||
) {
|
)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object : KSerializer<LinkPreviewOptions> {
|
companion object : KSerializer<LinkPreviewOptions> {
|
||||||
override val descriptor: SerialDescriptor
|
override val descriptor: SerialDescriptor
|
||||||
@ -116,13 +114,16 @@ sealed interface LinkPreviewOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun serialize(encoder: Encoder, value: LinkPreviewOptions) {
|
override fun serialize(encoder: Encoder, value: LinkPreviewOptions) {
|
||||||
when (value) {
|
Surrogate.serializer().serialize(
|
||||||
is Disabled -> Disabled.serializer().serialize(encoder, value)
|
encoder,
|
||||||
is Large -> Large.serializer().serialize(encoder, value)
|
Surrogate(
|
||||||
is Default -> Default.serializer().serialize(encoder, value)
|
isDisabled = value.isDisabled,
|
||||||
is Small -> Small.serializer().serialize(encoder, value)
|
url = value.url,
|
||||||
}
|
preferSmallMedia = value.preferSmallMedia,
|
||||||
|
preferLargeMedia = value.preferLargeMedia,
|
||||||
|
showAboveText = value.showAboveText
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user