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.MessageEntity.RawMessageEntities
|
2021-04-28 13:54:57 +00:00
|
|
|
import dev.inmo.tgbotapi.types.MessageEntity.asTextSources
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
|
|
|
import dev.inmo.tgbotapi.types.chat.abstracts.*
|
|
|
|
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
|
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.*
|
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.*
|
|
|
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
|
|
|
import dev.inmo.tgbotapi.types.message.content.media.*
|
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
|
|
|
|
import dev.inmo.tgbotapi.types.venue.Venue
|
2020-11-05 18:37:56 +00:00
|
|
|
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
|
2019-08-17 05:50:46 +00:00
|
|
|
internal data class RawMessage(
|
2020-11-05 18:37:56 +00:00
|
|
|
@SerialName(messageIdField)
|
2018-12-26 08:07:24 +00:00
|
|
|
val messageId: MessageIdentifier,
|
|
|
|
val date: TelegramDate,
|
2019-08-12 09:41:07 +00:00
|
|
|
private val chat: Chat,
|
2018-12-26 08:07:24 +00:00
|
|
|
private val from: User? = null,
|
2020-11-05 06:39:59 +00:00
|
|
|
private val sender_chat: PublicChat? = null,
|
2019-04-13 02:16:40 +00:00
|
|
|
private val forward_from: User? = null,
|
2019-08-12 09:41:07 +00:00
|
|
|
private val forward_from_chat: Chat? = null,
|
2019-04-13 02:16:40 +00:00
|
|
|
private val forward_from_message_id: MessageIdentifier? = null,
|
|
|
|
private val forward_signature: ForwardSignature? = null,
|
2019-04-16 09:26:02 +00:00
|
|
|
private val forward_sender_name: ForwardSenderName? = null,
|
2019-04-13 02:16:40 +00:00
|
|
|
private val forward_date: TelegramDate? = 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,
|
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,
|
2019-04-13 02:16:40 +00:00
|
|
|
private val media_group_id: MediaGroupIdentifier? = null,
|
|
|
|
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 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,
|
2021-12-20 22:10:41 +00:00
|
|
|
private val migrate_to_chat_id: ChatId? = null,
|
|
|
|
private val migrate_from_chat_id: ChatId? = 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,
|
2018-12-26 08:07:24 +00:00
|
|
|
|
2021-03-09 13:19:15 +00:00
|
|
|
// Voice Chat Service Messages
|
2022-04-17 14:03:00 +00:00
|
|
|
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
|
|
|
|
2021-03-09 13:45:19 +00:00
|
|
|
// 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 reply_markup: InlineKeyboardMarkup? = 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 {
|
2021-04-28 13:54:57 +00:00
|
|
|
text != null -> TextContent(text, (entities ?: emptyList()).asTextSources(text))
|
2018-12-26 08:07:24 +00:00
|
|
|
audio != null -> AudioContent(
|
|
|
|
audio,
|
|
|
|
caption,
|
|
|
|
adaptedCaptionEntities
|
|
|
|
)
|
|
|
|
video != null -> VideoContent(
|
|
|
|
video,
|
|
|
|
caption,
|
|
|
|
adaptedCaptionEntities
|
|
|
|
)
|
2019-06-28 11:05:40 +00:00
|
|
|
animation != null -> AnimationContent(
|
|
|
|
animation,
|
|
|
|
document,
|
|
|
|
caption,
|
|
|
|
adaptedCaptionEntities
|
|
|
|
)
|
2018-12-26 08:07:24 +00:00
|
|
|
document != null -> DocumentContent(
|
|
|
|
document,
|
|
|
|
caption,
|
|
|
|
adaptedCaptionEntities
|
|
|
|
)
|
|
|
|
voice != null -> VoiceContent(
|
|
|
|
voice,
|
|
|
|
caption,
|
|
|
|
adaptedCaptionEntities
|
|
|
|
)
|
|
|
|
photo != null -> PhotoContent(
|
|
|
|
photo.toList(),
|
|
|
|
caption,
|
|
|
|
adaptedCaptionEntities
|
|
|
|
)
|
|
|
|
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)
|
2020-02-07 04:47:35 +00:00
|
|
|
invoice != null -> InvoiceContent(invoice)
|
2018-12-26 08:07:24 +00:00
|
|
|
else -> null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 06:52:52 +00:00
|
|
|
private val forwarded: ForwardInfo? by lazy {
|
2019-04-16 09:26:02 +00:00
|
|
|
forward_date ?: return@lazy null // According to the documentation, now any forwarded message contains this field
|
2019-04-30 07:56:28 +00:00
|
|
|
when {
|
2020-01-15 06:52:52 +00:00
|
|
|
forward_sender_name != null -> AnonymousForwardInfo(
|
2019-04-30 04:53:56 +00:00
|
|
|
forward_date,
|
|
|
|
forward_sender_name
|
|
|
|
)
|
2020-02-25 07:45:32 +00:00
|
|
|
forward_from_chat is ChannelChat -> ForwardFromChannelInfo(
|
2019-04-30 07:56:28 +00:00
|
|
|
forward_date,
|
2020-06-05 08:25:19 +00:00
|
|
|
forward_from_message_id ?: error("Channel forwarded message must contain message id, but was not"),
|
2019-08-12 09:41:07 +00:00
|
|
|
forward_from_chat,
|
2019-04-30 07:56:28 +00:00
|
|
|
forward_signature
|
|
|
|
)
|
2020-10-02 08:59:10 +00:00
|
|
|
forward_from_chat is SupergroupChat -> ForwardFromSupergroupInfo(
|
|
|
|
forward_date,
|
|
|
|
forward_from_chat
|
|
|
|
)
|
2020-01-15 06:52:52 +00:00
|
|
|
forward_from != null -> UserForwardInfo(
|
2018-12-26 08:07:24 +00:00
|
|
|
forward_date,
|
2019-04-30 07:56:28 +00:00
|
|
|
forward_from
|
2018-12-26 08:07:24 +00:00
|
|
|
)
|
2019-04-30 07:56:28 +00:00
|
|
|
else -> null
|
2018-12-26 08:07:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private val chatEvent: ChatEvent? by lazy {
|
|
|
|
when {
|
|
|
|
new_chat_members != null -> NewChatMembers(new_chat_members.toList())
|
|
|
|
left_chat_member != null -> LeftChatMember(left_chat_member)
|
|
|
|
new_chat_title != null -> NewChatTitle(new_chat_title)
|
|
|
|
new_chat_photo != null -> NewChatPhoto(new_chat_photo.toList())
|
2022-04-17 14:03:00 +00:00
|
|
|
video_chat_started != null -> video_chat_started
|
|
|
|
video_chat_scheduled != null -> video_chat_scheduled
|
2021-03-09 13:45:19 +00:00
|
|
|
message_auto_delete_timer_changed != null -> message_auto_delete_timer_changed
|
2022-04-17 14:03:00 +00:00
|
|
|
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
|
|
|
|
)
|
|
|
|
supergroup_chat_created -> SupergroupChatCreated(
|
|
|
|
migrate_from_chat_id
|
|
|
|
)
|
2021-12-20 22:10:41 +00:00
|
|
|
migrate_from_chat_id != null -> MigratedToSupergroup(
|
|
|
|
migrate_from_chat_id
|
|
|
|
)
|
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)
|
2022-01-06 08:49:11 +00:00
|
|
|
connected_website != null -> UserLoggedIn(connected_website)
|
2022-04-17 12:36:40 +00:00
|
|
|
web_app_data != null -> web_app_data
|
2018-12-26 08:07:24 +00:00
|
|
|
else -> null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val asMessage: Message by lazy {
|
2020-01-22 21:47:43 +00:00
|
|
|
try {
|
|
|
|
chatEvent?.let { chatEvent ->
|
|
|
|
when (chat) {
|
2020-09-26 23:20:18 +00:00
|
|
|
is SupergroupChat -> CommonSupergroupEventMessage(
|
2019-01-10 14:09:51 +00:00
|
|
|
messageId,
|
2020-09-26 23:20:18 +00:00
|
|
|
from ?: error("Supergroup events are expected to contain 'from' field"),
|
2019-01-10 14:09:51 +00:00
|
|
|
chat,
|
2020-01-22 21:47:43 +00:00
|
|
|
chatEvent as? SupergroupEvent ?: throwWrongChatEvent(SupergroupEvent::class, chatEvent),
|
|
|
|
date.asDate
|
|
|
|
)
|
2020-09-26 23:20:18 +00:00
|
|
|
is GroupChat -> CommonGroupEventMessage(
|
2020-01-22 21:47:43 +00:00
|
|
|
messageId,
|
2020-09-26 23:20:18 +00:00
|
|
|
from ?: error("Supergroup events are expected to contain 'from' field"),
|
2020-01-22 21:47:43 +00:00
|
|
|
chat,
|
|
|
|
chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent),
|
|
|
|
date.asDate
|
|
|
|
)
|
|
|
|
is ChannelChat -> ChannelEventMessage(
|
|
|
|
messageId,
|
|
|
|
chat,
|
|
|
|
chatEvent as? ChannelEvent ?: throwWrongChatEvent(ChannelEvent::class, chatEvent),
|
|
|
|
date.asDate
|
|
|
|
)
|
2021-10-03 05:43:15 +00:00
|
|
|
is PrivateChat -> PrivateEventMessage(
|
|
|
|
messageId,
|
|
|
|
chat,
|
|
|
|
chatEvent as? PrivateEvent ?: throwWrongChatEvent(PrivateEvent::class, chatEvent),
|
|
|
|
date.asDate
|
|
|
|
)
|
2020-06-05 08:25:19 +00:00
|
|
|
else -> error("Expected one of the public chats, but was $chat (in extracting of chat event message)")
|
2020-01-22 21:47:43 +00:00
|
|
|
}
|
|
|
|
} ?: content?.let { content ->
|
|
|
|
media_group_id?.let {
|
2020-11-02 05:13:16 +00:00
|
|
|
val checkedContent = when (content) {
|
|
|
|
is PhotoContent -> content
|
|
|
|
is VideoContent -> content
|
|
|
|
is AudioContent -> content
|
|
|
|
is DocumentContent -> content
|
|
|
|
else -> error("Unsupported content for media group")
|
|
|
|
}
|
2020-01-22 21:47:43 +00:00
|
|
|
when (from) {
|
|
|
|
null -> ChannelMediaGroupMessage(
|
|
|
|
messageId,
|
|
|
|
chat,
|
|
|
|
date.asDate,
|
|
|
|
it,
|
2020-11-02 05:13:16 +00:00
|
|
|
checkedContent,
|
2020-01-22 21:47:43 +00:00
|
|
|
edit_date?.asDate,
|
2022-01-01 19:49:14 +00:00
|
|
|
has_protected_content == true,
|
2020-01-22 21:47:43 +00:00
|
|
|
forwarded,
|
|
|
|
reply_to_message?.asMessage,
|
|
|
|
reply_markup
|
|
|
|
)
|
|
|
|
else -> CommonMediaGroupMessage(
|
|
|
|
messageId,
|
|
|
|
from,
|
|
|
|
chat,
|
|
|
|
date.asDate,
|
|
|
|
it,
|
2020-11-02 05:13:16 +00:00
|
|
|
checkedContent,
|
2020-01-22 21:47:43 +00:00
|
|
|
edit_date?.asDate,
|
2022-01-01 19:49:14 +00:00
|
|
|
has_protected_content == true,
|
2020-01-22 21:47:43 +00:00
|
|
|
forwarded,
|
|
|
|
reply_to_message?.asMessage,
|
|
|
|
reply_markup
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} ?: when (chat) {
|
2020-11-05 06:39:59 +00:00
|
|
|
is PublicChat -> when (chat) {
|
2021-12-20 08:07:45 +00:00
|
|
|
is ChannelChat -> ChannelContentMessageImpl(
|
|
|
|
messageId,
|
|
|
|
chat,
|
|
|
|
content,
|
|
|
|
date.asDate,
|
|
|
|
edit_date?.asDate,
|
2022-01-01 19:49:14 +00:00
|
|
|
has_protected_content == true,
|
2021-12-20 08:07:45 +00:00
|
|
|
forwarded,
|
|
|
|
reply_to_message?.asMessage,
|
|
|
|
reply_markup,
|
|
|
|
via_bot,
|
|
|
|
author_signature
|
|
|
|
)
|
2020-11-05 06:39:59 +00:00
|
|
|
is GroupChat -> when (sender_chat) {
|
2021-12-20 08:07:45 +00:00
|
|
|
is ChannelChat -> if (is_automatic_forward == true) {
|
|
|
|
ConnectedFromChannelGroupContentMessageImpl(
|
|
|
|
chat,
|
|
|
|
sender_chat,
|
|
|
|
messageId,
|
|
|
|
date.asDate,
|
|
|
|
forwarded,
|
|
|
|
edit_date ?.asDate,
|
2022-01-01 19:49:14 +00:00
|
|
|
has_protected_content == true,
|
2021-12-20 08:07:45 +00:00
|
|
|
reply_to_message ?.asMessage,
|
|
|
|
reply_markup,
|
|
|
|
content,
|
|
|
|
via_bot,
|
|
|
|
author_signature
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
UnconnectedFromChannelGroupContentMessageImpl(
|
|
|
|
chat,
|
|
|
|
sender_chat,
|
|
|
|
messageId,
|
|
|
|
date.asDate,
|
|
|
|
forwarded,
|
|
|
|
edit_date ?.asDate,
|
2022-01-01 19:49:14 +00:00
|
|
|
has_protected_content == true,
|
2021-12-20 08:07:45 +00:00
|
|
|
reply_to_message ?.asMessage,
|
|
|
|
reply_markup,
|
|
|
|
content,
|
|
|
|
via_bot,
|
|
|
|
author_signature
|
|
|
|
)
|
|
|
|
}
|
2021-02-07 10:54:48 +00:00
|
|
|
is GroupChat -> AnonymousGroupContentMessageImpl(
|
2020-11-05 06:39:59 +00:00
|
|
|
chat,
|
|
|
|
messageId,
|
|
|
|
date.asDate,
|
|
|
|
forwarded,
|
|
|
|
edit_date ?.asDate,
|
2022-01-01 19:49:14 +00:00
|
|
|
has_protected_content == true,
|
2020-11-05 06:39:59 +00:00
|
|
|
reply_to_message ?.asMessage,
|
|
|
|
reply_markup,
|
|
|
|
content,
|
|
|
|
via_bot,
|
|
|
|
author_signature
|
|
|
|
)
|
2021-02-07 10:54:48 +00:00
|
|
|
null -> CommonGroupContentMessageImpl(
|
2020-11-05 06:39:59 +00:00
|
|
|
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"),
|
2020-11-05 06:39:59 +00:00
|
|
|
date.asDate,
|
|
|
|
forwarded,
|
|
|
|
edit_date ?.asDate,
|
2022-01-01 19:49:14 +00:00
|
|
|
has_protected_content == true,
|
2020-11-05 06:39:59 +00:00
|
|
|
reply_to_message ?.asMessage,
|
|
|
|
reply_markup,
|
|
|
|
content,
|
|
|
|
via_bot
|
|
|
|
)
|
|
|
|
else -> error("Currently in groups supported only fields \"sender_chat\" with channel, group or null, but was $sender_chat")
|
|
|
|
}
|
|
|
|
else -> error("Unknown type of public chat: $chat")
|
|
|
|
}
|
2021-02-07 10:54:48 +00:00
|
|
|
is PrivateChat -> PrivateContentMessageImpl(
|
2019-01-10 14:09:51 +00:00
|
|
|
messageId,
|
2020-06-05 08:25:19 +00:00
|
|
|
from ?: error("Was detected common message, but owner (sender) of the message was not found"),
|
2019-01-10 14:09:51 +00:00
|
|
|
chat,
|
2020-01-22 21:47:43 +00:00
|
|
|
content,
|
2019-01-10 14:09:51 +00:00
|
|
|
date.asDate,
|
2020-01-22 21:47:43 +00:00
|
|
|
edit_date?.asDate,
|
2022-01-01 19:49:14 +00:00
|
|
|
has_protected_content == true,
|
2019-02-17 06:29:17 +00:00
|
|
|
forwarded,
|
2020-01-22 21:47:43 +00:00
|
|
|
reply_to_message?.asMessage,
|
|
|
|
reply_markup,
|
2021-10-03 05:43:15 +00:00
|
|
|
via_bot
|
2019-01-10 14:09:51 +00:00
|
|
|
)
|
2020-11-05 06:39:59 +00:00
|
|
|
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
|
|
|
|
)
|
2020-06-05 08:25:19 +00:00
|
|
|
} ?: error("Was not found supported type of data")
|
2020-01-22 21:47:43 +00:00
|
|
|
} 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 {
|
2020-06-05 08:25:19 +00:00
|
|
|
error("Wrong type of chat event: expected $expected, but was $but")
|
2018-12-26 08:07:24 +00:00
|
|
|
}
|
|
|
|
}
|