1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-01 07:25:23 +00:00
tgbotapi/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt

575 lines
26 KiB
Kotlin
Raw Normal View History

2020-10-04 11:06:30 +00:00
package dev.inmo.tgbotapi.types.message
2018-12-26 08:07:24 +00:00
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
2022-04-21 18:16:41 +00:00
import dev.inmo.tgbotapi.types.chat.*
import dev.inmo.tgbotapi.types.chat.CommonBot
import dev.inmo.tgbotapi.types.chat.User
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.types.dice.Dice
import dev.inmo.tgbotapi.types.files.*
2022-04-17 12:15:24 +00:00
import dev.inmo.tgbotapi.types.files.Sticker
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.types.games.RawGame
2024-01-07 11:40:41 +00:00
import dev.inmo.tgbotapi.types.giveaway.*
2024-01-09 05:43:04 +00:00
import dev.inmo.tgbotapi.types.message.content.GiveawayContent
2020-11-04 19:12:14 +00:00
import dev.inmo.tgbotapi.types.location.Location
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.types.message.ChatEvents.*
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicEdited
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicHidden
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidden
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed
2021-03-09 13:19:15 +00:00
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
2021-12-20 08:07:45 +00:00
import dev.inmo.tgbotapi.types.message.abstracts.*
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.types.message.content.*
2022-05-01 05:52:02 +00:00
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
import dev.inmo.tgbotapi.types.message.content.MessageContent
2021-10-03 05:43:15 +00:00
import dev.inmo.tgbotapi.types.message.payments.*
2021-01-15 10:27:22 +00:00
import dev.inmo.tgbotapi.types.passport.PassportData
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.types.payments.Invoice
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
import dev.inmo.tgbotapi.types.polls.Poll
2023-02-05 14:46:12 +00:00
import dev.inmo.tgbotapi.types.request.ChatShared
2024-01-03 10:28:56 +00:00
import dev.inmo.tgbotapi.types.request.UsersShared
2023-08-18 18:31:36 +00:00
import dev.inmo.tgbotapi.types.stories.Story
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.types.venue.Venue
import kotlinx.serialization.SerialName
2020-03-31 05:41:58 +00:00
import kotlinx.serialization.Serializable
2018-12-26 08:07:24 +00:00
import kotlin.reflect.KClass
// TODO:: add PassportData type
@Serializable
internal data class RawMessage(
@SerialName(messageIdField)
val messageId: MessageId,
2018-12-26 08:07:24 +00:00
val date: TelegramDate,
2023-10-11 07:07:07 +00:00
private val chat: PreviewChat,
2022-11-06 06:51:53 +00:00
@SerialName(messageThreadIdField)
private val messageThreadId: MessageThreadId? = null,
2018-12-26 08:07:24 +00:00
private val from: User? = null,
2023-10-11 07:07:07 +00:00
private val sender_chat: PreviewPublicChat? = null,
2024-01-07 11:12:37 +00:00
private val forward_origin: MessageOrigin? = null,
private val is_topic_message: Boolean? = null,
2021-12-18 16:28:01 +00:00
private val is_automatic_forward: Boolean? = null,
2019-04-13 02:16:40 +00:00
private val reply_to_message: RawMessage? = null,
private val reply_to_story: Story? = null,
private val external_reply: ReplyInfo.External? = null,
2024-01-07 14:51:29 +00:00
private val quote: TextQuote? = null,
2020-06-05 07:38:05 +00:00
private val via_bot: CommonBot? = null,
2019-04-13 02:16:40 +00:00
private val edit_date: TelegramDate? = null,
2021-12-18 17:11:28 +00:00
private val has_protected_content: Boolean? = null,
2024-03-16 15:21:34 +00:00
private val media_group_id: MediaGroupId? = null,
2019-04-13 02:16:40 +00:00
private val author_signature: AuthorSignature? = null,
private val text: String? = null,
private val entities: RawMessageEntities? = null,
private val caption: String? = null,
private val caption_entities: RawMessageEntities? = null,
private val has_media_spoiler: Boolean? = null,
2023-08-18 18:31:36 +00:00
private val story: Story? = null,
2019-04-13 02:16:40 +00:00
private val audio: AudioFile? = null,
private val document: DocumentFile? = null,
private val animation: AnimationFile? = null,
2019-08-18 06:31:33 +00:00
private val game: RawGame? = null,
2018-12-26 08:07:24 +00:00
@Serializable(PhotoSerializer::class)
2019-04-13 02:16:40 +00:00
private val photo: Photo? = null,
private val sticker: Sticker? = null,
private val video: VideoFile? = null,
private val voice: VoiceFile? = null,
private val video_note: VideoNoteFile? = null,
private val contact: Contact? = null,
private val location: Location? = null,
private val venue: Venue? = null,
2019-04-16 08:04:02 +00:00
private val poll: Poll? = null,
2019-04-13 02:20:29 +00:00
private val new_chat_members: List<User>? = null,
2019-04-13 02:16:40 +00:00
private val left_chat_member: User? = null,
private val new_chat_title: String? = null,
2018-12-26 08:07:24 +00:00
@Serializable(PhotoSerializer::class)
2019-04-13 02:16:40 +00:00
private val new_chat_photo: Photo? = null,
private val delete_chat_photo: Boolean = false,
private val group_chat_created: Boolean = false,
private val supergroup_chat_created: Boolean = false,
private val channel_chat_created: Boolean = false,
2022-11-10 09:56:38 +00:00
private val migrate_to_chat_id: IdChatIdentifier? = null,
private val migrate_from_chat_id: IdChatIdentifier? = null,
2019-04-13 02:16:40 +00:00
private val pinned_message: RawMessage? = null,
private val invoice: Invoice? = null,
2020-03-30 15:30:22 +00:00
private val dice: Dice? = null,
2019-04-13 02:16:40 +00:00
private val successful_payment: SuccessfulPayment? = null,
2024-01-09 05:43:04 +00:00
private val giveaway: Giveaway? = null,
2024-01-07 13:04:23 +00:00
private val giveaway_winners: GiveawayResults? = null,
2024-02-16 15:38:28 +00:00
private val sender_boost_count: Int? = null,
2018-12-26 08:07:24 +00:00
2024-01-03 10:28:56 +00:00
private val users_shared: UsersShared? = null,
2023-02-05 14:46:12 +00:00
private val chat_shared: ChatShared? = null,
2021-03-09 13:19:15 +00:00
// Voice Chat Service Messages
private val video_chat_scheduled: VideoChatScheduled? = null,
private val video_chat_started: VideoChatStarted? = null,
private val video_chat_ended: VideoChatEnded? = null,
private val video_chat_participants_invited: VideoChatParticipantsInvited? = null,
2021-03-09 13:19:15 +00:00
// Forum
private val forum_topic_created: ForumTopicCreated? = null,
private val forum_topic_edited: ForumTopicEdited? = null,
private val forum_topic_closed: ForumTopicClosed? = null,
private val forum_topic_reopened: ForumTopicReopened? = null,
private val general_forum_topic_hidden: GeneralForumTopicHidden? = null,
private val general_forum_topic_unhidden: GeneralForumTopicUnhidden? = null,
private val write_access_allowed: WriteAccessAllowed? = null,
2024-02-16 15:13:37 +00:00
// Boost added to groups
private val boost_added: ChatBoostAdded? = null,
// AutoDelete Message time changed
private val message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged? = null,
2018-12-26 08:07:24 +00:00
// login property
2019-04-13 02:16:40 +00:00
private val connected_website: String? = null,
2018-12-26 08:07:24 +00:00
2022-04-17 12:36:40 +00:00
// login property
private val web_app_data: WebAppData? = null,
2018-12-26 08:07:24 +00:00
// passport property
2021-01-15 10:27:22 +00:00
private val passport_data: PassportData? = null,
2020-11-04 19:12:14 +00:00
private val proximity_alert_triggered: ProximityAlertTriggered? = null,
2019-06-01 09:28:37 +00:00
private val link_preview_options: LinkPreviewOptions? = null,
2024-01-04 07:10:05 +00:00
private val reply_markup: InlineKeyboardMarkup? = null,
// Business
private val business_connection_id: BusinessConnectionId? = null,
2024-04-16 12:37:04 +00:00
private val sender_business_bot: PreviewBot? = null,
2024-01-04 07:10:05 +00:00
// Giveaways
private val giveaway_created: GiveawayCreated? = null,
private val giveaway_completed: GiveawayPrivateResults? = null,
2018-12-26 08:07:24 +00:00
) {
private val content: MessageContent? by lazy {
2019-04-13 02:20:29 +00:00
val adaptedCaptionEntities = caption ?.let {
2021-04-28 13:54:57 +00:00
(caption_entities ?: emptyList()).asTextSources(caption)
2018-12-26 08:07:24 +00:00
} ?: emptyList()
when {
2023-08-18 18:31:36 +00:00
story != null -> StoryContent(
2023-08-19 12:15:54 +00:00
chat,
2023-08-18 18:31:36 +00:00
messageId,
story
)
2024-01-07 14:51:29 +00:00
text != null -> TextContent(text, (entities ?: emptyList()).asTextSources(text), link_preview_options, quote)
2018-12-26 08:07:24 +00:00
audio != null -> AudioContent(
audio,
caption,
2024-01-07 14:51:29 +00:00
adaptedCaptionEntities,
quote
2018-12-26 08:07:24 +00:00
)
video != null -> VideoContent(
video,
caption,
adaptedCaptionEntities,
2024-01-07 14:51:29 +00:00
has_media_spoiler ?: false,
quote
2018-12-26 08:07:24 +00:00
)
animation != null -> AnimationContent(
animation,
document,
caption,
adaptedCaptionEntities,
2024-01-07 14:51:29 +00:00
has_media_spoiler ?: false,
quote
)
2018-12-26 08:07:24 +00:00
document != null -> DocumentContent(
document,
caption,
2024-01-07 14:51:29 +00:00
adaptedCaptionEntities,
quote
2018-12-26 08:07:24 +00:00
)
voice != null -> VoiceContent(
voice,
caption,
2024-01-07 14:51:29 +00:00
adaptedCaptionEntities,
quote
2018-12-26 08:07:24 +00:00
)
photo != null -> PhotoContent(
2024-01-07 13:04:23 +00:00
photo,
2018-12-26 08:07:24 +00:00
caption,
adaptedCaptionEntities,
2024-01-07 14:51:29 +00:00
has_media_spoiler ?: false,
quote
2018-12-26 08:07:24 +00:00
)
sticker != null -> StickerContent(sticker)
2020-03-30 15:30:22 +00:00
dice != null -> DiceContent(dice)
2019-08-18 06:31:33 +00:00
game != null -> GameContent(game.asGame)
2018-12-26 08:07:24 +00:00
video_note != null -> VideoNoteContent(video_note)
contact != null -> ContactContent(contact)
location != null -> LocationContent(location)
venue != null -> VenueContent(venue)
2019-04-16 08:04:02 +00:00
poll != null -> PollContent(poll)
invoice != null -> InvoiceContent(invoice)
2024-01-09 05:43:04 +00:00
giveaway != null -> GiveawayContent(chat, messageId, giveaway)
2024-01-07 11:40:41 +00:00
giveaway_winners is GiveawayPublicResults -> GiveawayPublicResultsContent(giveaway_winners)
2018-12-26 08:07:24 +00:00
else -> null
}
}
private val chatEvent: ChatEvent? by lazy {
when {
new_chat_members != null -> NewChatMembers(new_chat_members.toList())
2023-03-10 08:59:59 +00:00
left_chat_member != null -> LeftChatMemberEvent(left_chat_member)
2018-12-26 08:07:24 +00:00
new_chat_title != null -> NewChatTitle(new_chat_title)
2024-01-07 13:04:23 +00:00
new_chat_photo != null -> NewChatPhoto(new_chat_photo)
video_chat_started != null -> video_chat_started
video_chat_scheduled != null -> video_chat_scheduled
message_auto_delete_timer_changed != null -> message_auto_delete_timer_changed
forum_topic_created != null -> forum_topic_created
forum_topic_edited != null -> forum_topic_edited
general_forum_topic_hidden != null -> general_forum_topic_hidden
general_forum_topic_unhidden != null -> general_forum_topic_unhidden
write_access_allowed != null -> write_access_allowed
forum_topic_closed != null -> forum_topic_closed
forum_topic_reopened != null -> forum_topic_reopened
video_chat_ended != null -> video_chat_ended
video_chat_participants_invited != null -> video_chat_participants_invited
2018-12-26 08:07:24 +00:00
delete_chat_photo -> DeleteChatPhoto()
group_chat_created -> GroupChatCreated(
migrate_to_chat_id
)
2023-03-10 08:59:59 +00:00
2018-12-26 08:07:24 +00:00
supergroup_chat_created -> SupergroupChatCreated(
migrate_from_chat_id
)
2023-03-10 08:59:59 +00:00
migrate_from_chat_id != null -> MigratedToSupergroup(
migrate_from_chat_id
)
2023-03-10 08:59:59 +00:00
2018-12-26 08:07:24 +00:00
channel_chat_created -> ChannelChatCreated()
pinned_message != null -> PinnedMessage(pinned_message.asMessage)
2020-11-04 19:12:14 +00:00
proximity_alert_triggered != null -> proximity_alert_triggered
2021-10-03 05:43:15 +00:00
successful_payment != null -> SuccessfulPaymentEvent(successful_payment)
connected_website != null -> UserLoggedIn(connected_website)
2022-04-17 12:36:40 +00:00
web_app_data != null -> web_app_data
2024-01-03 10:28:56 +00:00
users_shared != null -> users_shared
2023-02-05 14:46:12 +00:00
chat_shared != null -> chat_shared
2024-01-04 07:10:05 +00:00
giveaway_created != null -> giveaway_created
2024-01-07 11:40:41 +00:00
giveaway_winners is GiveawayPrivateResults -> giveaway_winners
2024-01-04 07:10:05 +00:00
giveaway_completed != null -> giveaway_completed
2024-02-16 15:13:37 +00:00
boost_added != null -> boost_added
2018-12-26 08:07:24 +00:00
else -> null
}
}
2024-01-11 19:11:57 +00:00
val asMessage: Message by lazy {
2024-01-07 09:21:32 +00:00
if (date.date == 0L) {
return@lazy InaccessibleMessage(
chat,
messageId
)
}
try {
chatEvent?.let { chatEvent ->
when (chat) {
2023-10-11 07:07:07 +00:00
is PreviewSupergroupChat -> CommonSupergroupEventMessage(
2019-01-10 14:09:51 +00:00
messageId,
from ?: error("Supergroup events are expected to contain 'from' field"),
2019-01-10 14:09:51 +00:00
chat,
chatEvent as? SupergroupEvent ?: throwWrongChatEvent(SupergroupEvent::class, chatEvent),
date.asDate
)
2023-10-11 07:07:07 +00:00
is PreviewGroupChat -> CommonGroupEventMessage(
messageId,
from ?: error("Supergroup events are expected to contain 'from' field"),
chat,
chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent),
date.asDate
)
2023-10-11 07:07:07 +00:00
is PreviewChannelChat -> ChannelEventMessage(
messageId,
chat,
chatEvent as? ChannelEvent ?: throwWrongChatEvent(ChannelEvent::class, chatEvent),
date.asDate
)
2023-10-11 07:07:07 +00:00
is PreviewPrivateChat -> PrivateEventMessage(
2021-10-03 05:43:15 +00:00
messageId,
chat,
chatEvent as? PrivateEvent ?: throwWrongChatEvent(PrivateEvent::class, chatEvent),
date.asDate
)
else -> error("Expected one of the public chats, but was $chat (in extracting of chat event message)")
}
} ?: content?.let { content ->
val replyInfo: ReplyInfo? = when {
reply_to_message != null -> ReplyInfo.Internal(
reply_to_message.asMessage
)
reply_to_story != null -> ReplyInfo.ToStory(reply_to_story)
external_reply != null -> external_reply
else -> null
}
when (chat) {
2023-10-11 07:07:07 +00:00
is PreviewPublicChat -> when (chat) {
is PreviewChannelChat -> ChannelContentMessageImpl(
2021-12-20 08:07:45 +00:00
messageId,
chat,
content,
date.asDate,
edit_date?.asDate,
has_protected_content == true,
2024-01-07 11:12:37 +00:00
forward_origin,
replyInfo,
2021-12-20 08:07:45 +00:00
reply_markup,
via_bot,
2022-11-07 19:51:27 +00:00
author_signature,
media_group_id
2021-12-20 08:07:45 +00:00
)
2023-10-11 07:07:07 +00:00
is PreviewForumChat -> if (messageThreadId != null) {
2022-11-10 09:56:38 +00:00
val chatId = ChatIdWithThreadId(
chat.id.chatId,
messageThreadId
)
val actualForumChat = when (chat) {
is ForumChatImpl -> chat.copy(id = chatId)
}
2022-11-06 06:51:53 +00:00
when (sender_chat) {
2023-10-11 07:07:07 +00:00
is PreviewChannelChat -> FromChannelForumContentMessageImpl(
2022-11-10 09:56:38 +00:00
actualForumChat,
2022-11-06 06:51:53 +00:00
sender_chat,
messageId,
messageThreadId,
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
2022-11-06 06:51:53 +00:00
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
2022-11-06 06:51:53 +00:00
reply_markup,
content,
via_bot,
2022-11-07 19:51:27 +00:00
author_signature,
media_group_id
2022-11-06 06:51:53 +00:00
)
2023-10-11 07:07:07 +00:00
is PreviewGroupChat -> AnonymousForumContentMessageImpl(
2022-11-10 09:56:38 +00:00
actualForumChat,
2022-11-06 06:51:53 +00:00
messageId,
messageThreadId,
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
2022-11-06 06:51:53 +00:00
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
2022-11-06 06:51:53 +00:00
reply_markup,
content,
via_bot,
2022-11-07 19:51:27 +00:00
author_signature,
media_group_id
2022-11-06 06:51:53 +00:00
)
null -> CommonForumContentMessageImpl(
2022-11-10 09:56:38 +00:00
actualForumChat,
2022-11-06 06:51:53 +00:00
messageId,
messageThreadId,
from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"),
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
2022-11-06 06:51:53 +00:00
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
2022-11-06 06:51:53 +00:00
reply_markup,
content,
2022-11-07 19:51:27 +00:00
via_bot,
2024-02-16 15:38:28 +00:00
media_group_id,
sender_boost_count
2022-11-06 06:51:53 +00:00
)
}
} else {
when (sender_chat) {
2023-10-11 07:07:07 +00:00
is PreviewChannelChat -> if (is_automatic_forward == true) {
2022-11-06 06:51:53 +00:00
ConnectedFromChannelGroupContentMessageImpl(
chat,
sender_chat,
messageId,
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
2022-11-06 06:51:53 +00:00
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
2022-11-06 06:51:53 +00:00
reply_markup,
content,
via_bot,
2022-11-07 19:51:27 +00:00
author_signature,
media_group_id
2022-11-06 06:51:53 +00:00
)
} else {
UnconnectedFromChannelGroupContentMessageImpl(
chat,
sender_chat,
messageId,
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
2022-11-06 06:51:53 +00:00
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
2022-11-06 06:51:53 +00:00
reply_markup,
content,
via_bot,
2022-11-07 19:51:27 +00:00
author_signature,
media_group_id
2022-11-06 06:51:53 +00:00
)
}
is GroupChat -> AnonymousGroupContentMessageImpl(
chat,
messageId,
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
2022-11-06 06:51:53 +00:00
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
2022-11-06 06:51:53 +00:00
reply_markup,
content,
via_bot,
2022-11-07 19:51:27 +00:00
author_signature,
media_group_id
2022-11-06 06:51:53 +00:00
)
null -> CommonGroupContentMessageImpl(
chat,
messageId,
from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"),
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
2022-11-06 06:51:53 +00:00
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
2022-11-06 06:51:53 +00:00
reply_markup,
content,
2022-11-07 19:51:27 +00:00
via_bot,
2024-02-16 15:38:28 +00:00
media_group_id,
sender_boost_count
2022-11-06 06:51:53 +00:00
)
}
}
2023-10-11 07:07:07 +00:00
is PreviewGroupChat -> when (sender_chat) {
is PreviewChannelChat -> if (is_automatic_forward == true) {
2021-12-20 08:07:45 +00:00
ConnectedFromChannelGroupContentMessageImpl(
chat,
sender_chat,
messageId,
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
2021-12-20 08:07:45 +00:00
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
2021-12-20 08:07:45 +00:00
reply_markup,
content,
via_bot,
2022-11-07 19:51:27 +00:00
author_signature,
media_group_id
2021-12-20 08:07:45 +00:00
)
} else {
UnconnectedFromChannelGroupContentMessageImpl(
chat,
sender_chat,
messageId,
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
2021-12-20 08:07:45 +00:00
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
2021-12-20 08:07:45 +00:00
reply_markup,
content,
via_bot,
2022-11-07 19:51:27 +00:00
author_signature,
media_group_id
2021-12-20 08:07:45 +00:00
)
}
2023-10-11 07:07:07 +00:00
is PreviewGroupChat -> AnonymousGroupContentMessageImpl(
chat,
messageId,
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
reply_markup,
content,
via_bot,
2022-11-07 19:51:27 +00:00
author_signature,
media_group_id
)
2021-02-07 10:54:48 +00:00
null -> CommonGroupContentMessageImpl(
chat,
messageId,
2020-11-12 15:46:33 +00:00
from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"),
date.asDate,
2024-01-07 11:12:37 +00:00
forward_origin,
edit_date ?.asDate,
has_protected_content == true,
replyInfo,
reply_markup,
content,
2022-11-07 19:51:27 +00:00
via_bot,
2024-02-16 15:38:28 +00:00
media_group_id,
sender_boost_count
)
}
}
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,
2024-04-16 12:37:04 +00:00
media_group_id,
sender_business_bot
)
}
else -> error("Unknown type of chat: $chat")
2019-01-10 14:09:51 +00:00
}
2021-01-15 10:27:22 +00:00
} ?: passport_data ?.let{
PassportMessage(
messageId,
chat,
2021-01-17 09:35:25 +00:00
from ?: error("For passport must be provided user, but got null"),
2021-01-15 10:27:22 +00:00
date.asDate,
passport_data
)
} ?: error("Was not found supported type of data")
} catch (e: Exception) {
UnknownMessageType(
messageId,
chat,
date.asDate,
e
)
}
2018-12-26 08:07:24 +00:00
}
2021-10-03 05:43:15 +00:00
private fun throwWrongChatEvent(expected: KClass<*>, but: ChatEvent): Nothing {
error("Wrong type of chat event: expected $expected, but was $but")
2018-12-26 08:07:24 +00:00
}
}