mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
fix for media fields in input media
This commit is contained in:
parent
bbc56fe94c
commit
957649603b
@ -1,6 +1,5 @@
|
||||
package dev.inmo.tgbotapi.requests.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaFileAttachmentName
|
||||
import dev.inmo.tgbotapi.utils.StorageFile
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.*
|
||||
@ -12,6 +11,14 @@ sealed class InputFile {
|
||||
abstract val fileId: String
|
||||
}
|
||||
|
||||
internal inline val InputFile.attachFileId
|
||||
get() = "attach://$fileId"
|
||||
internal inline val InputFile.fileIdToSend
|
||||
get() = when (this) {
|
||||
is FileId -> fileId
|
||||
is MultipartFile -> attachFileId
|
||||
}
|
||||
|
||||
// TODO:: add checks for file url/file id regex
|
||||
/**
|
||||
* Contains file id or file url
|
||||
@ -30,12 +37,6 @@ internal object InputFileSerializer : KSerializer<InputFile> {
|
||||
override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString())
|
||||
}
|
||||
|
||||
internal val InputFile.asMediaData: String
|
||||
get() = when (this) {
|
||||
is FileId -> fileId
|
||||
is MultipartFile -> fileId.toInputMediaFileAttachmentName()
|
||||
}
|
||||
|
||||
// TODO:: add checks for files size
|
||||
/**
|
||||
* Contains info about file for sending
|
||||
|
@ -23,5 +23,5 @@ data class InputMediaAnimation(
|
||||
|
||||
@SerialName(mediaField)
|
||||
override val media: String
|
||||
init { media = file.fileId } // crutch until js compiling will be fixed
|
||||
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ data class InputMediaAudio(
|
||||
|
||||
@SerialName(mediaField)
|
||||
override val media: String
|
||||
init { media = file.fileId } // crutch until js compiling will be fixed
|
||||
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
|
||||
}
|
||||
|
||||
fun AudioFile.toInputMediaAudio(
|
||||
|
@ -24,7 +24,7 @@ data class InputMediaDocument(
|
||||
|
||||
@SerialName(mediaField)
|
||||
override val media: String
|
||||
init { media = file.fileId } // crutch until js compiling will be fixed
|
||||
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
|
||||
}
|
||||
|
||||
fun DocumentFile.toInputMediaDocument(
|
||||
|
@ -24,7 +24,7 @@ data class InputMediaPhoto(
|
||||
|
||||
@SerialName(mediaField)
|
||||
override val media: String
|
||||
init { media = file.fileId } // crutch until js compiling will be fixed
|
||||
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
|
||||
}
|
||||
|
||||
fun PhotoSize.toInputMediaPhoto(
|
||||
|
@ -26,5 +26,5 @@ data class InputMediaVideo(
|
||||
|
||||
@SerialName(mediaField)
|
||||
override val media: String
|
||||
init { media = file.fileId } // crutch until js compiling will be fixed
|
||||
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user