1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-26 18:47:14 +00:00

Merge pull request #59 from InsanusMokrassar/0.22.0

0.22.0
This commit is contained in:
InsanusMokrassar 2020-01-15 13:35:08 +06:00 committed by GitHub
commit 50ae9ef955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
84 changed files with 514 additions and 302 deletions

View File

@ -1,5 +1,73 @@
# TelegramBotAPI changelog
## 0.22.0
* **`KtorCallFactory` must return `HttpStatement` instead of `HttpClientCall`**
* `SendMessage` was renamed to `SendTextMessage` and previous `SendMessage` is deprecated
* All `AbleToBe*` interfaces was renamed to `Possibly*`
* `AbleToBeEditedMessage` -> `PossiblyEditedMessage`
* `AbleToBeForwardedMessage` -> `PossiblyForwardedMessage`
* `AbleToBeMarkedUp` -> `PossiblyMarkedUp`
* `AbleToBeEditedMessage` -> `PossiblyEditedMessage`
* `ForwardedMessage` type was renamed to `ForwardInfo`
* `AnonymousForwardedMessage` -> `AnonymousForwardInfo`
* `UserForwardedMessage` -> `UserForwardInfo`
* `ForwardedFromChannelMessage` -> `ForwardFromChannelInfo`
* `PossiblyForwardedMessage#forwarded` field now renamed to `forwardInfo`
* All serializers in library now are `internal`. **If you have used some of them or I have marked as internal by a
mistake - don't hesitate to say this.**
* `EditChatMessage` now have generic type and extends `SimpleRequest<ContentMessage<GenericType>>`
* `ResendableContent` now extends `Request<out Message>` instead of `Request<Message>`
* Most part of requests have changed return type. They are listed below:
<details>
* `ForwardMessage`
* `GetChatAdministrators`
* `EditChatMessageLiveLocation`
* `StopChatMessageLiveLocation`
* `EditChatMessageText`
* `EditChatMessageCaption`
* `EditChatMessageMedia`
* `EditChatMessageReplyMarkup`
* `SendAnimation`
* `SendAudio`
* `SendContact`
* `SendLocation`
* `SendTextMessage`
* `SendPoll`
* `SendVenue`
* `SendGame`
* `SendDocument`
* `SendMediaGroup`
* `SendPhoto`
* `SendVideo`
* `SendVideoNote`
* `SendVoice`
* `SendSticker`
</details>
* Changed type of `createResend`
<details>
* `GameContent`
* `LocationContent`
* `PollContent`
* `TextContent`
* `VenueContent`
* `AnimationContent`
* `AudioContent`
* `DocumentContent`
* `ContactContent`
* `PhotoContent`
* `VideoContent`
* `VideoNoteContent`
* `VoiceContent`
* `StickerContent`
</details>
* Version updates:
* Ktor `1.2.6` -> `1.3.0`
## 0.21.0 TelegramBotAPI 4.5
* _**All `MessageEntity`'es now are replaced with `TextPart`**_

View File

@ -17,7 +17,7 @@ plugins {
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
}
project.version = "0.21.0"
project.version = "0.22.0"
project.group = "com.github.insanusmokrassar"
apply from: "publish.gradle"

View File

@ -4,7 +4,7 @@ kotlin_coroutines_version=1.3.3
kotlin_serialisation_runtime_version=0.14.0
klock_version=1.8.6
uuid_version=0.0.7
ktor_version=1.2.6
ktor_version=1.3.0
gradle_bintray_plugin_version=1.8.4

View File

@ -3,11 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import io.ktor.client.HttpClient
import io.ktor.client.call.HttpClientCall
import io.ktor.client.statement.HttpStatement
interface KtorCallFactory {
suspend fun <T: Any> prepareCall(
client: HttpClient,
baseUrl: String,
request: Request<T>
) : HttpClientCall?
) : HttpStatement?
}

View File

