diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/BusinessContentMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/BusinessContentMessageImpl.kt new file mode 100644 index 0000000000..35a5ce36e2 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/BusinessContentMessageImpl.kt @@ -0,0 +1,47 @@ +package dev.inmo.tgbotapi.types.message + +import korlibs.time.DateTime +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId +import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.types.chat.* +import dev.inmo.tgbotapi.types.chat.CommonBot +import dev.inmo.tgbotapi.types.chat.User +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage +import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage +import dev.inmo.tgbotapi.types.message.content.MessageContent + +data class BusinessContentMessageImpl( + override val messageId: MessageId, + override val from: User, + override val chat: PreviewPrivateChat, + override val businessConnectionId: BusinessConnectionId, + override val content: T, + override val date: DateTime, + override val editDate: DateTime?, + override val hasProtectedContent: Boolean, + override val forwardOrigin: MessageOrigin?, + override val replyInfo: ReplyInfo?, + override val replyMarkup: InlineKeyboardMarkup?, + override val senderBot: CommonBot?, + override val mediaGroupId: MediaGroupId?, +) : BusinessContentMessage { + constructor( + messageId: MessageId, + from: User, + chat: PreviewPrivateChat, + businessConnectionId: BusinessConnectionId, + content: T, + date: DateTime, + editDate: DateTime?, + hasProtectedContent: Boolean, + forwardInfo: ForwardInfo, + replyTo: AccessibleMessage?, + replyMarkup: InlineKeyboardMarkup?, + senderBot: CommonBot?, + mediaGroupId: MediaGroupId?, + ) : this( + messageId, from, chat, businessConnectionId, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, senderBot, mediaGroupId + ) +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index a7bc91d5d3..2f73f9063a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.message import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.* import dev.inmo.tgbotapi.types.chat.CommonBot @@ -139,6 +140,9 @@ internal data class RawMessage( private val reply_markup: InlineKeyboardMarkup? = null, + // Business + private val business_connection_id: BusinessConnectionId? = null, + // Giveaways private val giveaway_created: GiveawayCreated? = null, private val giveaway_completed: GiveawayPrivateResults? = null, @@ -509,20 +513,38 @@ internal data class RawMessage( ) } } - is PreviewPrivateChat -> PrivateContentMessageImpl( - messageId, - from ?: error("Was detected common message, but owner (sender) of the message was not found"), - chat, - content, - date.asDate, - edit_date?.asDate, - has_protected_content == true, - forward_origin, - replyInfo, - reply_markup, - via_bot, - media_group_id - ) + is PreviewPrivateChat -> if (business_connection_id == null) { + PrivateContentMessageImpl( + messageId, + from ?: error("Was detected common message, but owner (sender) of the message was not found"), + chat, + content, + date.asDate, + edit_date?.asDate, + has_protected_content == true, + forward_origin, + replyInfo, + reply_markup, + via_bot, + media_group_id + ) + } else { + BusinessContentMessageImpl( + messageId, + from ?: error("Was detected common message, but owner (sender) of the message was not found"), + chat, + business_connection_id, + content, + date.asDate, + edit_date?.asDate, + has_protected_content == true, + forward_origin, + replyInfo, + reply_markup, + via_bot, + media_group_id + ) + } else -> error("Unknown type of chat: $chat") } } ?: passport_data ?.let{ diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/BusinessContentMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/BusinessContentMessage.kt new file mode 100644 index 0000000000..e5eb955817 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/BusinessContentMessage.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId +import dev.inmo.tgbotapi.types.chat.PreviewPrivateChat +import dev.inmo.tgbotapi.types.message.content.MessageContent + +interface BusinessContentMessage : PossiblySentViaBotCommonMessage, FromUserMessage { + override val chat: PreviewPrivateChat + override val businessConnectionId: BusinessConnectionId +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt index 31acc87740..23a1759d6b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt @@ -7,5 +7,6 @@ sealed interface CommonMessage : AccessibleMessage, PossiblyEditedMessage, PossiblyReplyMessage, PossiblyMarkedUp, + PossiblyBusinessMessage, PossiblyMediaGroupMessage, ContentMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyBusinessMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyBusinessMessage.kt new file mode 100644 index 0000000000..75002f2b32 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyBusinessMessage.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId + +interface PossiblyBusinessMessage : Message { + val businessConnectionId: BusinessConnectionId? + get() = null +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateContentMessage.kt similarity index 86% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateContentMessage.kt index 590a72737f..bf133680c3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateContentMessage.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.types.message.abstracts -import dev.inmo.tgbotapi.types.chat.PreviewChat import dev.inmo.tgbotapi.types.chat.PreviewPrivateChat import dev.inmo.tgbotapi.types.message.content.MessageContent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/BusinessMessageUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/BusinessMessageUpdate.kt new file mode 100644 index 0000000000..0fb2d718e6 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/BusinessMessageUpdate.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.types.update + +import dev.inmo.tgbotapi.types.UpdateId +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage +import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage +import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate + +data class BusinessMessageUpdate( + override val updateId: UpdateId, + override val data: BusinessContentMessage<*> +) : BaseSentMessageUpdate { + override fun copy(newData: BusinessContentMessage<*>) = copy(updateId, newData) +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt index 8ac9ead5c6..c28a4683dc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt @@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.update import dev.inmo.tgbotapi.types.UpdateId import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate data class ChannelPostUpdate( override val updateId: UpdateId, override val data: AccessibleMessage ) : BaseSentMessageUpdate { - override fun copy(newData: AccessibleMessage): BaseSentMessageUpdate = copy(updateId, newData) + override fun copy(newData: ContentMessage<*>): BaseSentMessageUpdate = copy(updateId, newData) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt index 497435c8e8..98165a8843 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt @@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.update import dev.inmo.tgbotapi.types.UpdateId import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate data class MessageUpdate( override val updateId: UpdateId, override val data: AccessibleMessage ) : BaseSentMessageUpdate { - override fun copy(newData: AccessibleMessage) = copy(updateId, newData) + override fun copy(newData: ContentMessage<*>) = copy(updateId, newData) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt index 7816e42a59..7a044cdeab 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.types.update.abstracts import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage interface BaseSentMessageUpdate : BaseMessageUpdate { - fun copy(newData: AccessibleMessage): BaseSentMessageUpdate + fun copy(newData: ContentMessage<*>): BaseSentMessageUpdate } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt index a81465abeb..7ea2203aa4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt @@ -1,24 +1,7 @@ package dev.inmo.tgbotapi.utils.extensions -import dev.inmo.tgbotapi.types.message.AnonymousForumContentMessageImpl -import dev.inmo.tgbotapi.types.message.AnonymousGroupContentMessageImpl -import dev.inmo.tgbotapi.types.message.ChannelContentMessageImpl -import dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl -import dev.inmo.tgbotapi.types.message.CommonGroupContentMessageImpl -import dev.inmo.tgbotapi.types.message.ConnectedFromChannelGroupContentMessageImpl -import dev.inmo.tgbotapi.types.message.FromChannelForumContentMessageImpl -import dev.inmo.tgbotapi.types.message.PrivateContentMessageImpl -import dev.inmo.tgbotapi.types.message.UnconnectedFromChannelGroupContentMessageImpl -import dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.CommonGroupContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.ConnectedFromChannelGroupContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.FromChannelForumContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage -import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.UnconnectedFromChannelGroupContentMessage +import dev.inmo.tgbotapi.types.message.* +import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent import dev.inmo.tgbotapi.types.message.content.MediaGroupContent import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent @@ -46,6 +29,21 @@ fun List>.asMedia sourceMessage.authorSignature, sourceMessage.mediaGroupId ) + is BusinessContentMessage -> BusinessContentMessageImpl( + sourceMessage.messageId, + sourceMessage.user, + sourceMessage.chat, + sourceMessage.businessConnectionId, + content, + sourceMessage.date, + sourceMessage.editDate, + sourceMessage.hasProtectedContent, + sourceMessage.forwardOrigin, + sourceMessage.replyInfo, + sourceMessage.replyMarkup, + sourceMessage.senderBot, + sourceMessage.mediaGroupId + ) is PrivateContentMessage -> PrivateContentMessageImpl( sourceMessage.messageId, sourceMessage.user,