1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

some progress in business connections support

This commit is contained in:
InsanusMokrassar 2024-04-16 16:00:15 +06:00
parent 6ac6ad0c0a
commit be9c0cff61
11 changed files with 138 additions and 37 deletions

View File

@ -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<T: MessageContent>(
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<T> {
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
)
}

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.message package dev.inmo.tgbotapi.types.message
import dev.inmo.tgbotapi.types.* 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.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.* import dev.inmo.tgbotapi.types.chat.*
import dev.inmo.tgbotapi.types.chat.CommonBot import dev.inmo.tgbotapi.types.chat.CommonBot
@ -139,6 +140,9 @@ internal data class RawMessage(
private val reply_markup: InlineKeyboardMarkup? = null, private val reply_markup: InlineKeyboardMarkup? = null,
// Business
private val business_connection_id: BusinessConnectionId? = null,
// Giveaways // Giveaways
private val giveaway_created: GiveawayCreated? = null, private val giveaway_created: GiveawayCreated? = null,
private val giveaway_completed: GiveawayPrivateResults? = null, private val giveaway_completed: GiveawayPrivateResults? = null,
@ -509,7 +513,8 @@ internal data class RawMessage(
) )
} }
} }
is PreviewPrivateChat -> PrivateContentMessageImpl( is PreviewPrivateChat -> if (business_connection_id == null) {
PrivateContentMessageImpl(
messageId, messageId,
from ?: error("Was detected common message, but owner (sender) of the message was not found"), from ?: error("Was detected common message, but owner (sender) of the message was not found"),
chat, chat,
@ -523,6 +528,23 @@ internal data class RawMessage(
via_bot, via_bot,
media_group_id 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") else -> error("Unknown type of chat: $chat")
} }
} ?: passport_data ?.let{ } ?: passport_data ?.let{

View File

@ -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<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, FromUserMessage {
override val chat: PreviewPrivateChat
override val businessConnectionId: BusinessConnectionId
}

View File

@ -7,5 +7,6 @@ sealed interface CommonMessage<out T: MessageContent> : AccessibleMessage,
PossiblyEditedMessage, PossiblyEditedMessage,
PossiblyReplyMessage, PossiblyReplyMessage,
PossiblyMarkedUp, PossiblyMarkedUp,
PossiblyBusinessMessage,
PossiblyMediaGroupMessage<T>, PossiblyMediaGroupMessage<T>,
ContentMessage<T> ContentMessage<T>

View File

@ -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
}

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.message.abstracts 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.chat.PreviewPrivateChat
import dev.inmo.tgbotapi.types.message.content.MessageContent import dev.inmo.tgbotapi.types.message.content.MessageContent

View File

@ -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)
}

View File

@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.update
import dev.inmo.tgbotapi.types.UpdateId import dev.inmo.tgbotapi.types.UpdateId
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
data class ChannelPostUpdate( data class ChannelPostUpdate(
override val updateId: UpdateId, override val updateId: UpdateId,
override val data: AccessibleMessage override val data: AccessibleMessage
) : BaseSentMessageUpdate { ) : BaseSentMessageUpdate {
override fun copy(newData: AccessibleMessage): BaseSentMessageUpdate = copy(updateId, newData) override fun copy(newData: ContentMessage<*>): BaseSentMessageUpdate = copy(updateId, newData)
} }

View File

@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.update
import dev.inmo.tgbotapi.types.UpdateId import dev.inmo.tgbotapi.types.UpdateId
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
data class MessageUpdate( data class MessageUpdate(
override val updateId: UpdateId, override val updateId: UpdateId,
override val data: AccessibleMessage override val data: AccessibleMessage
) : BaseSentMessageUpdate { ) : BaseSentMessageUpdate {
override fun copy(newData: AccessibleMessage) = copy(updateId, newData) override fun copy(newData: ContentMessage<*>) = copy(updateId, newData)
} }

View File

@ -1,7 +1,8 @@
package dev.inmo.tgbotapi.types.update.abstracts package dev.inmo.tgbotapi.types.update.abstracts
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
interface BaseSentMessageUpdate : BaseMessageUpdate { interface BaseSentMessageUpdate : BaseMessageUpdate {
fun copy(newData: AccessibleMessage): BaseSentMessageUpdate fun copy(newData: ContentMessage<*>): BaseSentMessageUpdate
} }

View File

@ -1,24 +1,7 @@
package dev.inmo.tgbotapi.utils.extensions package dev.inmo.tgbotapi.utils.extensions
import dev.inmo.tgbotapi.types.message.AnonymousForumContentMessageImpl import dev.inmo.tgbotapi.types.message.*
import dev.inmo.tgbotapi.types.message.AnonymousGroupContentMessageImpl import dev.inmo.tgbotapi.types.message.abstracts.*
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.content.MediaGroupCollectionContent import dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
@ -46,6 +29,21 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.authorSignature, sourceMessage.authorSignature,
sourceMessage.mediaGroupId 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( is PrivateContentMessage -> PrivateContentMessageImpl(
sourceMessage.messageId, sourceMessage.messageId,
sourceMessage.user, sourceMessage.user,