@ -11,10 +11,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
import io.ktor.client.HttpClient
import io.ktor.client.call.HttpClientCall
import io.ktor.client.call.receive
import io.ktor.client.features.ClientRequestException
import io.ktor.client.response.readText
import io.ktor.client.statement.HttpStatement
import io.ktor.client.statement.readText
import kotlinx.coroutines.delay
import kotlinx.serialization.json.Json
@ -36,22 +36,20 @@ class KtorRequestsExecutor(
override suspend fun <T : Any> execute(request: Request<T>): T {
return requestsLimiter.limit {
var call: HttpClientCall? = null
var statement: HttpStatement? = null
for (factory in callsFactories) {
call = factory.prepareCall(
statement = factory.prepareCall(
client,
telegramAPIUrlsKeeper.commonAPIUrl,
request
)
if (call != null) {
if (statement != null) {
break
}
}
if (call == null) {
throw IllegalArgumentException("Can't execute request: $request")
}
try {
val content = call.response.receive<String>()
val response = statement ?.execute() ?: throw IllegalArgumentException("Can't execute request: $request")
val content = response.receive<String>()
val responseObject = jsonFormatter.parse(Response.serializer(), content)
(responseObject.result?.let {
@ -64,7 +62,7 @@ class KtorRequestsExecutor(
} else {
null
}
} ?: call.let {
} ?: response.let {
throw newRequestException(
responseObject,
content,

View File

@ -4,9 +4,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorCallFactory
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import io.ktor.client.HttpClient
import io.ktor.client.call.HttpClientCall
import io.ktor.client.call.call
import io.ktor.client.request.accept
import io.ktor.client.request.url
import io.ktor.client.request.*
import io.ktor.client.statement.HttpStatement
import io.ktor.http.ContentType
import io.ktor.http.HttpMethod
import kotlin.collections.set
@ -17,20 +16,23 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
client: HttpClient,
baseUrl: String,
request: Request<T>
): HttpClientCall? {
): HttpStatement? {
val preparedBody = prepareCallBody(client, baseUrl, request) ?: return null
return client.call {
url(
methodsCache[request.method()] ?: "$baseUrl/${request.method()}".also {
methodsCache[request.method()] = it
}
)
method = HttpMethod.Post
accept(ContentType.Application.Json)
return HttpStatement(
HttpRequestBuilder().apply {
url(
methodsCache[request.method()] ?: "$baseUrl/${request.method()}".also {
methodsCache[request.method()] = it
}
)
method = HttpMethod.Post
accept(ContentType.Application.Json)
body = preparedBody
}
body = preparedBody
},
client
)
}
protected abstract fun <T : Any> prepareCallBody(

View File

@ -1,7 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.bot
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import kotlinx.io.core.Closeable
import io.ktor.utils.io.core.Closeable
interface RequestsExecutor : Closeable {
/**

View File

@ -1,8 +1,8 @@
package com.github.insanusmokrassar.TelegramBotAPI.bot
import io.ktor.utils.io.core.Closeable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.io.core.Closeable
interface UpdatesPoller : Closeable {
fun start(scope: CoroutineScope = CoroutineScope(Dispatchers.Default))

View File

@ -1,7 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import kotlinx.io.errors.IOException
import kotlinx.io.IOException
fun newRequestException(
response: Response,
@ -22,10 +22,9 @@ sealed class RequestException constructor(
val response: Response,
val plainAnswer: String,
message: String? = null,
cause: Throwable? = null
override val cause: Throwable? = null
) : IOException(
message ?: "Something went wrong",
cause
message ?: "Something went wrong"
)
class CommonRequestException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :

View File

@ -3,10 +3,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import kotlinx.serialization.*
private val AbleToBeForwardedMessageDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<PossiblyForwardedMessage>()
@Serializable
data class ForwardMessage(
@SerialName(fromChatIdField)
@ -17,15 +18,14 @@ data class ForwardMessage(
override val messageId: MessageIdentifier,
@SerialName(disableNotificationField)
val disableNotification: Boolean = false
): SimpleRequest<Message>, MessageAction {
@Transient
): SimpleRequest<PossiblyForwardedMessage>, MessageAction {
override val chatId: ChatIdentifier
get() = fromChatId
override fun method(): String = "forwardMessage"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<PossiblyForwardedMessage>
get() = AbleToBeForwardedMessageDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -21,7 +21,7 @@ data class FileId(
fun String.toInputFile(): InputFile = FileId(this)
@Serializer(InputFile::class)
object InputFileSerializer : KSerializer<InputFile> {
internal object InputFileSerializer : KSerializer<InputFile> {
override val descriptor: SerialDescriptor = StringDescriptor.withName(FileId::class.toString())
override fun serialize(encoder: Encoder, obj: InputFile) = encoder.encodeString(obj.fileId)
override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString())

View File

@ -51,6 +51,6 @@ fun InlineQuery.createAnswer(
switchPmParameter
)
object InlineQueryAnswersResultsSerializer: KSerializer<List<InlineQueryResult>> by ArrayListSerializer(
internal object InlineQueryAnswersResultsSerializer: KSerializer<List<InlineQueryResult>> by ArrayListSerializer(
InlineQueryResultSerializer
)

View File

@ -21,7 +21,7 @@ data class AnswerShippingQueryOk(
get() = serializer()
}
object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ArrayListSerializer(
internal object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ArrayListSerializer(
ShippingOption.serializer()
)

View File

@ -3,23 +3,22 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMemberSerializerWithoutDeserialization
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
import kotlinx.serialization.*
import kotlinx.serialization.internal.ArrayListSerializer
private val chatMembersListSerializer = ArrayListSerializer(
ChatMemberSerializerWithoutDeserialization
AdministratorChatMemberSerializerWithoutDeserialization
)
@Serializable
data class GetChatAdministrators(
@SerialName(chatIdField)
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<List<ChatMember>> {
): ChatRequest, SimpleRequest<List<AdministratorChatMember>> {
override fun method(): String = "getChatAdministrators"
override val resultDeserializer: DeserializationStrategy<List<ChatMember>>
override val resultDeserializer: DeserializationStrategy<List<AdministratorChatMember>>
get() = chatMembersListSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()

View File

@ -3,10 +3,15 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import kotlinx.serialization.*
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
@Serializable
data class EditChatMessageLiveLocation(
@SerialName(chatIdField)
@ -19,10 +24,10 @@ data class EditChatMessageLiveLocation(
override val longitude: Double,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage, EditReplyMessage, EditLocationMessage {
) : EditChatMessage<LocationContent>, EditReplyMessage, EditLocationMessage {
override fun method(): String = "editMessageLiveLocation"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -4,10 +4,14 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditCh
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
import kotlinx.serialization.*
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
@Serializable
data class StopChatMessageLiveLocation(
@SerialName(chatIdField)
@ -16,10 +20,10 @@ data class StopChatMessageLiveLocation(
override val messageId: MessageIdentifier,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage, EditReplyMessage {
) : EditChatMessage<LocationContent>, EditReplyMessage {
override fun method(): String = "stopMessageLiveLocation"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -4,12 +4,16 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditCh
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
import kotlinx.serialization.*
const val editMessageReplyMarkupMethod = "editMessageReplyMarkup"
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<MessageContent>>()
@Serializable
data class EditChatMessageReplyMarkup(
@SerialName(chatIdField)
@ -18,11 +22,11 @@ data class EditChatMessageReplyMarkup(
override val messageId: MessageIdentifier,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage, EditReplyMessage {
) : EditChatMessage<MessageContent>, EditReplyMessage {
override fun method(): String = editMessageReplyMarkupMethod
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<MessageContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
interface EditChatMessage : SimpleRequest<Message>, MessageAction
interface EditChatMessage<MT: MessageContent> : SimpleRequest<ContentMessage<MT>>, MessageAction

View File

@ -1,12 +1,15 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.MediaContentMessageResultDeserializer
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
import kotlinx.serialization.*
const val editMessageCaptionMethod = "editMessageCaption"
@ -23,11 +26,11 @@ data class EditChatMessageCaption(
override val parseMode: ParseMode? = null,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage, EditTextChatMessage, EditReplyMessage {
) : EditChatMessage<MediaContent>, EditTextChatMessage, EditReplyMessage {
override fun method(): String = editMessageCaptionMethod
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<MediaContent>>
get() = MediaContentMessageResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -5,12 +5,15 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
import kotlinx.serialization.*
const val editMessageMediaMethod = "editMessageMedia"
internal val MediaContentMessageResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<MediaContent>>()
@Serializable
data class EditChatMessageMedia(
@SerialName(chatIdField)
@ -21,7 +24,7 @@ data class EditChatMessageMedia(
override val media: InputMedia,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage, EditReplyMessage, EditMediaMessage {
) : EditChatMessage<MediaContent>, EditReplyMessage, EditMediaMessage {
init {
if (media.file is MultipartFile) {
@ -30,8 +33,8 @@ data class EditChatMessageMedia(
}
override fun method(): String = editMessageMediaMethod
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<MediaContent>>
get() = MediaContentMessageResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -1,12 +1,14 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.TextContentMessageResultDeserializer
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import kotlinx.serialization.*
const val editMessageTextMethod = "editMessageText"
@ -25,11 +27,11 @@ data class EditChatMessageText(
override val disableWebPagePreview: Boolean? = null,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
) : EditChatMessage<TextContent>, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
override fun method(): String = editMessageTextMethod
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<TextContent>>
get() = TextContentMessageResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -15,4 +15,4 @@ interface GetGameHighScores : SimpleRequest<List<GameHighScore>> {
get() = GameHighScoresSerializer
}
object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ArrayListSerializer(GameHighScore.serializer())
internal object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ArrayListSerializer(GameHighScore.serializer())

View File

@ -4,10 +4,14 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.Replyi
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.ContactContent
import kotlinx.serialization.*
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<ContactContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendContact(
@SerialName(chatIdField)
@ -24,8 +28,8 @@ data class SendContact(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>
) : SendMessageRequest<ContentMessage<ContactContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<ContactContent>>
{
constructor(
chatId: ChatIdentifier,
@ -44,8 +48,8 @@ data class SendContact(
)
override fun method(): String = "sendContact"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<ContactContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -3,10 +3,15 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
import kotlinx.serialization.*
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
// TODO:: Add location tracker for tracking location
@Serializable
data class SendLocation(
@ -24,14 +29,14 @@ data class SendLocation(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
PositionedSendMessageRequest<Message>
) : SendMessageRequest<ContentMessage<LocationContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<LocationContent>>,
PositionedSendMessageRequest<ContentMessage<LocationContent>>
{
override fun method(): String = "sendLocation"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -6,12 +6,15 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import kotlinx.serialization.*
internal val TextContentMessageResultDeserializer: DeserializationStrategy<ContentMessage<TextContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendMessage(
data class SendTextMessage(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(textField)
@ -26,9 +29,9 @@ data class SendMessage(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
) : SendMessageRequest<ContentMessage<TextContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<TextContent>>,
TextableSendMessageRequest<ContentMessage<TextContent>>,
DisableWebPagePreview
{
init {
@ -38,8 +41,16 @@ data class SendMessage(
}
override fun method(): String = "sendMessage"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<TextContent>>
get() = TextContentMessageResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
@Deprecated(
"This declaration is deprecated due violation of common naming rules",
ReplaceWith(
"SendTextMessage"
)
)
typealias SendMessage = SendTextMessage

View File

@ -4,10 +4,14 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.Replyi
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.PollContent
import kotlinx.serialization.*
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendPoll(
@SerialName(chatIdField)
@ -22,8 +26,8 @@ data class SendPoll(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message> {
) : SendMessageRequest<ContentMessage<PollContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<PollContent>> {
init {
if (question.length !in pollQuestionTextLength) {
@ -40,8 +44,8 @@ data class SendPoll(
}
override fun method(): String = "sendPoll"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -3,10 +3,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.VenueContent
import kotlinx.serialization.*
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<VenueContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendVenue(
@SerialName(chatIdField)
@ -27,10 +30,10 @@ data class SendVenue(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<Message>,
PositionedSendMessageRequest<Message>,
TitledSendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>
) : SendMessageRequest<ContentMessage<VenueContent>>,
PositionedSendMessageRequest<ContentMessage<VenueContent>>,
TitledSendMessageRequest<ContentMessage<VenueContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<VenueContent>>
{
constructor(
chatId: ChatIdentifier,
@ -51,8 +54,8 @@ data class SendVenue(
)
override fun method(): String = "sendVenue"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<VenueContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -4,10 +4,14 @@ import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMar
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.GameContent
import kotlinx.serialization.*
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<GameContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendGame (
@SerialName(chatIdField)
@ -20,11 +24,11 @@ data class SendGame (
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<Message>,
) : SendMessageRequest<ContentMessage<GameContent>>,
ReplyMarkup {
override fun method(): String = "sendGame"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<GameContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -7,8 +7,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.AnimationContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -24,7 +25,7 @@ fun SendAnimation(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<Message> {
): Request<ContentMessage<AnimationContent>> {
val animationAsFileId = (animation as? FileId) ?.fileId
val animationAsFile = animation as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -54,6 +55,9 @@ fun SendAnimation(
}
}
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<AnimationContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendAnimationData internal constructor(
@SerialName(chatIdField)
@ -78,13 +82,13 @@ data class SendAnimationData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>,
DuratedSendMessageRequest<Message>,
SizedSendMessageRequest<Message>
) : DataRequest<ContentMessage<AnimationContent>>,
SendMessageRequest<ContentMessage<AnimationContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<AnimationContent>>,
TextableSendMessageRequest<ContentMessage<AnimationContent>>,
ThumbedSendMessageRequest<ContentMessage<AnimationContent>>,
DuratedSendMessageRequest<ContentMessage<AnimationContent>>,
SizedSendMessageRequest<ContentMessage<AnimationContent>>
{
init {
text ?.let {
@ -95,8 +99,8 @@ data class SendAnimationData internal constructor(
}
override fun method(): String = "sendAnimation"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<AnimationContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -8,8 +8,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.AudioContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -25,7 +26,7 @@ fun SendAudio(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<Message> {
): Request<ContentMessage<AudioContent>> {
val audioAsFileId = (audio as? FileId) ?.fileId
val audioAsFile = audio as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -55,6 +56,9 @@ fun SendAudio(
}
}
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<AudioContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendAudioData internal constructor(
@SerialName(chatIdField)
@ -79,13 +83,13 @@ data class SendAudioData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>,
TitledSendMessageRequest<Message>,
DuratedSendMessageRequest<Message>,
) : DataRequest<ContentMessage<AudioContent>>,
SendMessageRequest<ContentMessage<AudioContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<AudioContent>>,
TextableSendMessageRequest<ContentMessage<AudioContent>>,
ThumbedSendMessageRequest<ContentMessage<AudioContent>>,
TitledSendMessageRequest<ContentMessage<AudioContent>>,
DuratedSendMessageRequest<ContentMessage<AudioContent>>,
Performerable
{
init {
@ -97,8 +101,8 @@ data class SendAudioData internal constructor(
}
override fun method(): String = "sendAudio"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<AudioContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -7,8 +7,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.DocumentContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -21,7 +22,7 @@ fun SendDocument(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<Message> {
): Request<ContentMessage<DocumentContent>> {
val documentAsFileId = (document as? FileId) ?.fileId
val documentAsFile = document as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -48,6 +49,9 @@ fun SendDocument(
}
}
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<DocumentContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendDocumentData internal constructor(
@SerialName(chatIdField)
@ -66,11 +70,11 @@ data class SendDocumentData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>
) : DataRequest<ContentMessage<DocumentContent>>,
SendMessageRequest<ContentMessage<DocumentContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<DocumentContent>>,
TextableSendMessageRequest<ContentMessage<DocumentContent>>,
ThumbedSendMessageRequest<ContentMessage<DocumentContent>>
{
init {
text ?.let {
@ -81,8 +85,8 @@ data class SendDocumentData internal constructor(
}
override fun method(): String = "sendDocument"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<DocumentContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -6,8 +6,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMe
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.*
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
import kotlinx.serialization.*
import kotlinx.serialization.internal.ArrayListSerializer
@ -20,7 +20,7 @@ fun SendMediaGroup(
media: List<MediaGroupMemberInputMedia>,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null
): Request<List<Message>> {
): Request<List<MediaGroupMessage>> {
if (media.size !in membersCountInMediaGroup) {
throw IllegalArgumentException("Count of members for media group must be in $membersCountInMediaGroup range")
}
@ -53,7 +53,8 @@ fun SendMediaGroup(
}
}
private val messagesListSerializer = ArrayListSerializer(TelegramBotAPIMessageDeserializeOnlySerializer)
private val messagesListSerializer: ArrayListSerializer<MediaGroupMessage>
= ArrayListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass())
@Serializable
data class SendMediaGroupData internal constructor(
@ -64,7 +65,7 @@ data class SendMediaGroupData internal constructor(
override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField)
override val replyToMessageId: MessageIdentifier? = null
) : DataRequest<List<Message>>, SendMessageRequest<List<Message>> {
) : DataRequest<List<MediaGroupMessage>>, SendMessageRequest<List<MediaGroupMessage>> {
@SerialName(mediaField)
private val convertedMedia: String
get() = jsonArray {
@ -77,7 +78,7 @@ data class SendMediaGroupData internal constructor(
override fun method(): String = "sendMediaGroup"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override val resultDeserializer: DeserializationStrategy<List<Message>>
override val resultDeserializer: DeserializationStrategy<List<MediaGroupMessage>>
get() = messagesListSerializer
}

View File

@ -7,8 +7,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.PhotoContent
import kotlinx.serialization.*
fun SendPhoto(
@ -19,7 +20,7 @@ fun SendPhoto(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<Message> {
): Request<ContentMessage<PhotoContent>> {
val data = SendPhotoData(
chatId,
(photo as? FileId) ?.fileId,
@ -37,6 +38,9 @@ fun SendPhoto(
)
}
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PhotoContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendPhotoData internal constructor(
@SerialName(chatIdField)
@ -53,10 +57,10 @@ data class SendPhotoData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>
) : DataRequest<ContentMessage<PhotoContent>>,
SendMessageRequest<ContentMessage<PhotoContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<PhotoContent>>,
TextableSendMessageRequest<ContentMessage<PhotoContent>>
{
init {
text ?.let {
@ -67,8 +71,8 @@ data class SendPhotoData internal constructor(
}
override fun method(): String = "sendPhoto"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<PhotoContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -5,8 +5,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.Replyi
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.StickerContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
import kotlinx.serialization.*
import kotlinx.serialization.json.JsonObject
@ -17,7 +18,7 @@ fun SendSticker(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<Message> = SendStickerByFileId(
): Request<ContentMessage<StickerContent>> = SendStickerByFileId(
chatId,
sticker as? FileId,
disableNotification,
@ -30,6 +31,9 @@ fun SendSticker(
}
}
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<StickerContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendStickerByFileId internal constructor(
@SerialName(chatIdField)
@ -42,10 +46,10 @@ data class SendStickerByFileId internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<Message>, ReplyingMarkupSendMessageRequest<Message> {
) : SendMessageRequest<ContentMessage<StickerContent>>, ReplyingMarkupSendMessageRequest<ContentMessage<StickerContent>> {
override fun method(): String = "sendSticker"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<StickerContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
@ -54,7 +58,7 @@ data class SendStickerByFile internal constructor(
@Transient
private val sendStickerByFileId: SendStickerByFileId,
val sticker: MultipartFile
) : MultipartRequest<Message>, Request<Message> by sendStickerByFileId {
) : MultipartRequest<ContentMessage<StickerContent>>, Request<ContentMessage<StickerContent>> by sendStickerByFileId {
override val mediaMap: Map<String, MultipartFile> = mapOf(stickerField to sticker)
override val paramsJson: JsonObject = sendStickerByFileId.toJsonWithoutNulls(SendStickerByFileId.serializer())
}

View File

@ -7,8 +7,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.VideoContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -25,7 +26,7 @@ fun SendVideo(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<Message> {
): Request<ContentMessage<VideoContent>> {
val videoAsFileId = (video as? FileId) ?.fileId
val videoAsFile = video as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -56,6 +57,9 @@ fun SendVideo(
}
}
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<VideoContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendVideoData internal constructor(
@SerialName(chatIdField)
@ -82,13 +86,13 @@ data class SendVideoData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>,
DuratedSendMessageRequest<Message>,
SizedSendMessageRequest<Message>
) : DataRequest<ContentMessage<VideoContent>>,
SendMessageRequest<ContentMessage<VideoContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<VideoContent>>,
TextableSendMessageRequest<ContentMessage<VideoContent>>,
ThumbedSendMessageRequest<ContentMessage<VideoContent>>,
DuratedSendMessageRequest<ContentMessage<VideoContent>>,
SizedSendMessageRequest<ContentMessage<VideoContent>>
{
init {
text ?.let {
@ -99,8 +103,8 @@ data class SendVideoData internal constructor(
}
override fun method(): String = "sendVideo"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<VideoContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -7,8 +7,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.VideoNoteContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -23,7 +24,7 @@ fun SendVideoNote(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<Message> {
): Request<ContentMessage<VideoNoteContent>> {
val videoNoteAsFileId = (videoNote as? FileId) ?.fileId
val videoNoteAsFile = videoNote as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -52,6 +53,9 @@ fun SendVideoNote(
}
}
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<VideoNoteContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendVideoNoteData internal constructor(
@SerialName(chatIdField)
@ -74,13 +78,13 @@ data class SendVideoNoteData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>,
DuratedSendMessageRequest<Message>,
SizedSendMessageRequest<Message>
) : DataRequest<ContentMessage<VideoNoteContent>>,
SendMessageRequest<ContentMessage<VideoNoteContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<VideoNoteContent>>,
TextableSendMessageRequest<ContentMessage<VideoNoteContent>>,
ThumbedSendMessageRequest<ContentMessage<VideoNoteContent>>,
DuratedSendMessageRequest<ContentMessage<VideoNoteContent>>,
SizedSendMessageRequest<ContentMessage<VideoNoteContent>>
{
override val height: Int?
get() = width
@ -94,8 +98,8 @@ data class SendVideoNoteData internal constructor(
}
override fun method(): String = "sendVideoNote"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<VideoNoteContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -7,8 +7,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.VoiceContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -22,7 +23,7 @@ fun SendVoice(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<Message> {
): Request<ContentMessage<VoiceContent>> {
val voiceAsFileId = (voice as? FileId) ?.fileId
val voiceAsFile = voice as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -50,6 +51,9 @@ fun SendVoice(
}
}
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<VoiceContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
@Serializable
data class SendVoiceData internal constructor(
@SerialName(chatIdField)
@ -70,12 +74,12 @@ data class SendVoiceData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>,
DuratedSendMessageRequest<Message>
) : DataRequest<ContentMessage<VoiceContent>>,
SendMessageRequest<ContentMessage<VoiceContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<VoiceContent>>,
TextableSendMessageRequest<ContentMessage<VoiceContent>>,
ThumbedSendMessageRequest<ContentMessage<VoiceContent>>,
DuratedSendMessageRequest<ContentMessage<VoiceContent>>
{
init {
text ?.let {
@ -86,8 +90,8 @@ data class SendVoiceData internal constructor(
}
override fun method(): String = "sendVoice"
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ContentMessage<VoiceContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -9,11 +9,12 @@ interface ChatMember {
val user: User
}
internal object ChatMemberSerializerWithoutDeserialization : KSerializer<ChatMember> {
internal object AdministratorChatMemberSerializerWithoutDeserialization : KSerializer<AdministratorChatMember> {
override val descriptor: SerialDescriptor = StringDescriptor.withName("ChatMemberSerializerWithoutDeserialization")
override fun deserialize(decoder: Decoder): ChatMember = ChatMemberDeserializationStrategy.deserialize(decoder)
override fun serialize(encoder: Encoder, obj: ChatMember) = throw UnsupportedOperationException()
override fun deserialize(decoder: Decoder): AdministratorChatMember
= ChatMemberDeserializationStrategy.deserialize(decoder) as AdministratorChatMember
override fun serialize(encoder: Encoder, obj: AdministratorChatMember) = throw UnsupportedOperationException()
}
internal object ChatMemberDeserializationStrategy : DeserializationStrategy<ChatMember> {

View File

@ -6,7 +6,7 @@ import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
@Serializer(InlineQueryResult::class)
object InlineQueryResultSerializer : KSerializer<InlineQueryResult> {
internal object InlineQueryResultSerializer : KSerializer<InlineQueryResult> {
override val descriptor: SerialDescriptor = StringDescriptor.withName(InlineQueryResult::class.toString())
override fun serialize(encoder: Encoder, obj: InlineQueryResult) {
when(obj) {

View File

@ -6,7 +6,7 @@ import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
@Serializer(InputMessageContent::class)
object InputMessageContentSerializer : KSerializer<InputMessageContent> {
internal object InputMessageContentSerializer : KSerializer<InputMessageContent> {
override val descriptor: SerialDescriptor = StringDescriptor.withName(InputMessageContent::class.toString())
override fun serialize(encoder: Encoder, obj: InputMessageContent) {
when (obj) {

View File

@ -4,7 +4,7 @@ import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
@Serializer(InputMedia::class)
object InputMediaSerializer : KSerializer<InputMedia> {
internal object InputMediaSerializer : KSerializer<InputMedia> {
override val descriptor: SerialDescriptor = StringDescriptor.withName(InputMedia::class.toString())
override fun serialize(encoder: Encoder, obj: InputMedia) {
when (obj) {

View File

@ -4,7 +4,7 @@ import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
@Serializer(MediaGroupMemberInputMedia::class)
object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMemberInputMedia> {
internal object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMemberInputMedia> {
override val descriptor: SerialDescriptor = StringDescriptor.withName(MediaGroupMemberInputMedia::class.toString())
override fun serialize(encoder: Encoder, obj: MediaGroupMemberInputMedia) {
when (obj) {

View File

@ -13,6 +13,6 @@ data class UserProfilePhotos (
val photos: List<Photo>
)
object UserProfilePhotosPhotosSerializer : KSerializer<List<Photo>> by ArrayListSerializer(
internal object UserProfilePhotosPhotosSerializer : KSerializer<List<Photo>> by ArrayListSerializer(
PhotoSerializer
)

View File

@ -5,7 +5,7 @@ import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
import kotlinx.serialization.json.*
object InlineKeyboardButtonSerializer : KSerializer<InlineKeyboardButton> {
internal object InlineKeyboardButtonSerializer : KSerializer<InlineKeyboardButton> {
override val descriptor: SerialDescriptor = StringDescriptor.withName("com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons.InlineKeyboardButton")
private fun resolveSerializer(json: JsonObject): KSerializer<out InlineKeyboardButton> {

View File

@ -4,7 +4,7 @@ import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
@Serializer(KeyboardMarkup::class)
object KeyboardMarkupSerializer : KSerializer<KeyboardMarkup> {
internal object KeyboardMarkupSerializer : KSerializer<KeyboardMarkup> {
override val descriptor: SerialDescriptor = StringDescriptor.withName(KeyboardMarkup::class.toString())
override fun serialize(encoder: Encoder, obj: KeyboardMarkup) {
when(obj) {

View File

@ -11,7 +11,7 @@ import kotlinx.serialization.json.JsonObjectSerializer
private val formatter = Json.nonstrict
object PreviewChatSerializer : KSerializer<Chat> {
internal object PreviewChatSerializer : KSerializer<Chat> {
override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer")
override fun deserialize(decoder: Decoder): Chat {
@ -39,7 +39,7 @@ object PreviewChatSerializer : KSerializer<Chat> {
}
}
object ExtendedChatSerializer : KSerializer<ExtendedChat> {
internal object ExtendedChatSerializer : KSerializer<ExtendedChat> {
override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer")
override fun deserialize(decoder: Decoder): ExtendedChat {

View File

@ -13,7 +13,7 @@ fun Photo.biggest(): PhotoSize? = maxBy {
it.resolution
}
object PhotoSerializer : KSerializer<Photo> by ArrayListSerializer(
internal object PhotoSerializer : KSerializer<Photo> by ArrayListSerializer(
PhotoSize.serializer()
)

View File

@ -16,7 +16,7 @@ data class ChannelMediaGroupMessage(
override val mediaGroupId: MediaGroupIdentifier,
override val content: MediaGroupContent,
override val editDate: DateTime?,
override val forwarded: ForwardedMessage?,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?
) : MediaGroupMessage

View File

@ -15,7 +15,7 @@ data class ChannelMessage<T: MessageContent>(
override val content: T,
override val date: DateTime,
override val editDate: DateTime?,
override val forwarded: ForwardedMessage?,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
val authorSignature: AuthorSignature?

View File

@ -15,7 +15,7 @@ data class CommonMediaGroupMessage(
override val mediaGroupId: MediaGroupIdentifier,
override val content: MediaGroupContent,
override val editDate: DateTime?,
override val forwarded: ForwardedMessage?,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?
) : MediaGroupMessage, FromUserMessage

View File

@ -16,7 +16,7 @@ data class CommonMessageImpl<T: MessageContent>(
override val content: T,
override val date: DateTime,
override val editDate: DateTime?,
override val forwarded: ForwardedMessage?,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
val paymentInfo: PaymentInfo?

View File

@ -0,0 +1,57 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
@Deprecated(
"Renamed",
ReplaceWith(
"ForwardInfo",
"com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo"
)
)
typealias ForwardedMessage = ForwardInfo
sealed class ForwardInfo {
abstract val dateOfOriginal: TelegramDate
}
@Deprecated(
"Renamed",
ReplaceWith(
"AnonymousForwardInfo",
"com.github.insanusmokrassar.TelegramBotAPI.types.message.AnonymousForwardInfo"
)
)
typealias AnonymousForwardedMessage = AnonymousForwardInfo
data class AnonymousForwardInfo(
override val dateOfOriginal: TelegramDate,
val senderName: String
) : ForwardInfo()
@Deprecated(
"Renamed",
ReplaceWith(
"UserForwardInfo",
"com.github.insanusmokrassar.TelegramBotAPI.types.message.UserForwardInfo"
)
)
typealias UserForwardedMessage = UserForwardInfo
data class UserForwardInfo(
override val dateOfOriginal: TelegramDate,
val from: User
) : ForwardInfo()
@Deprecated(
"Renamed",
ReplaceWith(
"ForwardFromChannelInfo",
"com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardFromChannelInfo"
)
)
typealias ForwardedFromChannelMessage = ForwardFromChannelInfo
data class ForwardFromChannelInfo(
override val dateOfOriginal: TelegramDate,
val messageId: MessageIdentifier,
val channelChat: Chat,
val signature: String? = null
) : ForwardInfo()

View File

@ -1,25 +0,0 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
sealed class ForwardedMessage {
abstract val dateOfOriginal: TelegramDate
}
data class AnonymousForwardedMessage(
override val dateOfOriginal: TelegramDate,
val senderName: String
) : ForwardedMessage()
data class UserForwardedMessage(
override val dateOfOriginal: TelegramDate,
val from: User
) : ForwardedMessage()
data class ForwardedFromChannelMessage(
override val dateOfOriginal: TelegramDate,
val messageId: MessageIdentifier,
val channelChat: Chat,
val signature: String? = null
) : ForwardedMessage()

View File

@ -134,20 +134,20 @@ internal data class RawMessage(
}
@Transient
private val forwarded: ForwardedMessage? by lazy {
private val forwarded: ForwardInfo? by lazy {
forward_date ?: return@lazy null // According to the documentation, now any forwarded message contains this field
when {
forward_sender_name != null -> AnonymousForwardedMessage(
forward_sender_name != null -> AnonymousForwardInfo(
forward_date,
forward_sender_name
)
forward_from_chat != null -> ForwardedFromChannelMessage(
forward_from_chat != null -> ForwardFromChannelInfo(
forward_date,
forward_from_message_id ?: throw IllegalStateException("Channel forwarded message must contain message id, but was not"),
forward_from_chat,
forward_signature
)
forward_from != null -> UserForwardedMessage(
forward_from != null -> UserForwardInfo(
forward_date,
forward_from
)

View File

@ -1,7 +0,0 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardedMessage
interface AbleToBeForwardedMessage : Message {
val forwarded: ForwardedMessage?
}

View File

@ -3,8 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
interface CommonMessage<T: MessageContent> : Message,
AbleToBeForwardedMessage,
AbleToBeEditedMessage,
AbleToReplyMessage,
AbleToBeMarkedUp,
PossiblyForwardedMessage,
PossiblyEditedMessage,
PossiblyReplyMessage,
PossiblyMarkedUp,
ContentMessage<T>

View File

@ -13,24 +13,29 @@ interface Message {
val date: DateTime
}
internal object TelegramBotAPIMessageDeserializationStrategy : DeserializationStrategy<Message> {
internal class TelegramBotAPIMessageDeserializationStrategyClass<T> : DeserializationStrategy<T> {
override val descriptor: SerialDescriptor = StringDescriptor.withName("TelegramBotAPIMessageSerializer")
override fun patch(decoder: Decoder, old: Message): Message = throw UpdateNotSupportedException(descriptor.name)
override fun deserialize(decoder: Decoder): Message {
return RawMessage.serializer().deserialize(decoder).asMessage
override fun patch(decoder: Decoder, old: T): T = throw UpdateNotSupportedException(descriptor.name)
override fun deserialize(decoder: Decoder): T {
return RawMessage.serializer().deserialize(decoder).asMessage as T
}
}
internal object TelegramBotAPIMessageDeserializationStrategy
: DeserializationStrategy<Message> by TelegramBotAPIMessageDeserializationStrategyClass()
internal object TelegramBotAPIMessageDeserializeOnlySerializer : KSerializer<Message> {
internal class TelegramBotAPIMessageDeserializeOnlySerializerClass<T : Message> : KSerializer<T> {
private val deserializer = TelegramBotAPIMessageDeserializationStrategyClass<T>()
override val descriptor: SerialDescriptor
get() = TelegramBotAPIMessageDeserializationStrategy.descriptor
get() = deserializer.descriptor
override fun deserialize(decoder: Decoder): Message {
return TelegramBotAPIMessageDeserializationStrategy.deserialize(decoder)
override fun deserialize(decoder: Decoder): T {
return deserializer.deserialize(decoder)
}
override fun serialize(encoder: Encoder, obj: Message) {
override fun serialize(encoder: Encoder, obj: T) {
throw UnsupportedOperationException("Currently, Message objects can't be serialized y this serializer")
}
}
internal object TelegramBotAPIMessageDeserializeOnlySerializer
: KSerializer<Message> by TelegramBotAPIMessageDeserializeOnlySerializerClass()

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.soywiz.klock.DateTime
interface AbleToBeEditedMessage : Message {
interface PossiblyEditedMessage : Message {
val editDate: DateTime?
}

View File

@ -0,0 +1,13 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo
interface PossiblyForwardedMessage : Message {
val forwardInfo: ForwardInfo?
@Deprecated(
"Renamed",
ReplaceWith("forwardInfo")
)
val forwarded: ForwardInfo?
get() = forwardInfo
}

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
interface AbleToBeMarkedUp {
interface PossiblyMarkedUp {
val replyMarkup: InlineKeyboardMarkup?
}

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo
interface AbleToBePaymentedMessage : Message {
interface PossiblyPaymentMessage : Message {
val paymentInfo: PaymentInfo?
}

View File

@ -1,5 +1,5 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
interface AbleToReplyMessage {
interface PossiblyReplyMessage {
val replyTo: Message?
}

View File

@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendContact
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
@ -15,7 +16,7 @@ data class ContactContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendContact(
): Request<ContentMessage<ContactContent>> = SendContact(
chatId, contact, disableNotification, replyToMessageId, replyMarkup
)
}

View File

@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.games.Game
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
@ -17,7 +18,7 @@ data class GameContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendGame(
): Request<ContentMessage<GameContent>> = SendGame(
chatId,
game.title,
disableNotification,

View File

@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendLocation
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
@ -15,7 +16,7 @@ data class LocationContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendLocation(
): Request<ContentMessage<LocationContent>> = SendLocation(
chatId,
location.latitude,
location.longitude,

View File

@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendPoll
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
@ -17,7 +18,7 @@ data class PollContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendPoll(
): Request<ContentMessage<PollContent>> = SendPoll(
chatId,
poll.question,
poll.options.map { it.text },

View File

@ -3,10 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendMessage
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendTextMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
@ -20,7 +22,7 @@ data class TextContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendMessage(
): Request<ContentMessage<TextContent>> = SendTextMessage(
chatId,
toHtmlTexts().first(),
HTMLParseMode,
@ -35,7 +37,7 @@ data class TextContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): List<Request<Message>> = createResends(
): List<Request<ContentMessage<TextContent>>> = createResends(
chatId,
disableNotification,
replyToMessageId,
@ -49,12 +51,12 @@ data class TextContent(
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?,
parseMode: ParseMode = HTMLParseMode
): List<Request<Message>> = when (parseMode) {
): List<Request<ContentMessage<TextContent>>> = when (parseMode) {
is MarkdownParseMode -> toMarkdownTexts()
is MarkdownV2ParseMode -> toMarkdownV2Texts()
is HTMLParseMode -> toHtmlTexts()
}.map {
SendMessage(
SendTextMessage(
chatId,
it,
parseMode,

View File

@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendVenue
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
@ -15,7 +16,7 @@ data class VenueContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendVenue(
): Request<ContentMessage<VenueContent>> = SendVenue(
chatId, venue, disableNotification, replyToMessageId, replyMarkup
)
}

View File

@ -12,12 +12,12 @@ interface ResendableContent {
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<Message>
): Request<out Message>
fun createResends(
chatId: ChatIdentifier,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): List<Request<Message>> = listOf(createResend(chatId, disableNotification, replyToMessageId, replyMarkup))
): List<Request<out Message>> = listOf(createResend(chatId, disableNotification, replyToMessageId, replyMarkup))
}

View File

@ -10,6 +10,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AnimationFile
import com.github.insanusmokrassar.TelegramBotAPI.types.files.DocumentFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
@ -25,7 +26,7 @@ data class AnimationContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendAnimation(
): Request<ContentMessage<AnimationContent>> = SendAnimation(
chatId,
media.fileId,
media.thumb ?.fileId,

View File

@ -9,6 +9,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AudioFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
@ -23,7 +24,7 @@ data class AudioContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendAudio(
): Request<ContentMessage<AudioContent>> = SendAudio(
chatId,
media.fileId,
media.thumb ?.fileId,

View File

@ -9,6 +9,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.DocumentFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
@ -23,7 +24,7 @@ data class DocumentContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendDocument(
): Request<ContentMessage<DocumentContent>> = SendDocument(
chatId,
media.fileId,
media.thumb ?.fileId,

View File

@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
import com.github.insanusmokrassar.TelegramBotAPI.types.files.biggest
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaCollectionContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
@ -28,7 +29,7 @@ data class PhotoContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendPhoto(
): Request<ContentMessage<PhotoContent>> = SendPhoto(
chatId,
media.fileId,
toHtmlCaptions().firstOrNull(),

View File

@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
@ -17,7 +18,7 @@ data class StickerContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendSticker(
): Request<ContentMessage<StickerContent>> = SendSticker(
chatId,
media.fileId,
disableNotification,

View File

@ -10,6 +10,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
@ -24,7 +25,7 @@ data class VideoContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendVideo(
): Request<ContentMessage<VideoContent>> = SendVideo(
chatId,
media.fileId,
media.thumb ?.fileId,

View File

@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoNoteFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
@ -18,7 +19,7 @@ data class VideoNoteContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = createResend(chatId, null, null, disableNotification, replyToMessageId, replyMarkup)
): Request<ContentMessage<VideoNoteContent>> = createResend(chatId, null, null, disableNotification, replyToMessageId, replyMarkup)
fun createResend(
chatId: ChatIdentifier,
@ -27,7 +28,7 @@ data class VideoNoteContent(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<Message> = SendVideoNote(
): Request<ContentMessage<VideoNoteContent>> = SendVideoNote(
chatId,
media.fileId,
media.thumb ?.fileId,

View File

@ -9,6 +9,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VoiceFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
@ -23,7 +24,7 @@ data class VoiceContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<Message> = SendVoice(
): Request<ContentMessage<VoiceContent>> = SendVoice(
chatId,
media.fileId,
null,

View File

@ -16,6 +16,6 @@ data class ShippingOption(
override val prices: List<LabeledPrice>
) : Priced
object LabeledPricesSerializer : KSerializer<List<LabeledPrice>> by ArrayListSerializer(
internal object LabeledPricesSerializer : KSerializer<List<LabeledPrice>> by ArrayListSerializer(
LabeledPrice.serializer()
)

View File

@ -19,7 +19,7 @@ data class AnonymousPollOption (
override val votes: Int
) : PollOption()
object PollOptionSerializer : KSerializer<PollOption> {
internal object PollOptionSerializer : KSerializer<PollOption> {
override val descriptor: SerialDescriptor = StringDescriptor.withName(PollOption::class.simpleName ?: "PollOption")
override fun deserialize(decoder: Decoder): PollOption = AnonymousPollOption.serializer().deserialize(

View File

@ -2,18 +2,18 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardedMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
val List<BaseMessageUpdate>.forwarded: ForwardedMessage?
val List<BaseMessageUpdate>.forwarded: ForwardInfo?
get() = first().let {
(it as? AbleToBeForwardedMessage) ?.forwarded
(it as? PossiblyForwardedMessage) ?.forwardInfo
}
val List<BaseMessageUpdate>.replyTo: Message?
get() = first().let {
(it as? AbleToReplyMessage) ?.replyTo
(it as? PossiblyReplyMessage) ?.replyTo
}
val List<BaseMessageUpdate>.chat: Chat?

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import kotlinx.io.core.Input
import io.ktor.utils.io.core.Input
import kotlinx.serialization.Serializable
@Serializable

View File

@ -1,7 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.benasher44.uuid.uuid4
import kotlinx.io.core.Input
import io.ktor.utils.io.core.Input
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient

View File

@ -1,8 +1,8 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.benasher44.uuid.uuid4
import kotlinx.io.core.Input
import kotlinx.io.streams.asInput
import io.ktor.utils.io.core.Input
import io.ktor.utils.io.streams.asInput
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import java.io.File