2020-10-04 11:06:30 +00:00
|
|
|
package dev.inmo.tgbotapi.types.InputMedia
|
2018-12-26 08:07:24 +00:00
|
|
|
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
|
|
|
|
import dev.inmo.tgbotapi.requests.abstracts.*
|
|
|
|
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
|
|
|
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
2020-11-04 17:33:48 +00:00
|
|
|
import dev.inmo.tgbotapi.types.disableContentTypeDetectionField
|
2020-10-30 14:38:02 +00:00
|
|
|
import dev.inmo.tgbotapi.types.files.DocumentFile
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.types.mediaField
|
2020-10-30 14:38:02 +00:00
|
|
|
import kotlinx.serialization.*
|
|
|
|
|
|
|
|
internal const val documentInputMediaType = "document"
|
2018-12-26 08:07:24 +00:00
|
|
|
|
2020-11-04 17:33:48 +00:00
|
|
|
/**
|
|
|
|
* Represents a general file to be sent. See https://core.telegram.org/bots/api#inputmediadocument
|
|
|
|
*
|
|
|
|
* @param disableContentTypeDetection Disables automatic server-side content type detection for files uploaded using
|
|
|
|
* multipart/form-data. Always used by Telegram system as true, if the document is sent as part of an album.
|
|
|
|
*
|
|
|
|
* @see InputFile
|
|
|
|
* @see MultipartFile
|
|
|
|
* @see FileId
|
|
|
|
*/
|
2018-12-26 08:07:24 +00:00
|
|
|
@Serializable
|
|
|
|
data class InputMediaDocument(
|
2019-04-15 11:30:09 +00:00
|
|
|
override val file: InputFile,
|
2018-12-26 08:07:24 +00:00
|
|
|
override val caption: String? = null,
|
|
|
|
@SerialName(parseModeField)
|
|
|
|
override val parseMode: ParseMode? = null,
|
2020-11-04 17:33:48 +00:00
|
|
|
override val thumb: InputFile? = null,
|
|
|
|
@SerialName(disableContentTypeDetectionField)
|
|
|
|
val disableContentTypeDetection: Boolean? = null
|
2020-11-02 06:39:12 +00:00
|
|
|
) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia, CaptionedOutput {
|
2020-10-30 14:38:02 +00:00
|
|
|
override val type: String = documentInputMediaType
|
|
|
|
|
|
|
|
override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this)
|
2018-12-26 08:07:24 +00:00
|
|
|
|
|
|
|
@SerialName(mediaField)
|
2020-08-29 06:08:37 +00:00
|
|
|
override val media: String
|
2020-11-02 07:51:20 +00:00
|
|
|
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
|
2018-12-26 08:07:24 +00:00
|
|
|
}
|
2020-10-30 14:38:02 +00:00
|
|
|
|
|
|
|
fun DocumentFile.toInputMediaDocument(
|
|
|
|
caption: String? = null,
|
|
|
|
parseMode: ParseMode? = null
|
|
|
|
) = InputMediaDocument(
|
|
|
|
fileId,
|
|
|
|
caption,
|
|
|
|
parseMode,
|
|
|
|
thumb ?.fileId
|
|
|
|
)
|