mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-03 15:19:30 +00:00
add support of InputStoryContent
This commit is contained in:
@@ -277,7 +277,9 @@ const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat"
|
||||
const val switchInlineQueryChosenChatField = "switch_inline_query_chosen_chat"
|
||||
const val switchInlineQueryField = "switch_inline_query"
|
||||
const val isAnimatedField = "is_animated"
|
||||
const val isAnimationField = "is_animation"
|
||||
const val isVideoField = "is_video"
|
||||
const val coverFrameTimeStampField = "cover_frame_timestamp"
|
||||
const val inviteLinkField = "invite_link"
|
||||
const val viaChatFolderInviteLinkField = "via_chat_folder_invite_link"
|
||||
const val viaJoinRequestField = "via_join_request"
|
||||
|
@@ -1,10 +1,19 @@
|
||||
package dev.inmo.tgbotapi.types.stories
|
||||
|
||||
import dev.inmo.tgbotapi.requests.abstracts.MultipartFile
|
||||
import dev.inmo.tgbotapi.types.photoField
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.utils.decodeDataAndJson
|
||||
import kotlinx.serialization.EncodeDefault
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
@Serializable
|
||||
sealed interface InputStoryContent {
|
||||
sealed interface Type {
|
||||
val name: String
|
||||
@@ -17,12 +26,52 @@ sealed interface InputStoryContent {
|
||||
@SerialName(photoField)
|
||||
val photo: MultipartFile
|
||||
) : InputStoryContent {
|
||||
override val type: Type
|
||||
get() = Companion
|
||||
@EncodeDefault
|
||||
override val type: Type = Companion
|
||||
override val media: Pair<String, MultipartFile>
|
||||
get() = photoField to photo
|
||||
|
||||
companion object : Type {
|
||||
override val name: String
|
||||
get() = "photo"
|
||||
}
|
||||
}
|
||||
@Serializable
|
||||
data class Video (
|
||||
@SerialName(videoField)
|
||||
val video: MultipartFile,
|
||||
@SerialName(durationField)
|
||||
val duration: DoubleSeconds? = null,
|
||||
@SerialName(coverFrameTimeStampField)
|
||||
val coverFrameTimeStamp: DoubleSeconds? = null,
|
||||
@SerialName(isAnimationField)
|
||||
val isAnimation: Boolean = false
|
||||
) : InputStoryContent {
|
||||
@EncodeDefault
|
||||
override val type: Type = Companion
|
||||
override val media: Pair<String, MultipartFile>
|
||||
get() = videoField to video
|
||||
|
||||
companion object : Type {
|
||||
override val name: String
|
||||
get() = "video"
|
||||
}
|
||||
}
|
||||
|
||||
companion object : KSerializer<InputStoryContent> {
|
||||
private val serializer = JsonObject.serializer()
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = serializer.descriptor
|
||||
|
||||
override fun serialize(encoder: Encoder, value: InputStoryContent) {
|
||||
when (value) {
|
||||
is Photo -> Photo.serializer().serialize(encoder, value)
|
||||
is Video -> Video.serializer().serialize(encoder, value)
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): InputStoryContent {
|
||||
throw UnsupportedOperationException("InputStoryContent cannot be deserialized for now")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user