disableContentTypeDetection

This commit is contained in:
InsanusMokrassar 2020-11-04 23:33:48 +06:00
parent 179bb66183
commit 2a33216006
4 changed files with 41 additions and 4 deletions

View File

@ -16,6 +16,7 @@
* New fields `ExtendedChannelChat#linkedGroupChatId` and `ExtendedSupergroupChat#linkedChannelChatId`
* New fields `ExtendedSupergroupChat#location`
* New fields `AudioFile#fileName` and `VideoFile#fileName`
* New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection`
## 0.29.4

View File

@ -14,6 +14,15 @@ import dev.inmo.tgbotapi.utils.mapOfNotNull
import dev.inmo.tgbotapi.utils.throwRangeError
import kotlinx.serialization.*
/**
* Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned.
* Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
*
* @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile]
*
* @see ContentMessage
* @see DocumentContent
*/
fun SendDocument(
chatId: ChatIdentifier,
document: InputFile,
@ -22,7 +31,8 @@ fun SendDocument(
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
replyMarkup: KeyboardMarkup? = null,
disableContentTypeDetection: Boolean? = null
): Request<ContentMessage<DocumentContent>> {
val documentAsFileId = (document as? FileId) ?.fileId
val documentAsFile = document as? MultipartFile
@ -37,7 +47,8 @@ fun SendDocument(
parseMode,
disableNotification,
replyToMessageId,
replyMarkup
replyMarkup,
disableContentTypeDetection
)
return if (documentAsFile == null && thumbAsFile == null) {
@ -53,6 +64,15 @@ fun SendDocument(
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<DocumentContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
/**
* Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned.
* Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
*
* @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile]
*
* @see ContentMessage
* @see DocumentContent
*/
@Serializable
data class SendDocumentData internal constructor(
@SerialName(chatIdField)
@ -70,7 +90,9 @@ data class SendDocumentData internal constructor(
@SerialName(replyToMessageIdField)
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
override val replyMarkup: KeyboardMarkup? = null,
@SerialName(disableContentTypeDetectionField)
val disableContentTypeDetection: Boolean? = null
) : DataRequest<ContentMessage<DocumentContent>>,
SendMessageRequest<ContentMessage<DocumentContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<DocumentContent>>,

View File

@ -86,6 +86,7 @@ const val disableWebPagePreviewField = "disable_web_page_preview"
const val disableNotificationField = "disable_notification"
const val replyToMessageIdField = "reply_to_message_id"
const val replyMarkupField = "reply_markup"
const val disableContentTypeDetectionField = "disable_content_type_detection"
const val supportStreamingField = "support_streaming"
const val livePeriodField = "live_period"
const val isBotField = "is_bot"

View File

@ -4,19 +4,32 @@ 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
import dev.inmo.tgbotapi.types.disableContentTypeDetectionField
import dev.inmo.tgbotapi.types.files.DocumentFile
import dev.inmo.tgbotapi.types.mediaField
import kotlinx.serialization.*
internal const val documentInputMediaType = "document"
/**
* 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
*/
@Serializable
data class InputMediaDocument(
override val file: InputFile,
override val caption: String? = null,
@SerialName(parseModeField)
override val parseMode: ParseMode? = null,
override val thumb: InputFile? = null
override val thumb: InputFile? = null,
@SerialName(disableContentTypeDetectionField)
val disableContentTypeDetection: Boolean? = null
) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia, CaptionedOutput {
override val type: String = documentInputMediaType