mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-16 13:49:26 +00:00
add support of copy/forward/delete messages
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.abstracts.types
|
||||
|
||||
import dev.inmo.tgbotapi.types.MessageId
|
||||
|
||||
interface MessagesAction: ChatRequest {
|
||||
val messageIds: List<MessageId>
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package dev.inmo.tgbotapi.requests
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.types.MessageAction
|
||||
import dev.inmo.tgbotapi.abstracts.types.MessagesAction
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
@Serializable
|
||||
data class DeleteMessages(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdsField)
|
||||
override val messageIds: List<MessageId>
|
||||
) : SimpleRequest<Boolean>, MessagesAction {
|
||||
override fun method(): String = "deleteMessages"
|
||||
|
||||
init {
|
||||
require(messageIds.size in deleteMessagesLimit) {
|
||||
"Messages count for deleteMessages must be in $deleteMessagesLimit range"
|
||||
}
|
||||
}
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
package dev.inmo.tgbotapi.requests
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.types.DisableNotification
|
||||
import dev.inmo.tgbotapi.abstracts.types.MessagesAction
|
||||
import dev.inmo.tgbotapi.abstracts.types.ProtectContent
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.OptionallyMessageThreadRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
|
||||
fun ForwardMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
messageIds: Array<MessageId>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = ForwardMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = fromChatId,
|
||||
messageIds = messageIds.toList(),
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
fun ForwardMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
messageId: MessageId,
|
||||
vararg messageIds: MessageId,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = ForwardMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = fromChatId,
|
||||
messageIds = (listOf(messageId) + messageIds.toList()),
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ForwardMessages (
|
||||
@SerialName(chatIdField)
|
||||
val toChatId: ChatIdentifier,
|
||||
@SerialName(fromChatIdField)
|
||||
val fromChatId: ChatIdentifier,
|
||||
@SerialName(messageIdsField)
|
||||
override val messageIds: List<MessageId>,
|
||||
@SerialName(messageThreadIdField)
|
||||
override val threadId: MessageThreadId? = toChatId.threadId,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(protectContentField)
|
||||
override val protectContent: Boolean = false,
|
||||
@SerialName(removeCaptionField)
|
||||
private val removeCaption: Boolean = false
|
||||
): SimpleRequest<List<MessageId>>,
|
||||
MessagesAction,
|
||||
ProtectContent,
|
||||
OptionallyMessageThreadRequest,
|
||||
DisableNotification {
|
||||
override val chatId: ChatIdentifier
|
||||
get() = fromChatId
|
||||
|
||||
init {
|
||||
require(messageIds.size in forwardMessagesLimit) {
|
||||
"Messages count for forwardMessages must be in $forwardMessagesLimit range"
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "forwardMessages"
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<List<MessageId>>
|
||||
get() = ListSerializer(MessageIdSerializer)
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
package dev.inmo.tgbotapi.requests.send
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.types.DisableNotification
|
||||
import dev.inmo.tgbotapi.abstracts.types.MessagesAction
|
||||
import dev.inmo.tgbotapi.abstracts.types.ProtectContent
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.OptionallyMessageThreadRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.message.textsources.TextSource
|
||||
import dev.inmo.tgbotapi.types.message.ParseMode
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.message.*
|
||||
import dev.inmo.tgbotapi.types.message.toRawMessageEntities
|
||||
import dev.inmo.tgbotapi.utils.extensions.makeString
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
|
||||
fun CopyMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
messageIds: Array<MessageId>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = CopyMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = fromChatId,
|
||||
messageIds = messageIds.toList(),
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
fun CopyMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
messageId: MessageId,
|
||||
vararg messageIds: MessageId,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = CopyMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = fromChatId,
|
||||
messageIds = (listOf(messageId) + messageIds.toList()),
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class CopyMessages (
|
||||
@SerialName(chatIdField)
|
||||
val toChatId: ChatIdentifier,
|
||||
@SerialName(fromChatIdField)
|
||||
val fromChatId: ChatIdentifier,
|
||||
@SerialName(messageIdsField)
|
||||
override val messageIds: List<MessageId>,
|
||||
@SerialName(messageThreadIdField)
|
||||
override val threadId: MessageThreadId? = toChatId.threadId,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(protectContentField)
|
||||
override val protectContent: Boolean = false,
|
||||
@SerialName(removeCaptionField)
|
||||
private val removeCaption: Boolean = false
|
||||
): SimpleRequest<List<MessageId>>,
|
||||
MessagesAction,
|
||||
ProtectContent,
|
||||
OptionallyMessageThreadRequest,
|
||||
DisableNotification {
|
||||
override val chatId: ChatIdentifier
|
||||
get() = fromChatId
|
||||
|
||||
init {
|
||||
require(messageIds.size in copyMessagesLimit) {
|
||||
"Messages count for copyMessages must be in $copyMessagesLimit range"
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "copyMessages"
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<List<MessageId>>
|
||||
get() = ListSerializer(MessageIdSerializer)
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
@@ -175,6 +175,10 @@ val keywordsInStickerLimit = 0 .. 20
|
||||
|
||||
val stickerKeywordLengthLimit = 0 .. 64
|
||||
|
||||
val forwardMessagesLimit = 1 .. 100
|
||||
val copyMessagesLimit = forwardMessagesLimit
|
||||
val deleteMessagesLimit = forwardMessagesLimit
|
||||
|
||||
const val botActionActualityTime: Seconds = 5
|
||||
|
||||
val cloudStorageKeyLimit = 1 .. 128
|
||||
@@ -196,6 +200,7 @@ const val tgWebAppStartParamField = "tgWebAppStartParam"
|
||||
const val chatIdField = "chat_id"
|
||||
const val senderChatIdField = "sender_chat_id"
|
||||
const val messageIdField = "message_id"
|
||||
const val messageIdsField = "message_ids"
|
||||
const val actorChatField = "actor_chat"
|
||||
const val messageThreadIdField = "message_thread_id"
|
||||
const val mediaGroupIdField = "media_group_id"
|
||||
@@ -205,6 +210,7 @@ const val disableWebPagePreviewField = "disable_web_page_preview"
|
||||
const val linkPreviewOptionsField = "link_preview_options"
|
||||
const val disableNotificationField = "disable_notification"
|
||||
const val protectContentField = "protect_content"
|
||||
const val removeCaptionField = "remove_caption"
|
||||
const val replyToMessageIdField = "reply_to_message_id"
|
||||
const val allowSendingWithoutReplyField = "allow_sending_without_reply"
|
||||
const val replyMarkupField = "reply_markup"
|
||||
|
Reference in New Issue
Block a user