mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
some progress in business connections support
This commit is contained in:
parent
6ac6ad0c0a
commit
be9c0cff61
@ -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
|
||||
)
|
||||
}
|
@ -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{
|
||||
|
@ -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
|
||||
}
|
@ -7,5 +7,6 @@ sealed interface CommonMessage<out T: MessageContent> : AccessibleMessage,
|
||||
PossiblyEditedMessage,
|
||||
PossiblyReplyMessage,
|
||||
PossiblyMarkedUp,
|
||||
PossiblyBusinessMessage,
|
||||
PossiblyMediaGroupMessage<T>,
|
||||
ContentMessage<T>
|
||||
|
@ -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
|
||||
}
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.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,
|
||||
|
Loading…
Reference in New Issue
Block a user