mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-06-03 00:15:27 +00:00
127 lines
5.0 KiB
Kotlin
127 lines
5.0 KiB
Kotlin
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media
|
|
|
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.ReplyingMarkupSendMessageRequest
|
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.StickerContent
|
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
|
|
import kotlinx.serialization.*
|
|
import kotlinx.serialization.json.JsonObject
|
|
|
|
fun SendSticker(
|
|
chatId: ChatIdentifier,
|
|
sticker: InputFile,
|
|
disableNotification: Boolean = false,
|
|
replyToMessageId: MessageIdentifier? = null,
|
|
replyMarkup: KeyboardMarkup? = null
|
|
): Request<ContentMessage<StickerContent>> = SendStickerByFileId(
|
|
chatId,
|
|
sticker as? FileId,
|
|
disableNotification,
|
|
replyToMessageId,
|
|
replyMarkup
|
|
).let {
|
|
when (sticker) {
|
|
is MultipartFile -> SendStickerByFile(it, sticker)
|
|
is FileId -> it
|
|
}
|
|
}
|
|
|
|
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<StickerContent>>
|
|
= TelegramBotAPIMessageDeserializationStrategyClass()
|
|
|
|
@Serializable
|
|
data class SendStickerByFileId internal constructor(
|
|
@SerialName(chatIdField)
|
|
override val chatId: ChatIdentifier,
|
|
@SerialName(stickerField)
|
|
val sticker: FileId? = null,
|
|
@SerialName(disableNotificationField)
|
|
override val disableNotification: Boolean = false,
|
|
@SerialName(replyToMessageIdField)
|
|
override val replyToMessageId: MessageIdentifier? = null,
|
|
@SerialName(replyMarkupField)
|
|
override val replyMarkup: KeyboardMarkup? = null
|
|
) : SendMessageRequest<ContentMessage<StickerContent>>, ReplyingMarkupSendMessageRequest<ContentMessage<StickerContent>> {
|
|
override fun method(): String = "sendSticker"
|
|
override val resultDeserializer: DeserializationStrategy<ContentMessage<StickerContent>>
|
|
get() = commonResultDeserializer
|
|
override val requestSerializer: SerializationStrategy<*>
|
|
get() = serializer()
|
|
}
|
|
|
|
data class SendStickerByFile internal constructor(
|
|
@Transient
|
|
private val sendStickerByFileId: SendStickerByFileId,
|
|
val sticker: MultipartFile
|
|
) : MultipartRequest<ContentMessage<StickerContent>>, Request<ContentMessage<StickerContent>> by sendStickerByFileId {
|
|
override val mediaMap: Map<String, MultipartFile> = mapOf(stickerField to sticker)
|
|
override val paramsJson: JsonObject = sendStickerByFileId.toJsonWithoutNulls(SendStickerByFileId.serializer())
|
|
}
|
|
|
|
|
|
suspend fun RequestsExecutor.sendSticker(
|
|
chatId: ChatIdentifier,
|
|
sticker: FileId,
|
|
disableNotification: Boolean = false,
|
|
replyToMessageId: MessageIdentifier? = null,
|
|
replyMarkup: KeyboardMarkup? = null
|
|
) = execute(
|
|
SendStickerByFileId(chatId, sticker, disableNotification, replyToMessageId, replyMarkup)
|
|
)
|
|
|
|
suspend fun RequestsExecutor.sendSticker(
|
|
chatId: ChatIdentifier,
|
|
sticker: MultipartFile,
|
|
disableNotification: Boolean = false,
|
|
replyToMessageId: MessageIdentifier? = null,
|
|
replyMarkup: KeyboardMarkup? = null
|
|
) = execute(
|
|
SendStickerByFile(
|
|
SendStickerByFileId(chatId, null, disableNotification, replyToMessageId, replyMarkup),
|
|
sticker
|
|
)
|
|
)
|
|
|
|
suspend fun RequestsExecutor.sendSticker(
|
|
chat: Chat,
|
|
sticker: FileId,
|
|
disableNotification: Boolean = false,
|
|
replyToMessageId: MessageIdentifier? = null,
|
|
replyMarkup: KeyboardMarkup? = null
|
|
) = sendSticker(chat.id, sticker, disableNotification, replyToMessageId, replyMarkup)
|
|
|
|
suspend fun RequestsExecutor.sendSticker(
|
|
chat: Chat,
|
|
sticker: MultipartFile,
|
|
disableNotification: Boolean = false,
|
|
replyToMessageId: MessageIdentifier? = null,
|
|
replyMarkup: KeyboardMarkup? = null
|
|
) = sendSticker(chat.id, sticker, disableNotification, replyToMessageId, replyMarkup)
|
|
|
|
suspend fun RequestsExecutor.sendSticker(
|
|
chatId: ChatIdentifier,
|
|
sticker: Sticker,
|
|
disableNotification: Boolean = false,
|
|
replyToMessageId: MessageIdentifier? = null,
|
|
replyMarkup: KeyboardMarkup? = null
|
|
) = sendSticker(
|
|
chatId, sticker.fileId, disableNotification, replyToMessageId, replyMarkup
|
|
)
|
|
|
|
suspend fun RequestsExecutor.sendSticker(
|
|
chat: Chat,
|
|
sticker: Sticker,
|
|
disableNotification: Boolean = false,
|
|
replyToMessageId: MessageIdentifier? = null,
|
|
replyMarkup: KeyboardMarkup? = null
|
|
) = sendSticker(chat.id, sticker.fileId, disableNotification, replyToMessageId, replyMarkup)
|
|
|