mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
implementation of sender_chat and author_signature
This commit is contained in:
parent
ec806dfd83
commit
ff34b23777
15
CHANGELOG.md
15
CHANGELOG.md
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## 0.30.0 Bot API 5.0
|
## 0.30.0 Bot API 5.0
|
||||||
|
|
||||||
|
**THIS UPDATE CONTAINS A LOT OF BREAKING CHANGES. PLEASE, BE CAREFUL ON UPGRADING OF YOUR PROJECT**
|
||||||
|
|
||||||
* `Core`:
|
* `Core`:
|
||||||
* Support of `logOut` method (`LogOut` object as a `Request`)
|
* Support of `logOut` method (`LogOut` object as a `Request`)
|
||||||
* Support of `close` method (`Close` object as a `Request`)
|
* Support of `close` method (`Close` object as a `Request`)
|
||||||
@ -43,6 +45,19 @@
|
|||||||
* Property `pollQuestionTextLength` now have maximum up to `300`
|
* Property `pollQuestionTextLength` now have maximum up to `300`
|
||||||
* Anonymous Admins:
|
* Anonymous Admins:
|
||||||
* New field `AdministratorChatMember#isAnonymous`
|
* New field `AdministratorChatMember#isAnonymous`
|
||||||
|
* Several new interfaces of messages:
|
||||||
|
* `SignedMessage` - any message which possibly have `authorSignature`
|
||||||
|
* `WithSenderChatMessage` - any message which have `senderChat`. Property `senderChat` is not-nullable due to
|
||||||
|
separation of implementators
|
||||||
|
* `PublicMessage` - all channel messages have property `val chat: PublicChat` instead of common `val chat: Chat`
|
||||||
|
* `ChannelMessage` - all channel messages have property `val chat: ChannelChat` instead of common `val chat: Chat`
|
||||||
|
* Old `ChannelMessage` was safely renamed to `ChannelMessageImpl` (old name was set as typealias and deprecated)
|
||||||
|
* `GroupMessage` - all group messages have property `val chat: GroupChat` instead of common `val chat: Chat`
|
||||||
|
* `FromChannelGroupMessage` - instances should have property `val channel: ChannelChat`
|
||||||
|
* `AnonymousGroupMessage` - instances may have setup property `authorSignature`
|
||||||
|
* `CommonGroupMessage` - just common message
|
||||||
|
* `PrivateMessage` - works like previous `CommonMessageImpl`
|
||||||
|
* Previous `CommonMessageImpl` safely renamed to `PrivateMessageImpl`
|
||||||
* `API`:
|
* `API`:
|
||||||
* Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat`
|
* Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat`
|
||||||
* New extensions `TelegramBot#unpinAllChatMessages`
|
* New extensions `TelegramBot#unpinAllChatMessages`
|
||||||
|
@ -7,10 +7,12 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message
|
|||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||||
import com.soywiz.klock.DateTime
|
import com.soywiz.klock.DateTime
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.ChannelMessage
|
||||||
|
|
||||||
data class ChannelMessage<T: MessageContent>(
|
data class ChannelMessageImpl<T: MessageContent>(
|
||||||
override val messageId: MessageIdentifier,
|
override val messageId: MessageIdentifier,
|
||||||
override val chat: Chat,
|
override val chat: ChannelChat,
|
||||||
override val content: T,
|
override val content: T,
|
||||||
override val date: DateTime,
|
override val date: DateTime,
|
||||||
override val editDate: DateTime?,
|
override val editDate: DateTime?,
|
||||||
@ -18,5 +20,8 @@ data class ChannelMessage<T: MessageContent>(
|
|||||||
override val replyTo: Message?,
|
override val replyTo: Message?,
|
||||||
override val replyMarkup: InlineKeyboardMarkup?,
|
override val replyMarkup: InlineKeyboardMarkup?,
|
||||||
override val senderBot: CommonBot?,
|
override val senderBot: CommonBot?,
|
||||||
val authorSignature: AuthorSignature?
|
override val authorSignature: AuthorSignature?
|
||||||
) : PossiblySentViaBotCommonMessage<T>
|
) : ChannelMessage<T>
|
||||||
|
|
||||||
|
@Deprecated("Renamed", ReplaceWith("ChannelMessageImpl", "dev.inmo.tgbotapi.types.message.ChannelMessageImpl"))
|
||||||
|
typealias ChannelMessage<T> = ChannelMessageImpl<T>
|
@ -0,0 +1,49 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
|
||||||
|
import com.soywiz.klock.DateTime
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
|
|
||||||
|
data class FromChannelGroupMessageImpl<T : MessageContent>(
|
||||||
|
override val chat: GroupChat,
|
||||||
|
override val channel: ChannelChat,
|
||||||
|
override val messageId: MessageIdentifier,
|
||||||
|
override val date: DateTime,
|
||||||
|
override val forwardInfo: ForwardInfo?,
|
||||||
|
override val editDate: DateTime?,
|
||||||
|
override val replyTo: Message?,
|
||||||
|
override val replyMarkup: InlineKeyboardMarkup?,
|
||||||
|
override val content: T,
|
||||||
|
override val senderBot: CommonBot?,
|
||||||
|
override val authorSignature: AuthorSignature?
|
||||||
|
) : FromChannelGroupMessage<T>
|
||||||
|
|
||||||
|
data class AnonymousGroupMessageImpl<T : MessageContent>(
|
||||||
|
override val chat: GroupChat,
|
||||||
|
override val messageId: MessageIdentifier,
|
||||||
|
override val date: DateTime,
|
||||||
|
override val forwardInfo: ForwardInfo?,
|
||||||
|
override val editDate: DateTime?,
|
||||||
|
override val replyTo: Message?,
|
||||||
|
override val replyMarkup: InlineKeyboardMarkup?,
|
||||||
|
override val content: T,
|
||||||
|
override val senderBot: CommonBot?,
|
||||||
|
override val authorSignature: AuthorSignature?
|
||||||
|
) : AnonymousGroupMessage<T>
|
||||||
|
|
||||||
|
data class CommonGroupMessageImpl<T : MessageContent>(
|
||||||
|
override val chat: GroupChat,
|
||||||
|
override val messageId: MessageIdentifier,
|
||||||
|
override val date: DateTime,
|
||||||
|
override val forwardInfo: ForwardInfo?,
|
||||||
|
override val editDate: DateTime?,
|
||||||
|
override val replyTo: Message?,
|
||||||
|
override val replyMarkup: InlineKeyboardMarkup?,
|
||||||
|
override val content: T,
|
||||||
|
override val senderBot: CommonBot?
|
||||||
|
) : CommonGroupMessage<T>
|
@ -3,14 +3,13 @@ package dev.inmo.tgbotapi.types.message
|
|||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
|
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
|
||||||
import com.soywiz.klock.DateTime
|
import com.soywiz.klock.DateTime
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
|
|
||||||
data class CommonMessageImpl<T: MessageContent>(
|
data class PrivateMessageImpl<T: MessageContent>(
|
||||||
override val messageId: MessageIdentifier,
|
override val messageId: MessageIdentifier,
|
||||||
override val user: User,
|
override val user: User,
|
||||||
override val chat: Chat,
|
override val chat: Chat,
|
||||||
@ -22,4 +21,7 @@ data class CommonMessageImpl<T: MessageContent>(
|
|||||||
override val replyMarkup: InlineKeyboardMarkup?,
|
override val replyMarkup: InlineKeyboardMarkup?,
|
||||||
override val senderBot: CommonBot?,
|
override val senderBot: CommonBot?,
|
||||||
val paymentInfo: SuccessfulPaymentInfo?
|
val paymentInfo: SuccessfulPaymentInfo?
|
||||||
) : PossiblySentViaBotCommonMessage<T>, FromUserMessage
|
) : PrivateMessage<T>
|
||||||
|
|
||||||
|
@Deprecated("Renamed", ReplaceWith("PrivateMessageImpl", "dev.inmo.tgbotapi.types.message.PrivateMessageImpl"))
|
||||||
|
typealias CommonMessageImpl<T> = PrivateMessageImpl<T>
|
@ -10,7 +10,6 @@ import dev.inmo.tgbotapi.types.files.*
|
|||||||
import dev.inmo.tgbotapi.types.games.RawGame
|
import dev.inmo.tgbotapi.types.games.RawGame
|
||||||
import dev.inmo.tgbotapi.types.location.Location
|
import dev.inmo.tgbotapi.types.location.Location
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.ProximityAlertTriggered
|
import dev.inmo.tgbotapi.types.message.ChatEvents.ProximityAlertTriggered
|
||||||
import dev.inmo.tgbotapi.types.location.StaticLocation
|
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
@ -31,14 +30,11 @@ import kotlin.reflect.KClass
|
|||||||
// TODO:: add PassportData type
|
// TODO:: add PassportData type
|
||||||
@Serializable
|
@Serializable
|
||||||
internal data class RawMessage(
|
internal data class RawMessage(
|
||||||
@SerialName(messageIdField)
|
|
||||||
val messageId: MessageIdentifier,
|
val messageId: MessageIdentifier,
|
||||||
@SerialName(dateField)
|
|
||||||
val date: TelegramDate,
|
val date: TelegramDate,
|
||||||
@SerialName(chatField)
|
|
||||||
private val chat: Chat,
|
private val chat: Chat,
|
||||||
@SerialName(fromField)
|
|
||||||
private val from: User? = null,
|
private val from: User? = null,
|
||||||
|
private val sender_chat: PublicChat? = null,
|
||||||
private val forward_from: User? = null,
|
private val forward_from: User? = null,
|
||||||
private val forward_from_chat: Chat? = null,
|
private val forward_from_chat: Chat? = null,
|
||||||
private val forward_from_message_id: MessageIdentifier? = null,
|
private val forward_from_message_id: MessageIdentifier? = null,
|
||||||
@ -258,19 +254,61 @@ internal data class RawMessage(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} ?: when (chat) {
|
} ?: when (chat) {
|
||||||
is ChannelChat -> ChannelMessage(
|
is PublicChat -> when (chat) {
|
||||||
messageId,
|
is ChannelChat -> ChannelMessageImpl(
|
||||||
chat,
|
messageId,
|
||||||
content,
|
chat,
|
||||||
date.asDate,
|
content,
|
||||||
edit_date?.asDate,
|
date.asDate,
|
||||||
forwarded,
|
edit_date?.asDate,
|
||||||
reply_to_message?.asMessage,
|
forwarded,
|
||||||
reply_markup,
|
reply_to_message?.asMessage,
|
||||||
via_bot,
|
reply_markup,
|
||||||
author_signature
|
via_bot,
|
||||||
)
|
author_signature
|
||||||
else -> CommonMessageImpl(
|
)
|
||||||
|
is GroupChat -> when (sender_chat) {
|
||||||
|
is ChannelChat -> FromChannelGroupMessageImpl(
|
||||||
|
chat,
|
||||||
|
sender_chat,
|
||||||
|
messageId,
|
||||||
|
date.asDate,
|
||||||
|
forwarded,
|
||||||
|
edit_date ?.asDate,
|
||||||
|
reply_to_message ?.asMessage,
|
||||||
|
reply_markup,
|
||||||
|
content,
|
||||||
|
via_bot,
|
||||||
|
author_signature
|
||||||
|
)
|
||||||
|
is GroupChat -> AnonymousGroupMessageImpl(
|
||||||
|
chat,
|
||||||
|
messageId,
|
||||||
|
date.asDate,
|
||||||
|
forwarded,
|
||||||
|
edit_date ?.asDate,
|
||||||
|
reply_to_message ?.asMessage,
|
||||||
|
reply_markup,
|
||||||
|
content,
|
||||||
|
via_bot,
|
||||||
|
author_signature
|
||||||
|
)
|
||||||
|
null -> CommonGroupMessageImpl(
|
||||||
|
chat,
|
||||||
|
messageId,
|
||||||
|
date.asDate,
|
||||||
|
forwarded,
|
||||||
|
edit_date ?.asDate,
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
is PrivateChat -> PrivateMessageImpl(
|
||||||
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,
|
||||||
@ -283,6 +321,7 @@ internal data class RawMessage(
|
|||||||
via_bot,
|
via_bot,
|
||||||
paymentInfo
|
paymentInfo
|
||||||
)
|
)
|
||||||
|
else -> error("Unknown type of chat: $chat")
|
||||||
}
|
}
|
||||||
} ?: error("Was not found supported type of data")
|
} ?: error("Was not found supported type of data")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||||
|
|
||||||
|
interface ChannelMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, SignedMessage, WithSenderChatMessage {
|
||||||
|
override val chat: ChannelChat
|
||||||
|
override val senderChat: ChannelChat
|
||||||
|
get() = chat
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
|
|
||||||
|
interface GroupMessage<T : MessageContent> : PublicMessage<T> {
|
||||||
|
override val chat: GroupChat
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FromChannelGroupMessage<T : MessageContent> : GroupMessage<T>, SignedMessage, WithSenderChatMessage {
|
||||||
|
val channel: ChannelChat
|
||||||
|
override val senderChat: ChannelChat
|
||||||
|
get() = channel
|
||||||
|
}
|
||||||
|
interface AnonymousGroupMessage<T : MessageContent> : GroupMessage<T>, SignedMessage, WithSenderChatMessage {
|
||||||
|
override val senderChat: GroupChat
|
||||||
|
get() = chat
|
||||||
|
}
|
||||||
|
interface CommonGroupMessage<T : MessageContent> : GroupMessage<T>
|
@ -0,0 +1,6 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||||
|
|
||||||
|
interface PrivateMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, FromUserMessage
|
@ -0,0 +1,9 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||||
|
|
||||||
|
interface PublicMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T> {
|
||||||
|
override val chat: PublicChat
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.AuthorSignature
|
||||||
|
|
||||||
|
interface SignedMessage : Message {
|
||||||
|
val authorSignature: AuthorSignature?
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||||
|
|
||||||
|
interface WithSenderChatMessage {
|
||||||
|
val senderChat: Chat
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user