1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2026-08-17 22:56:28 +00:00

improvemens?

This commit is contained in:
2026-08-13 17:51:33 +06:00
parent d48e951232
commit 4f19cb7626
10 changed files with 408 additions and 391 deletions

View File

@@ -15313,17 +15313,21 @@ public final class dev/inmo/tgbotapi/types/ReplyInfo$ToStory$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}
public final class dev/inmo/tgbotapi/types/ReplyParameters : dev/inmo/tgbotapi/abstracts/TextedInput {
public abstract interface class dev/inmo/tgbotapi/types/ReplyParameters {
public static final field Companion Ldev/inmo/tgbotapi/types/ReplyParameters$Companion;
public synthetic fun <init> (JLjava/lang/Boolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (JLjava/lang/Boolean;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public abstract fun getAllowSendingWithoutReply ()Ljava/lang/Boolean;
public abstract fun getMessageId-CigXjpw ()Ldev/inmo/tgbotapi/types/MessageId;
}
public final class dev/inmo/tgbotapi/types/ReplyParameters$Chat : dev/inmo/tgbotapi/abstracts/TextedInput, dev/inmo/tgbotapi/types/ReplyParameters {
public static final field Companion Ldev/inmo/tgbotapi/types/ReplyParameters$Chat$Companion;
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;JLjava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;JLjava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;JLjava/lang/Boolean;Ljava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Ljava/util/List;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;JLjava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Ljava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;JLjava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Ljava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;JLjava/util/List;Ljava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;JLjava/util/List;Ljava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;Ldev/inmo/tgbotapi/types/MessageId;Ljava/lang/Boolean;Ljava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Ljava/util/List;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;Ldev/inmo/tgbotapi/types/EphemeralMessageId;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Ljava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Ljava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Ljava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Ljava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
@@ -15337,20 +15341,21 @@ public final class dev/inmo/tgbotapi/types/ReplyParameters : dev/inmo/tgbotapi/a
public synthetic fun <init> (Lkotlin/Triple;Ljava/util/List;Ljava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lkotlin/Triple;Ljava/util/List;Ljava/lang/Boolean;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ldev/inmo/tgbotapi/types/ChatIdentifier;
public final fun component10-lUwSvXo ()Ldev/inmo/tgbotapi/types/EphemeralMessageId;
public final fun component2-CigXjpw ()Ldev/inmo/tgbotapi/types/MessageId;
public final fun component2-APLFQys ()J
public final fun component3 ()Ljava/lang/Boolean;
public final fun component4 ()Ljava/lang/String;
public final fun component5 ()Ldev/inmo/tgbotapi/types/message/ParseMode;
public final fun component7 ()Ljava/lang/Integer;
public final fun component8-Wby8Lsc ()Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;
public final fun component9-y3a_nt8 ()Ljava/lang/String;
public final fun copy-LVJNs80 (Ldev/inmo/tgbotapi/types/ChatIdentifier;JLjava/lang/Boolean;Ljava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Ljava/util/List;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;)Ldev/inmo/tgbotapi/types/ReplyParameters$Chat;
public static synthetic fun copy-LVJNs80$default (Ldev/inmo/tgbotapi/types/ReplyParameters$Chat;Ldev/inmo/tgbotapi/types/ChatIdentifier;JLjava/lang/Boolean;Ljava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Ljava/util/List;Ljava/lang/Integer;Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;Ljava/lang/String;ILjava/lang/Object;)Ldev/inmo/tgbotapi/types/ReplyParameters$Chat;
public fun equals (Ljava/lang/Object;)Z
public final fun getAllowSendingWithoutReply ()Ljava/lang/Boolean;
public fun getAllowSendingWithoutReply ()Ljava/lang/Boolean;
public final fun getChatIdentifier ()Ldev/inmo/tgbotapi/types/ChatIdentifier;
public final fun getChecklistTaskId-Wby8Lsc ()Ldev/inmo/tgbotapi/types/checklists/ChecklistTaskId;
public final fun getEphemeralMessageId-lUwSvXo ()Ldev/inmo/tgbotapi/types/EphemeralMessageId;
public final fun getMessageId-CigXjpw ()Ldev/inmo/tgbotapi/types/MessageId;
public fun getMessageId-APLFQys ()J
public synthetic fun getMessageId-CigXjpw ()Ldev/inmo/tgbotapi/types/MessageId;
public final fun getPollOptionId-y3a_nt8 ()Ljava/lang/String;
public final fun getQuote ()Ljava/lang/String;
public final fun getQuoteParseMode ()Ldev/inmo/tgbotapi/types/message/ParseMode;
@@ -15361,21 +15366,43 @@ public final class dev/inmo/tgbotapi/types/ReplyParameters : dev/inmo/tgbotapi/a
public fun toString ()Ljava/lang/String;
}
public final synthetic class dev/inmo/tgbotapi/types/ReplyParameters$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Ldev/inmo/tgbotapi/types/ReplyParameters$$serializer;
public final fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/ReplyParameters;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/ReplyParameters;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
public final class dev/inmo/tgbotapi/types/ReplyParameters$Chat$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}
public final class dev/inmo/tgbotapi/types/ReplyParameters$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}
public final class dev/inmo/tgbotapi/types/ReplyParameters$Ephemeral : dev/inmo/tgbotapi/types/ReplyParameters {
public static final field Companion Ldev/inmo/tgbotapi/types/ReplyParameters$Ephemeral$Companion;
public synthetic fun <init> (JLjava/lang/Boolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (JLjava/lang/Boolean;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1-TazDcj0 ()J
public final fun component2 ()Ljava/lang/Boolean;
public final fun copy-DIpU5II (JLjava/lang/Boolean;)Ldev/inmo/tgbotapi/types/ReplyParameters$Ephemeral;
public static synthetic fun copy-DIpU5II$default (Ldev/inmo/tgbotapi/types/ReplyParameters$Ephemeral;JLjava/lang/Boolean;ILjava/lang/Object;)Ldev/inmo/tgbotapi/types/ReplyParameters$Ephemeral;
public fun equals (Ljava/lang/Object;)Z
public fun getAllowSendingWithoutReply ()Ljava/lang/Boolean;
public final fun getEphemeralMessageId-TazDcj0 ()J
public fun getMessageId-CigXjpw ()Ldev/inmo/tgbotapi/types/MessageId;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}
public final class dev/inmo/tgbotapi/types/ReplyParameters$Ephemeral$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}
public final class dev/inmo/tgbotapi/types/ReplyParameters$Serializer : kotlinx/serialization/KSerializer {
public static final field INSTANCE Ldev/inmo/tgbotapi/types/ReplyParameters$Serializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/ReplyParameters;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/ReplyParameters;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
}
public final class dev/inmo/tgbotapi/types/ReplyParametersKt {
public static final fun ephemeralReplyParametersOrNull (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Ljava/lang/Boolean;)Ldev/inmo/tgbotapi/types/ReplyParameters;
public static synthetic fun ephemeralReplyParametersOrNull$default (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Ljava/lang/Boolean;ILjava/lang/Object;)Ldev/inmo/tgbotapi/types/ReplyParameters;

View File

@@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.types
import dev.inmo.tgbotapi.abstracts.TextedInput
import dev.inmo.tgbotapi.types.checklists.ChecklistTaskId
import dev.inmo.tgbotapi.types.polls.PollOptionPersistentId
import dev.inmo.tgbotapi.types.message.ParseMode
import dev.inmo.tgbotapi.types.message.RawMessageEntity
import dev.inmo.tgbotapi.types.message.abstracts.Message
@@ -12,227 +11,148 @@ import dev.inmo.tgbotapi.types.message.asTextSources
import dev.inmo.tgbotapi.types.message.textsources.TextSource
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.message.toRawMessageEntities
import dev.inmo.tgbotapi.types.polls.PollOptionPersistentId
import dev.inmo.tgbotapi.utils.extensions.makeSourceString
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@ConsistentCopyVisibility
@Serializable
data class ReplyParameters internal constructor(
@SerialName(chatIdField)
val chatIdentifier: ChatIdentifier?,
@SerialName(messageIdField)
val messageId: MessageId?,
@SerialName(allowSendingWithoutReplyField)
val allowSendingWithoutReply: Boolean? = null,
@SerialName(quoteField)
val quote: String? = null,
@SerialName(quoteParseModeField)
val quoteParseMode: ParseMode? = null,
@SerialName(quoteEntitiesField)
private val quoteEntities: List<RawMessageEntity>? = null,
@SerialName(quotePositionField)
val quotePosition: Int? = null,
@SerialName(checklistTaskIdField)
val checklistTaskId: ChecklistTaskId? = null,
@SerialName(pollOptionIdField)
val pollOptionId: PollOptionPersistentId? = null,
@SerialName(ephemeralMessageIdField)
val ephemeralMessageId: EphemeralMessageId? = null,
) : TextedInput {
init {
require(messageId != null || ephemeralMessageId != null) {
"Either messageId or ephemeralMessageId must be specified for ReplyParameters"
}
}
override val text: String?
get() = quote
override val textSources: List<TextSource> by lazy {
quoteEntities ?.asTextSources(quote ?: return@lazy emptyList()) ?: emptyList()
}
@Serializable(ReplyParameters.Serializer::class)
sealed interface ReplyParameters {
val messageId: MessageId?
val allowSendingWithoutReply: Boolean?
/**
* Builds [ReplyParameters] targeting an ephemeral message by its [ephemeralMessageId]. The reply itself must
* also be sent as ephemeral (see `receiverUserId` of the corresponding send request); [chatIdentifier] and
* [quote]-related fields are not supported for such replies.
* Reply parameters targeting a regular message identified by [messageId]. A `null` [chatIdentifier] targets a
* message in the current chat; a non-null [chatIdentifier] targets a message in a different chat.
*/
constructor(
ephemeralMessageId: EphemeralMessageId,
allowSendingWithoutReply: Boolean? = null,
) : this(
chatIdentifier = null,
messageId = null,
allowSendingWithoutReply = allowSendingWithoutReply,
ephemeralMessageId = ephemeralMessageId
)
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
@ConsistentCopyVisibility
@Serializable(ReplyParameters.Serializer::class)
data class Chat internal constructor(
val chatIdentifier: ChatIdentifier?,
override val messageId: MessageId,
override val allowSendingWithoutReply: Boolean? = null,
val quote: String? = null,
val quoteParseMode: ParseMode? = null,
internal val quoteEntities: List<RawMessageEntity>? = null,
val quotePosition: Int? = null,
val checklistTaskId: ChecklistTaskId? = null,
val pollOptionId: PollOptionPersistentId? = null,
) : ReplyParameters, TextedInput {
override val text: String?
get() = quote
override val textSources: List<TextSource> by lazy {
quoteEntities ?.asTextSources(quote ?: return@lazy emptyList()) ?: emptyList()
}
constructor(
chatIdentifier: ChatIdentifier,
messageId: MessageId,
entities: TextSourcesList,
allowSendingWithoutReply: Boolean? = null,
quotePosition: Int? = null,
checklistTaskId: ChecklistTaskId? = null,
pollOptionId: PollOptionPersistentId? = null,
) : this(
chatIdentifier,
messageId,
allowSendingWithoutReply,
entities.makeSourceString(),
null,
entities.toRawMessageEntities(),
quotePosition,
checklistTaskId,
pollOptionId
)
constructor(
metaInfo: Message.MetaInfo,
entities: TextSourcesList,
allowSendingWithoutReply: Boolean? = null,
quotePosition: Int? = null,
checklistTaskId: ChecklistTaskId? = null,
pollOptionId: PollOptionPersistentId? = null,
) : this(
metaInfo.chatId,
metaInfo.messageId,
entities,
allowSendingWithoutReply,
quotePosition,
checklistTaskId,
pollOptionId
)
constructor(
message: Message,
entities: TextSourcesList,
allowSendingWithoutReply: Boolean? = null,
quotePosition: Int? = null,
checklistTaskId: ChecklistTaskId? = null,
pollOptionId: PollOptionPersistentId? = null,
) : this(
message.metaInfo,
entities,
allowSendingWithoutReply,
quotePosition,
checklistTaskId,
pollOptionId
)
constructor(
chatIdentifier: ChatIdentifier,
messageId: MessageId,
quote: String,
quoteParseMode: ParseMode,
allowSendingWithoutReply: Boolean? = null,
quotePosition: Int? = null,
checklistTaskId: ChecklistTaskId? = null,
pollOptionId: PollOptionPersistentId? = null,
) : this(
chatIdentifier,
messageId,
allowSendingWithoutReply,
quote,
quoteParseMode,
null,
quotePosition,
checklistTaskId,
pollOptionId
)
constructor(
metaInfo: Message.MetaInfo,
quote: String,
quoteParseMode: ParseMode,
allowSendingWithoutReply: Boolean? = null,
quotePosition: Int? = null,
checklistTaskId: ChecklistTaskId? = null,
pollOptionId: PollOptionPersistentId? = null,
) : this(
metaInfo.chatId,
metaInfo.messageId,
quote,
quoteParseMode,
allowSendingWithoutReply,
quotePosition,
checklistTaskId,
pollOptionId
)
constructor(
message: Message,
quote: String,
quoteParseMode: ParseMode,
allowSendingWithoutReply: Boolean? = null,
quotePosition: Int? = null,
checklistTaskId: ChecklistTaskId? = null,
pollOptionId: PollOptionPersistentId? = null,
) : this(
message.metaInfo,
quote,
quoteParseMode,
allowSendingWithoutReply,
quotePosition,
checklistTaskId,
pollOptionId
)
constructor(
chatIdentifier: ChatIdentifier,
messageId: MessageId,
allowSendingWithoutReply: Boolean? = null,
quotePosition: Int? = null,
checklistTaskId: ChecklistTaskId? = null,
pollOptionId: PollOptionPersistentId? = null,
) : this(
chatIdentifier,
messageId,
allowSendingWithoutReply,
null,
null,
null,
quotePosition,
checklistTaskId,
pollOptionId
)
constructor(
metaInfo: Message.MetaInfo,
allowSendingWithoutReply: Boolean? = null,
quotePosition: Int? = null,
checklistTaskId: ChecklistTaskId? = null,
pollOptionId: PollOptionPersistentId? = null,
) : this(
metaInfo.chatId,
metaInfo.messageId,
allowSendingWithoutReply,
quotePosition,
checklistTaskId,
pollOptionId
)
constructor(
message: Message,
allowSendingWithoutReply: Boolean? = null,
quotePosition: Int? = null,
checklistTaskId: ChecklistTaskId? = null,
pollOptionId: PollOptionPersistentId? = null,
) : this(
message.metaInfo,
allowSendingWithoutReply,
quotePosition,
checklistTaskId,
pollOptionId
)
constructor(
chatIdentifier: ChatIdentifier,
messageId: MessageId,
entities: TextSourcesList,
allowSendingWithoutReply: Boolean? = null,
quotePosition: Int? = null,
checklistTaskId: ChecklistTaskId? = null,
pollOptionId: PollOptionPersistentId? = null,
) : this(chatIdentifier, messageId, allowSendingWithoutReply, entities.makeSourceString(), null, entities.toRawMessageEntities(), quotePosition, checklistTaskId, pollOptionId)
constructor(metaInfo: Message.MetaInfo, entities: TextSourcesList, allowSendingWithoutReply: Boolean? = null, quotePosition: Int? = null, checklistTaskId: ChecklistTaskId? = null, pollOptionId: PollOptionPersistentId? = null) :
this(metaInfo.chatId, metaInfo.messageId, entities, allowSendingWithoutReply, quotePosition, checklistTaskId, pollOptionId)
constructor(message: Message, entities: TextSourcesList, allowSendingWithoutReply: Boolean? = null, quotePosition: Int? = null, checklistTaskId: ChecklistTaskId? = null, pollOptionId: PollOptionPersistentId? = null) :
this(message.metaInfo, entities, allowSendingWithoutReply, quotePosition, checklistTaskId, pollOptionId)
constructor(chatIdentifier: ChatIdentifier, messageId: MessageId, quote: String, quoteParseMode: ParseMode, allowSendingWithoutReply: Boolean? = null, quotePosition: Int? = null, checklistTaskId: ChecklistTaskId? = null, pollOptionId: PollOptionPersistentId? = null) :
this(chatIdentifier, messageId, allowSendingWithoutReply, quote, quoteParseMode, null, quotePosition, checklistTaskId, pollOptionId)
constructor(metaInfo: Message.MetaInfo, quote: String, quoteParseMode: ParseMode, allowSendingWithoutReply: Boolean? = null, quotePosition: Int? = null, checklistTaskId: ChecklistTaskId? = null, pollOptionId: PollOptionPersistentId? = null) :
this(metaInfo.chatId, metaInfo.messageId, quote, quoteParseMode, allowSendingWithoutReply, quotePosition, checklistTaskId, pollOptionId)
constructor(message: Message, quote: String, quoteParseMode: ParseMode, allowSendingWithoutReply: Boolean? = null, quotePosition: Int? = null, checklistTaskId: ChecklistTaskId? = null, pollOptionId: PollOptionPersistentId? = null) :
this(message.metaInfo, quote, quoteParseMode, allowSendingWithoutReply, quotePosition, checklistTaskId, pollOptionId)
constructor(chatIdentifier: ChatIdentifier, messageId: MessageId, allowSendingWithoutReply: Boolean? = null, quotePosition: Int? = null, checklistTaskId: ChecklistTaskId? = null, pollOptionId: PollOptionPersistentId? = null) :
this(chatIdentifier, messageId, allowSendingWithoutReply, null, null, null, quotePosition, checklistTaskId, pollOptionId)
constructor(metaInfo: Message.MetaInfo, allowSendingWithoutReply: Boolean? = null, quotePosition: Int? = null, checklistTaskId: ChecklistTaskId? = null, pollOptionId: PollOptionPersistentId? = null) :
this(metaInfo.chatId, metaInfo.messageId, allowSendingWithoutReply, quotePosition, checklistTaskId, pollOptionId)
constructor(message: Message, allowSendingWithoutReply: Boolean? = null, quotePosition: Int? = null, checklistTaskId: ChecklistTaskId? = null, pollOptionId: PollOptionPersistentId? = null) :
this(message.metaInfo, allowSendingWithoutReply, quotePosition, checklistTaskId, pollOptionId)
}
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
@Serializable(ReplyParameters.Serializer::class)
/**
* Reply parameters targeting an incoming ephemeral message identified by [ephemeralMessageId]. The outgoing
* reply must also be ephemeral; chat and quote fields are unsupported for ephemeral replies.
*/
data class Ephemeral(
val ephemeralMessageId: EphemeralMessageId,
override val allowSendingWithoutReply: Boolean? = null,
) : ReplyParameters {
override val messageId: MessageId? = null
}
object Serializer : KSerializer<ReplyParameters> {
@Serializable
private data class Surrogate(
@SerialName(chatIdField) val chatIdentifier: ChatIdentifier? = null,
@SerialName(messageIdField) val messageId: MessageId? = null,
@SerialName(allowSendingWithoutReplyField) val allowSendingWithoutReply: Boolean? = null,
@SerialName(quoteField) val quote: String? = null,
@SerialName(quoteParseModeField) val quoteParseMode: ParseMode? = null,
@SerialName(quoteEntitiesField) val quoteEntities: List<RawMessageEntity>? = null,
@SerialName(quotePositionField) val quotePosition: Int? = null,
@SerialName(checklistTaskIdField) val checklistTaskId: ChecklistTaskId? = null,
@SerialName(pollOptionIdField) val pollOptionId: PollOptionPersistentId? = null,
@SerialName(ephemeralMessageIdField) val ephemeralMessageId: EphemeralMessageId? = null,
)
override val descriptor: SerialDescriptor = Surrogate.serializer().descriptor
override fun deserialize(decoder: Decoder): ReplyParameters {
val surrogate = decoder.decodeSerializableValue(Surrogate.serializer())
if (surrogate.messageId != null && surrogate.ephemeralMessageId != null) {
throw SerializationException("ReplyParameters must contain either message_id or ephemeral_message_id, not both")
}
return when {
surrogate.ephemeralMessageId != null -> Ephemeral(surrogate.ephemeralMessageId, surrogate.allowSendingWithoutReply)
surrogate.messageId != null -> Chat(
surrogate.chatIdentifier, surrogate.messageId, surrogate.allowSendingWithoutReply, surrogate.quote,
surrogate.quoteParseMode, surrogate.quoteEntities, surrogate.quotePosition, surrogate.checklistTaskId,
surrogate.pollOptionId
)
else -> throw SerializationException("ReplyParameters must contain message_id or ephemeral_message_id")
}
}
override fun serialize(encoder: Encoder, value: ReplyParameters) {
val surrogate = when (value) {
is Chat -> Surrogate(value.chatIdentifier, value.messageId, value.allowSendingWithoutReply, value.quote, value.quoteParseMode, value.quoteEntities, value.quotePosition, value.checklistTaskId, value.pollOptionId)
is Ephemeral -> Surrogate(allowSendingWithoutReply = value.allowSendingWithoutReply, ephemeralMessageId = value.ephemeralMessageId)
}
encoder.encodeSerializableValue(Surrogate.serializer(), surrogate)
}
}
}
/**
* Builds [ReplyParameters] targeting [this] ephemeral message (via its [PossiblyEphemeralMessage.ephemeralMessageId]),
* or `null` if [this] is not an ephemeral message. Used by `reply(to = ...)` helpers to automatically address a
* reply through `ephemeral_message_id` when the target message is itself ephemeral.
* Builds [ReplyParameters] targeting the receiver's ephemeral message through
* [PossiblyEphemeralMessage.ephemeralMessageId], or returns `null` for a non-ephemeral receiver.
*/
fun Message.ephemeralReplyParametersOrNull(allowSendingWithoutReply: Boolean? = null): ReplyParameters? =
(this as? PossiblyEphemeralMessage) ?.ephemeralMessageId ?.let {
ReplyParameters(it, allowSendingWithoutReply)
ReplyParameters.Ephemeral(it, allowSendingWithoutReply)
}
/**
* The [UserId] that should receive an ephemeral reply to [this] message (`null` if [this] is not ephemeral):
* the original ephemeral message's [PossiblyEphemeralMessage.receiverUser], falling back to the message sender
* ([OptionallyFromUserMessage.from]) when [PossiblyEphemeralMessage.receiverUser] is missing.
* Returns the receiver [UserId] for an ephemeral reply: [PossiblyEphemeralMessage.receiverUser] when available,
* otherwise [OptionallyFromUserMessage.from]; returns `null` for a non-ephemeral message.
*/
val Message.ephemeralReplyReceiverUserIdOrNull: UserId?
get() = (this as? PossiblyEphemeralMessage) ?.takeIf { it.ephemeralMessageId != null } ?.let {

View File

@@ -192,7 +192,7 @@ sealed interface ResendableContent {
effectId = effectId,
suggestedPostParameters = suggestedPostParameters,
replyParameters = replyToMessageId ?.let {
ReplyParameters(
ReplyParameters.Chat(
chatId,
replyToMessageId,
allowSendingWithoutReply = allowSendingWithoutReply

View File

@@ -0,0 +1,70 @@
package dev.inmo.tgbotapi.types
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class ReplyParametersSerializationTest {
private val json = Json { encodeDefaults = false }
@Test
fun chatRoundTripUsesFlatShape() {
val value: ReplyParameters = ReplyParameters.Chat(
ChatId(RawChatId(123L)),
MessageId(456L),
allowSendingWithoutReply = true
)
val encoded = json.encodeToString(value)
val encodedObject = json.parseToJsonElement(encoded).jsonObject
assertTrue("chat_id" in encodedObject)
assertTrue("message_id" in encodedObject)
assertFalse("ephemeral_message_id" in encodedObject)
assertEquals(value, json.decodeFromString<ReplyParameters>(encoded))
}
@Test
fun ephemeralRoundTripUsesFlatShape() {
val value: ReplyParameters = ReplyParameters.Ephemeral(EphemeralMessageId(789L), true)
val encoded = json.encodeToString(value)
val encodedObject = json.parseToJsonElement(encoded).jsonObject
assertTrue("ephemeral_message_id" in encodedObject)
assertFalse("chat_id" in encodedObject)
assertFalse("message_id" in encodedObject)
assertEquals(value, json.decodeFromString<ReplyParameters>(encoded))
}
@Test
fun currentChatPayloadWithoutChatIdDecodes() {
val decoded = json.decodeFromString<ReplyParameters>("""{"message_id":456}""")
assertEquals(
ReplyParameters.Chat(chatIdentifier = null, messageId = MessageId(456L)),
decoded
)
}
@Test
fun payloadWithBothTargetKindsIsRejected() {
assertFailsWith<SerializationException> {
json.decodeFromString<ReplyParameters>("""{"chat_id":123,"message_id":456,"ephemeral_message_id":789}""")
}
}
@Test
fun payloadWithoutTargetIsRejected() {
assertFailsWith<SerializationException> {
json.decodeFromString<ReplyParameters>("""{"allow_sending_without_reply":true}""")
}
}
}