2020-10-04 11:06:30 +00:00
|
|
|
package dev.inmo.tgbotapi.requests.send.media
|
2018-12-26 08:07:24 +00:00
|
|
|
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.requests.abstracts.*
|
2023-03-11 15:17:59 +00:00
|
|
|
import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
|
|
|
|
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
|
|
|
|
import dev.inmo.tgbotapi.types.*
|
|
|
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
|
|
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
|
|
|
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
2022-05-01 05:52:02 +00:00
|
|
|
import dev.inmo.tgbotapi.types.message.content.StickerContent
|
2023-03-10 06:43:09 +00:00
|
|
|
import dev.inmo.tgbotapi.utils.mapOfNotNull
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.utils.toJsonWithoutNulls
|
2018-12-26 08:07:24 +00:00
|
|
|
import kotlinx.serialization.*
|
|
|
|
import kotlinx.serialization.json.JsonObject
|
2023-03-10 06:43:09 +00:00
|
|
|
import kotlinx.serialization.json.JsonPrimitive
|
|
|
|
import kotlinx.serialization.json.buildJsonObject
|
|
|
|
import kotlinx.serialization.json.put
|
2018-12-26 08:07:24 +00:00
|
|
|
|
|
|
|
fun SendSticker(
|
|
|
|
chatId: ChatIdentifier,
|
|
|
|
sticker: InputFile,
|
2022-11-10 10:24:20 +00:00
|
|
|
threadId: MessageThreadId? = chatId.threadId,
|
2023-03-10 06:43:09 +00:00
|
|
|
emoji: String? = null,
|
2018-12-26 08:07:24 +00:00
|
|
|
disableNotification: Boolean = false,
|
2022-01-01 14:13:22 +00:00
|
|
|
protectContent: Boolean = false,
|
2022-09-14 18:17:18 +00:00
|
|
|
replyToMessageId: MessageId? = null,
|
2020-11-05 15:33:11 +00:00
|
|
|
allowSendingWithoutReply: Boolean? = null,
|
2018-12-26 08:07:24 +00:00
|
|
|
replyMarkup: KeyboardMarkup? = null
|
2020-01-15 05:17:53 +00:00
|
|
|
): Request<ContentMessage<StickerContent>> = SendStickerByFileId(
|
2018-12-26 08:07:24 +00:00
|
|
|
chatId,
|
2023-03-11 15:17:59 +00:00
|
|
|
sticker,
|
2022-11-07 17:02:58 +00:00
|
|
|
threadId,
|
2018-12-26 08:07:24 +00:00
|
|
|
disableNotification,
|
2022-01-01 14:13:22 +00:00
|
|
|
protectContent,
|
2018-12-26 08:07:24 +00:00
|
|
|
replyToMessageId,
|
2020-11-05 15:33:11 +00:00
|
|
|
allowSendingWithoutReply,
|
2018-12-26 08:07:24 +00:00
|
|
|
replyMarkup
|
|
|
|
).let {
|
|
|
|
when (sticker) {
|
2023-03-11 15:17:59 +00:00
|
|
|
is MultipartFile -> CommonMultipartFileRequest(
|
|
|
|
it,
|
|
|
|
listOf(sticker).associateBy { it.fileId }
|
|
|
|
)
|
2018-12-26 08:07:24 +00:00
|
|
|
is FileId -> it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 05:17:53 +00:00
|
|
|
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<StickerContent>>
|
|
|
|
= TelegramBotAPIMessageDeserializationStrategyClass()
|
|
|
|
|
2018-12-26 08:07:24 +00:00
|
|
|
@Serializable
|
|
|
|
data class SendStickerByFileId internal constructor(
|
|
|
|
@SerialName(chatIdField)
|
|
|
|
override val chatId: ChatIdentifier,
|
|
|
|
@SerialName(stickerField)
|
2023-03-11 15:17:59 +00:00
|
|
|
val sticker: InputFile,
|
2022-11-07 17:02:58 +00:00
|
|
|
@SerialName(messageThreadIdField)
|
2022-11-10 10:24:20 +00:00
|
|
|
override val threadId: MessageThreadId? = chatId.threadId,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(disableNotificationField)
|
|
|
|
override val disableNotification: Boolean = false,
|
2022-01-01 14:13:22 +00:00
|
|
|
@SerialName(protectContentField)
|
|
|
|
override val protectContent: Boolean = false,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(replyToMessageIdField)
|
2022-09-14 18:17:18 +00:00
|
|
|
override val replyToMessageId: MessageId? = null,
|
2020-11-05 15:33:11 +00:00
|
|
|
@SerialName(allowSendingWithoutReplyField)
|
|
|
|
override val allowSendingWithoutReply: Boolean? = null,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(replyMarkupField)
|
|
|
|
override val replyMarkup: KeyboardMarkup? = null
|
2020-01-15 05:17:53 +00:00
|
|
|
) : SendMessageRequest<ContentMessage<StickerContent>>, ReplyingMarkupSendMessageRequest<ContentMessage<StickerContent>> {
|
2018-12-26 08:07:24 +00:00
|
|
|
override fun method(): String = "sendSticker"
|
2020-01-15 05:17:53 +00:00
|
|
|
override val resultDeserializer: DeserializationStrategy<ContentMessage<StickerContent>>
|
|
|
|
get() = commonResultDeserializer
|
2019-12-02 08:35:37 +00:00
|
|
|
override val requestSerializer: SerializationStrategy<*>
|
|
|
|
get() = serializer()
|
2018-12-26 08:07:24 +00:00
|
|
|
}
|