1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

"RawMessage" usages replaced by "Message" usages

This commit is contained in:
InsanusMokrassar 2019-08-17 11:50:46 +06:00
parent 8330aa1b3d
commit 56f36523db
96 changed files with 319 additions and 256 deletions

View File

@ -2,6 +2,12 @@
## 0.18.0
* `RawMessage` now is internal class
* All `RawMessage` usages was replaced with `Message` interface
* `TelegramBotAPIMessageDeserializationStrategy` was created. It was used for deserialization of Telegram Bot API
incoming messages
* `TelegramBotAPIMessageDeserializeOnlySerializer` was created. It **MUST NOT** be used to serialize messages
## 0.17.0
Libraries updates:

View File

@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.newRequestExcep
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.EmptyLimiter
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.RequestLimiter
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.extractResult
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
@ -16,6 +17,7 @@ import io.ktor.client.engine.HttpClientEngine
import io.ktor.util.cio.toByteArray
import kotlinx.coroutines.delay
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElementSerializer
class KtorRequestsExecutor(
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
@ -74,11 +76,11 @@ class KtorRequestsExecutor(
val content = call.response.use {
it.content.toByteArray().toString(Charsets.UTF_8)
}
val responseObject = jsonFormatter.parse(
Response.serializer(request.resultSerializer()),
content
)
responseObject.result ?: responseObject.parameters ?.let {
val responseObject = jsonFormatter.extractResult(content)
val result = responseObject.result ?.let {
jsonFormatter.fromJson(request.resultDeserializer(), it)
} ?: responseObject.parameters ?.let {
val error = it.error
if (error is RetryAfterError) {
delay(error.leftToRetry)
@ -93,6 +95,7 @@ class KtorRequestsExecutor(
"Can't get result object from $content"
)
}
result
}
}

View File

@ -3,9 +3,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapWithCommonValues
import io.ktor.client.HttpClient
import io.ktor.client.request.forms.*
import io.ktor.client.request.forms.MultiPartFormDataContent
import io.ktor.client.request.forms.formData
import io.ktor.http.Headers
import io.ktor.http.HttpHeaders
import kotlinx.io.core.readBytes
class MultipartRequestCallFactory : AbstractRequestCallFactory() {
@ -21,9 +23,7 @@ class MultipartRequestCallFactory : AbstractRequestCallFactory() {
when (value) {
is MultipartFile -> append(
key,
InputProvider {
value.file.asInput()
},
value.file.asInput().readBytes(),
Headers.build {
append(HttpHeaders.ContentType, value.mimeType)
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")

View File

@ -4,7 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import java.io.IOException
fun newRequestException(
response: Response<*>,
response: Response,
plainAnswer: String,
message: String? = null,
cause: Throwable? = null
@ -15,7 +15,7 @@ fun newRequestException(
}
sealed class RequestException constructor(
val response: Response<*>,
val response: Response,
val plainAnswer: String,
message: String? = null,
cause: Throwable? = null
@ -24,13 +24,13 @@ sealed class RequestException constructor(
cause
)
class CommonRequestException(response: Response<*>, plainAnswer: String, message: String?, cause: Throwable?) :
class CommonRequestException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
RequestException(response, plainAnswer, message, cause)
class UnauthorizedException(response: Response<*>, plainAnswer: String, message: String?, cause: Throwable?) :
class UnauthorizedException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
RequestException(response, plainAnswer, message, cause)
class ReplyMessageNotFoundException(response: Response<*>, plainAnswer: String, message: String?, cause: Throwable?) :
class ReplyMessageNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
RequestException(response, plainAnswer, message, cause)
@Deprecated(

View File

@ -15,5 +15,5 @@ data class DeleteMessage(
) : SimpleRequest<Boolean>, MessageAction {
override fun method(): String = "deleteMessage"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -3,7 +3,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
@Serializable
@ -16,12 +17,12 @@ data class ForwardMessage(
override val messageId: MessageIdentifier,
@SerialName(disableNotificationField)
val disableNotification: Boolean = false
): SimpleRequest<RawMessage>, MessageAction {
): SimpleRequest<Message>, MessageAction {
@Transient
override val chatId: ChatIdentifier
get() = fromChatId
override fun method(): String = "forwardMessage"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -8,5 +8,5 @@ import kotlinx.serialization.Serializable
@Serializable
class GetMe : SimpleRequest<User> {
override fun method(): String = "getMe"
override fun resultSerializer(): KSerializer<User> = User.serializer()
override fun resultDeserializer(): KSerializer<User> = User.serializer()
}

View File

@ -38,5 +38,5 @@ data class GetUpdates(
): SimpleRequest<List<RawUpdate>> {
override fun method(): String = "getUpdates"
override fun resultSerializer(): KSerializer<List<RawUpdate>> = ArrayListSerializer(RawUpdate.serializer())
override fun resultDeserializer(): KSerializer<List<RawUpdate>> = ArrayListSerializer(RawUpdate.serializer())
}

View File

@ -18,5 +18,5 @@ data class StopPoll(
override val replyMarkup: InlineKeyboardMarkup? = null
) : MessageAction, SimpleRequest<Poll>, ReplyMarkup {
override fun method(): String = "stopPoll"
override fun resultSerializer(): KSerializer<Poll> = Poll.serializer()
override fun resultDeserializer(): KSerializer<Poll> = Poll.serializer()
}

View File

@ -8,14 +8,13 @@ import kotlinx.serialization.json.JsonObject
@Serializable(RequestSerializer::class)
interface Request<T: Any> {
fun method(): String
fun resultSerializer(): KSerializer<T>
fun resultDeserializer(): DeserializationStrategy<T>
fun json(): JsonObject = toJsonWithoutNulls(RequestSerializer)
}
object RequestSerializer : KSerializer<Request<*>> by ContextSerializer(Request::class)
fun <T : Any> StringFormat.extractResult(
from: String,
dataSerializer: KSerializer<T>
): Response<T> {
return parse(Response.serializer(dataSerializer), from)
fun StringFormat.extractResult(
from: String
): Response {
return parse(Response.serializer(), from)
}

View File

@ -20,7 +20,7 @@ data class AnswerCallbackQuery(
val cachedTimeSeconds: Int? = null
) : SimpleRequest<Boolean> {
override fun method(): String = "answerCallbackQuery"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}
fun CallbackQuery.createAnswer(

View File

@ -28,7 +28,7 @@ data class AnswerInlineQuery(
val switchPmParameter: String? = null
): SimpleRequest<Boolean> {
override fun method(): String = "answerInlineQuery"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}
fun InlineQuery.createAnswer(

View File

@ -7,7 +7,7 @@ import kotlinx.serialization.serializer
interface AnswerPreCheckoutQuery : SimpleRequest<Boolean> {
override fun method(): String = "answerPreCheckoutQuery"
override fun resultSerializer(): KSerializer<Boolean> = Boolean.serializer()
override fun resultDeserializer(): KSerializer<Boolean> = Boolean.serializer()
val preCheckoutQueryId: PreCheckoutQueryId
val isOk: Boolean

View File

@ -7,7 +7,7 @@ import kotlinx.serialization.serializer
interface AnswerShippingQuery : SimpleRequest<Boolean> {
override fun method(): String = "answerShippingQuery"
override fun resultSerializer(): KSerializer<Boolean> = Boolean.serializer()
override fun resultDeserializer(): KSerializer<Boolean> = Boolean.serializer()
val shippingQueryId: ShippingQueryIdentifier
val isOk: Boolean

View File

@ -13,5 +13,5 @@ data class ExportChatInviteLink(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<String> {
override fun method(): String = "exportChatInviteLink"
override fun resultSerializer(): KSerializer<String> = StringSerializer
override fun resultDeserializer(): KSerializer<String> = StringSerializer
}

View File

@ -13,5 +13,5 @@ data class LeaveChat(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "leaveChat"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -14,5 +14,5 @@ data class GetChat(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<ExtendedChat> {
override fun method(): String = "getChat"
override fun resultSerializer(): KSerializer<ExtendedChat> = ExtendedChatSerializer
override fun resultDeserializer(): KSerializer<ExtendedChat> = ExtendedChatSerializer
}

View File

@ -14,5 +14,5 @@ data class GetChatAdministrators(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<List<RawChatMember>> {
override fun method(): String = "getChatAdministrators"
override fun resultSerializer(): KSerializer<List<RawChatMember>> = ArrayListSerializer(RawChatMember.serializer())
override fun resultDeserializer(): KSerializer<List<RawChatMember>> = ArrayListSerializer(RawChatMember.serializer())
}

View File

@ -13,5 +13,5 @@ data class GetChatMembersCount(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<Int> {
override fun method(): String = "getChatMembersCount"
override fun resultSerializer(): KSerializer<Int> = IntSerializer
override fun resultDeserializer(): KSerializer<Int> = IntSerializer
}

View File

@ -13,5 +13,5 @@ data class GetChatMember(
override val userId: UserId
) : ChatMemberRequest<RawChatMember> {
override fun method(): String = "getChatMember"
override fun resultSerializer(): KSerializer<RawChatMember> = RawChatMember.serializer()
override fun resultDeserializer(): KSerializer<RawChatMember> = RawChatMember.serializer()
}

View File

@ -16,5 +16,5 @@ data class KickChatMember(
override val untilDate: TelegramDate? = null
) : ChatMemberRequest<Boolean>, UntilDate {
override fun method(): String = "kickChatMember"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -32,5 +32,5 @@ data class PromoteChatMember(
private val canPromoteMembers: Boolean? = null
) : ChatMemberRequest<Boolean>, UntilDate {
override fun method(): String = "promoteChatMember"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -19,5 +19,5 @@ data class RestrictChatMember(
val permissions: ChatPermissions
) : ChatMemberRequest<Boolean>, UntilDate {
override fun method(): String = "restrictChatMember"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -13,5 +13,5 @@ data class UnbanChatMember(
override val userId: UserId
) : ChatMemberRequest<Boolean> {
override fun method(): String = "unbanChatMember"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -13,5 +13,5 @@ data class DeleteChatPhoto(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "deleteChatPhoto"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -16,5 +16,5 @@ data class PinChatMessage (
override val disableNotification: Boolean = false
): ChatRequest, SimpleRequest<Boolean>, MessageAction, DisableNotification {
override fun method(): String = "pinChatMessage"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -20,5 +20,5 @@ data class SetChatDescription (
}
override fun method(): String = "setChatDescription"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -15,5 +15,5 @@ data class SetChatPermissions (
val permissions: ChatPermissions
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "setChatPermissions"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -16,7 +16,7 @@ data class SetChatPhoto (
val photo: MultipartFile = throw IllegalArgumentException("Unfortunately, this type of objects can't be parsed automatically")
): ChatRequest, MultipartRequest<Boolean> {
override fun method(): String = "setChatPhoto"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
override val paramsJson: JsonObject = toJson(serializer())
}

View File

@ -20,5 +20,5 @@ data class SetChatTitle (
}
override fun method(): String = "setChatTitle"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -13,5 +13,5 @@ data class UnpinChatMessage(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "unpinChatMessage"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -13,5 +13,5 @@ data class DeleteChatStickerSet(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "deleteChatStickerSet"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -14,5 +14,5 @@ data class SetChatStickerSet(
val stickerSetName: StickerSetName
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "setChatStickerSet"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -3,7 +3,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
@Serializable
@ -20,5 +21,5 @@ data class EditChatMessageLiveLocation(
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage, EditReplyMessage, EditLocationMessage {
override fun method(): String = "editMessageLiveLocation"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -4,7 +4,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
@Serializable
@ -17,5 +18,5 @@ data class StopChatMessageLiveLocation(
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage, EditReplyMessage {
override fun method(): String = "stopMessageLiveLocation"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -4,7 +4,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
const val editMessageReplyMarkupMethod = "editMessageReplyMarkup"
@ -20,5 +21,5 @@ data class EditChatMessageReplyMarkup(
) : EditChatMessage, EditReplyMessage {
override fun method(): String = editMessageReplyMarkupMethod
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -2,6 +2,6 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
interface EditChatMessage : SimpleRequest<RawMessage>, MessageAction
interface EditChatMessage : SimpleRequest<Message>, MessageAction

View File

@ -7,5 +7,5 @@ import kotlinx.serialization.internal.BooleanSerializer
interface EditInlineMessage : SimpleRequest<Boolean> {
val inlineMessageId: InlineMessageIdentifier
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -5,7 +5,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
const val editMessageCaptionMethod = "editMessageCaption"
@ -25,5 +26,5 @@ data class EditChatMessageCaption(
) : EditChatMessage, EditTextChatMessage, EditReplyMessage {
override fun method(): String = editMessageCaptionMethod
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -5,7 +5,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
const val editMessageMediaMethod = "editMessageMedia"
@ -29,5 +30,5 @@ data class EditChatMessageMedia(
}
override fun method(): String = editMessageMediaMethod
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -5,7 +5,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
const val editMessageTextMethod = "editMessageText"
@ -27,5 +28,5 @@ data class EditChatMessageText(
) : EditChatMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
override fun method(): String = editMessageTextMethod
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -10,7 +10,7 @@ interface GetGameHighScores : SimpleRequest<List<GameHighScore>> {
val userId: UserId
override fun method(): String = "getGameHighScores"
override fun resultSerializer(): KSerializer<List<GameHighScore>> = GameHighScoresSerializer
override fun resultDeserializer(): KSerializer<List<GameHighScore>> = GameHighScoresSerializer
}
object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ArrayListSerializer(GameHighScore.serializer())

View File

@ -12,5 +12,5 @@ interface SetGameScore : SimpleRequest<Boolean> {
val disableEditMessage: Boolean
override fun method(): String = "setGameScore"
override fun resultSerializer(): KSerializer<Boolean> = Boolean.serializer()
override fun resultDeserializer(): KSerializer<Boolean> = Boolean.serializer()
}

View File

@ -12,5 +12,5 @@ data class GetFile(
val fileId: FileId
): SimpleRequest<PathedFile> {
override fun method(): String = "getFile"
override fun resultSerializer(): KSerializer<PathedFile> = PathedFile.serializer()
override fun resultDeserializer(): KSerializer<PathedFile> = PathedFile.serializer()
}

View File

@ -11,5 +11,5 @@ data class GetStickerSet(
val name: String
): SimpleRequest<StickerSet> {
override fun method(): String = "getStickerSet"
override fun resultSerializer(): KSerializer<StickerSet> = StickerSet.serializer()
override fun resultDeserializer(): KSerializer<StickerSet> = StickerSet.serializer()
}

View File

@ -23,5 +23,5 @@ data class GetUserProfilePhotos(
}
override fun method(): String = "getUserProfilePhotos"
override fun resultSerializer(): KSerializer<UserProfilePhotos> = UserProfilePhotos.serializer()
override fun resultDeserializer(): KSerializer<UserProfilePhotos> = UserProfilePhotos.serializer()
}

View File

@ -17,5 +17,5 @@ data class SendAction(
val action: BotAction
): SendChatMessageRequest<Boolean> {
override fun method(): String = "sendChatAction"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -4,7 +4,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
@Serializable
@ -23,8 +24,8 @@ data class SendContact(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>
) : SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>
{
constructor(
chatId: ChatIdentifier,
@ -43,7 +44,7 @@ data class SendContact(
)
override fun method(): String = "sendContact"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}
fun Contact.toRequest(

View File

@ -3,7 +3,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
// TODO:: Add location tracker for tracking location
@ -23,11 +24,11 @@ data class SendLocation(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>,
PositionedSendMessageRequest<RawMessage>
) : SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
PositionedSendMessageRequest<Message>
{
override fun method(): String = "sendLocation"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -6,7 +6,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
@Serializable
@ -25,9 +26,9 @@ data class SendMessage(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>,
TextableSendMessageRequest<RawMessage>,
) : SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
DisableWebPagePreview
{
init {
@ -37,5 +38,5 @@ data class SendMessage(
}
override fun method(): String = "sendMessage"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -4,7 +4,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
@Serializable
@ -21,8 +22,8 @@ data class SendPoll(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage> {
) : SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message> {
init {
if (question.length !in pollQuestionTextLength) {
@ -39,5 +40,5 @@ data class SendPoll(
}
override fun method(): String = "sendPoll"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -3,7 +3,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
@Serializable
@ -26,10 +27,10 @@ data class SendVenue(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<RawMessage>,
PositionedSendMessageRequest<RawMessage>,
TitledSendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>
) : SendMessageRequest<Message>,
PositionedSendMessageRequest<Message>,
TitledSendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>
{
constructor(
chatId: ChatIdentifier,
@ -50,7 +51,7 @@ data class SendVenue(
)
override fun method(): String = "sendVenue"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}
fun Venue.toRequest(

View File

@ -4,7 +4,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
@Serializable
@ -19,8 +20,8 @@ data class SendGame (
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<RawMessage>,
) : SendMessageRequest<Message>,
ReplyMarkup {
override fun method(): String = "sendGame"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}

View File

@ -7,7 +7,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -23,7 +24,7 @@ fun SendAnimation(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> {
): Request<Message> {
val animationAsFileId = (animation as? FileId) ?.fileId
val animationAsFile = animation as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -77,13 +78,13 @@ data class SendAnimationData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<RawMessage>,
SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>,
TextableSendMessageRequest<RawMessage>,
ThumbedSendMessageRequest<RawMessage>,
DuratedSendMessageRequest<RawMessage>,
SizedSendMessageRequest<RawMessage>
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>,
DuratedSendMessageRequest<Message>,
SizedSendMessageRequest<Message>
{
init {
text ?.let {
@ -94,7 +95,7 @@ data class SendAnimationData internal constructor(
}
override fun method(): String = "sendAnimation"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}
data class SendAnimationFiles internal constructor(

View File

@ -8,7 +8,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -24,7 +25,7 @@ fun SendAudio(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> {
): Request<Message> {
val audioAsFileId = (audio as? FileId) ?.fileId
val audioAsFile = audio as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -78,13 +79,13 @@ data class SendAudioData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<RawMessage>,
SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>,
TextableSendMessageRequest<RawMessage>,
ThumbedSendMessageRequest<RawMessage>,
TitledSendMessageRequest<RawMessage>,
DuratedSendMessageRequest<RawMessage>,
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>,
TitledSendMessageRequest<Message>,
DuratedSendMessageRequest<Message>,
Performerable
{
init {
@ -96,7 +97,7 @@ data class SendAudioData internal constructor(
}
override fun method(): String = "sendAudio"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}
data class SendAudioFiles internal constructor(

View File

@ -7,7 +7,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -20,7 +21,7 @@ fun SendDocument(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> {
): Request<Message> {
val documentAsFileId = (document as? FileId) ?.fileId
val documentAsFile = document as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -65,11 +66,11 @@ data class SendDocumentData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<RawMessage>,
SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>,
TextableSendMessageRequest<RawMessage>,
ThumbedSendMessageRequest<RawMessage>
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>
{
init {
text ?.let {
@ -80,7 +81,7 @@ data class SendDocumentData internal constructor(
}
override fun method(): String = "sendDocument"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}
data class SendDocumentFiles internal constructor(

View File

@ -6,7 +6,7 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
import kotlinx.serialization.*
import kotlinx.serialization.internal.ArrayListSerializer
@ -19,7 +19,7 @@ fun SendMediaGroup(
media: List<MediaGroupMemberInputMedia>,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null
): Request<List<RawMessage>> {
): Request<List<Message>> {
if (media.size !in membersCountInMediaGroup) {
throw IllegalArgumentException("Count of members for media group must be in $membersCountInMediaGroup range")
}
@ -52,7 +52,7 @@ fun SendMediaGroup(
}
}
private val serializer = ArrayListSerializer(RawMessage.serializer())
private val serializer = ArrayListSerializer(TelegramBotAPIMessageDeserializeOnlySerializer)
@Serializable
data class SendMediaGroupData internal constructor(
@ -63,8 +63,8 @@ data class SendMediaGroupData internal constructor(
override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField)
override val replyToMessageId: MessageIdentifier? = null
) : DataRequest<List<RawMessage>>,
SendMessageRequest<List<RawMessage>>
) : DataRequest<List<Message>>,
SendMessageRequest<List<Message>>
{
@SerialName(mediaField)
private val convertedMedia: String
@ -76,7 +76,7 @@ data class SendMediaGroupData internal constructor(
override fun method(): String = "sendMediaGroup"
override fun resultSerializer(): KSerializer<List<RawMessage>> = serializer
override fun resultDeserializer(): DeserializationStrategy<List<Message>> = serializer
}
data class SendMediaGroupFiles internal constructor(

View File

@ -7,7 +7,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
fun SendPhoto(
@ -18,7 +19,7 @@ fun SendPhoto(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> {
): Request<Message> {
val data = SendPhotoData(
chatId,
(photo as? FileId) ?.fileId,
@ -52,10 +53,10 @@ data class SendPhotoData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<RawMessage>,
SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>,
TextableSendMessageRequest<RawMessage>
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>
{
init {
text ?.let {
@ -66,7 +67,7 @@ data class SendPhotoData internal constructor(
}
override fun method(): String = "sendPhoto"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}
data class SendPhotoFiles internal constructor(

View File

@ -5,7 +5,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
import kotlinx.serialization.*
import kotlinx.serialization.json.JsonObject
@ -16,7 +17,7 @@ fun SendSticker(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> = SendStickerByFileId(
): Request<Message> = SendStickerByFileId(
chatId,
sticker as? FileId,
disableNotification,
@ -41,16 +42,16 @@ data class SendStickerByFileId internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<RawMessage>, ReplyingMarkupSendMessageRequest<RawMessage> {
) : SendMessageRequest<Message>, ReplyingMarkupSendMessageRequest<Message> {
override fun method(): String = "sendSticker"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}
data class SendStickerByFile internal constructor(
@Transient
private val sendStickerByFileId: SendStickerByFileId,
val sticker: MultipartFile
) : MultipartRequest<RawMessage>, Request<RawMessage> by sendStickerByFileId {
) : MultipartRequest<Message>, Request<Message> by sendStickerByFileId {
override val mediaMap: Map<String, MultipartFile> = mapOf(stickerField to sticker)
override val paramsJson: JsonObject = sendStickerByFileId.toJsonWithoutNulls(SendStickerByFileId.serializer())
}

View File

@ -7,7 +7,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -24,7 +25,7 @@ fun SendVideo(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> {
): Request<Message> {
val videoAsFileId = (video as? FileId) ?.fileId
val videoAsFile = video as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -81,13 +82,13 @@ data class SendVideoData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<RawMessage>,
SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>,
TextableSendMessageRequest<RawMessage>,
ThumbedSendMessageRequest<RawMessage>,
DuratedSendMessageRequest<RawMessage>,
SizedSendMessageRequest<RawMessage>
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>,
DuratedSendMessageRequest<Message>,
SizedSendMessageRequest<Message>
{
init {
text ?.let {
@ -98,7 +99,7 @@ data class SendVideoData internal constructor(
}
override fun method(): String = "sendVideo"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}
data class SendVideoFiles internal constructor(

View File

@ -7,7 +7,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -22,7 +23,7 @@ fun SendVideoNote(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> {
): Request<Message> {
val videoNoteAsFileId = (videoNote as? FileId) ?.fileId
val videoNoteAsFile = videoNote as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -73,13 +74,13 @@ data class SendVideoNoteData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<RawMessage>,
SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>,
TextableSendMessageRequest<RawMessage>,
ThumbedSendMessageRequest<RawMessage>,
DuratedSendMessageRequest<RawMessage>,
SizedSendMessageRequest<RawMessage>
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>,
DuratedSendMessageRequest<Message>,
SizedSendMessageRequest<Message>
{
@Transient
override val height: Int?
@ -94,7 +95,7 @@ data class SendVideoNoteData internal constructor(
}
override fun method(): String = "sendVideoNote"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}
data class SendVideoNoteFiles internal constructor(

View File

@ -7,7 +7,8 @@ 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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
import kotlinx.serialization.*
@ -21,7 +22,7 @@ fun SendVoice(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> {
): Request<Message> {
val voiceAsFileId = (voice as? FileId) ?.fileId
val voiceAsFile = voice as? MultipartFile
val thumbAsFileId = (thumb as? FileId) ?.fileId
@ -69,12 +70,12 @@ data class SendVoiceData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : DataRequest<RawMessage>,
SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>,
TextableSendMessageRequest<RawMessage>,
ThumbedSendMessageRequest<RawMessage>,
DuratedSendMessageRequest<RawMessage>
) : DataRequest<Message>,
SendMessageRequest<Message>,
ReplyingMarkupSendMessageRequest<Message>,
TextableSendMessageRequest<Message>,
ThumbedSendMessageRequest<Message>,
DuratedSendMessageRequest<Message>
{
init {
text ?.let {
@ -85,7 +86,7 @@ data class SendVoiceData internal constructor(
}
override fun method(): String = "sendVoice"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
}
data class SendVoiceFiles internal constructor(

View File

@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartRequest
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.KSerializer
import kotlinx.serialization.json.JsonObject
@ -13,7 +14,7 @@ class MultipartRequestImpl<D: DataRequest<R>, F: Files, R: Any>(
val files: F
) : MultipartRequest<R> {
override fun method(): String = data.method()
override fun resultSerializer(): KSerializer<R> = data.resultSerializer()
override fun resultDeserializer(): DeserializationStrategy<R> = data.resultDeserializer()
override val paramsJson: JsonObject = data.json()
override val mediaMap: Map<String, MultipartFile> = files
}

View File

@ -4,7 +4,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.LabeledPrice
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.LabeledPricesSerializer
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.abstracts.*
@ -62,9 +63,9 @@ data class SendInvoice(
DisableNotification,
ReplyMessageId,
ReplyMarkup,
SendMessageRequest<RawMessage> {
SendMessageRequest<Message> {
override fun method(): String = "sendInvoice"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
@SerialName(photoUrlField)
var photoUrl: String? = null

View File

@ -12,5 +12,5 @@ data class DeleteStickerFromSet(
val sticker: FileId
) : SimpleRequest<Boolean> {
override fun method(): String = "deleteStickerFromSet"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -21,5 +21,5 @@ data class SetStickerPositionInSet(
}
override fun method(): String = "setStickerPositionInSet"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -24,5 +24,5 @@ data class UploadStickerFile(
override val mediaMap: Map<String, MultipartFile> = mapOf(pngStickerField to sticker)
@Transient
override val paramsJson: JsonObject = toJsonWithoutNulls(serializer())
override fun resultSerializer(): KSerializer<File> = File.serializer()
override fun resultDeserializer(): KSerializer<File> = File.serializer()
}

View File

@ -12,5 +12,5 @@ interface StickerSetAction : SimpleRequest<Boolean> {
val emojis: String // must be more than one
val maskPosition: MaskPosition?
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -9,5 +9,5 @@ import kotlinx.serialization.internal.BooleanSerializer
class DeleteWebhook : SimpleRequest<Boolean> {
override fun method(): String = "deleteWebhook"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -9,5 +9,5 @@ import kotlinx.serialization.Serializable
class GetWebhookInfo : SimpleRequest<WebhookInfo> {
override fun method(): String = "getWebhookInfo"
override fun resultSerializer(): KSerializer<WebhookInfo> = WebhookInfo.serializer()
override fun resultDeserializer(): KSerializer<WebhookInfo> = WebhookInfo.serializer()
}

View File

@ -51,7 +51,7 @@ data class SetWebhook internal constructor(
val allowedUpdates: List<String>? = null
) : DataRequest<Boolean> {
override fun method(): String = "setWebhook"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
init {
maxAllowedConnections ?.let {

View File

@ -2,6 +2,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.CallbackQuery
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
import kotlinx.serialization.*
@Serializable
@ -10,7 +12,8 @@ data class RawCallbackQuery(
val id: CallbackQueryIdentifier,
@SerialName(fromField)
val from: User,
val message: RawMessage? = null,
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
val message: Message? = null,
@SerialName(inlineMessageIdField)
val inlineMessageId: InlineMessageIdentifier? = null,
@SerialName("chat_instance")
@ -22,8 +25,8 @@ data class RawCallbackQuery(
@Transient
val asCallbackQuery: CallbackQuery by lazy {
when {
message != null && data != null -> MessageDataCallbackQuery(id, from, chatInstance, message.asMessage, data)
message != null && gameShortName != null -> MessageGameShortNameCallbackQuery(id, from, chatInstance, message.asMessage, gameShortName)
message != null && data != null -> MessageDataCallbackQuery(id, from, chatInstance, message, data)
message != null && gameShortName != null -> MessageGameShortNameCallbackQuery(id, from, chatInstance, message, gameShortName)
inlineMessageId != null && data != null -> InlineMessageIdDataCallbackQuery(id, from, chatInstance, inlineMessageId, data)
inlineMessageId != null && gameShortName != null -> InlineMessageIdGameShortNameCallbackQuery(id, from, chatInstance, inlineMessageId, gameShortName)
else -> throw IllegalStateException("Strange answer from server, can't create callback query")

View File

@ -2,19 +2,14 @@ package com.github.insanusmokrassar.TelegramBotAPI.types
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Deprecated(
"Deprecated because incorrect name",
ReplaceWith("Response")
)
typealias ResponseParameters<T> = Response<T>
import kotlinx.serialization.json.JsonElement
@Serializable
data class Response<T : Any>(
data class Response(
val ok: Boolean = false,
val description: String? = null,
@SerialName("error_code")
val errorCode: Int? = null,
val result: T? = null,
val result: JsonElement? = null,
val parameters: ResponseParametersRaw? = null
)

View File

@ -2,9 +2,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
import kotlinx.serialization.Serializable
interface ExtendedPublicChat : ExtendedChat, PublicChat {
val description: String
val inviteLink: String?
val pinnedMessage: RawMessage?
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
val pinnedMessage: Message?
}

View File

@ -3,6 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChannelChat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@ -21,5 +23,6 @@ data class ExtendedChannelChatImpl(
@SerialName(inviteLinkField)
override val inviteLink: String? = null,
@SerialName(pinnedMessageField)
override val pinnedMessage: RawMessage? = null
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
override val pinnedMessage: Message? = null
) : ExtendedChannelChat

View File

@ -4,6 +4,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedGroupChat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@ -22,5 +24,6 @@ data class ExtendedGroupChatImpl(
@SerialName(inviteLinkField)
override val inviteLink: String? = null,
@SerialName(pinnedMessageField)
override val pinnedMessage: RawMessage? = null
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
override val pinnedMessage: Message? = null
) : ExtendedGroupChat

View File

@ -4,6 +4,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedSupergroupChat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@ -24,7 +26,8 @@ data class ExtendedSupergroupChatImpl(
@SerialName(inviteLinkField)
override val inviteLink: String? = null,
@SerialName(pinnedMessageField)
override val pinnedMessage: RawMessage? = null,
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
override val pinnedMessage: Message? = null,
@SerialName(stickerSetNameFullField)
override val stickerSetName: StickerSetName? = null,
@SerialName(canSetStickerSetField)

View File

@ -24,7 +24,7 @@ import kotlin.reflect.KClass
// TODO:: add PassportData type
@Serializable
data class RawMessage(
internal data class RawMessage(
@SerialName(messageIdField)
val messageId: MessageIdentifier,
@SerialName(dateField)

View File

@ -2,10 +2,35 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
import org.joda.time.DateTime
interface Message {
val messageId: MessageIdentifier
val chat: Chat
val date: DateTime
}
}
object TelegramBotAPIMessageDeserializationStrategy : DeserializationStrategy<Message> {
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
}
}
object TelegramBotAPIMessageDeserializeOnlySerializer : KSerializer<Message> {
override val descriptor: SerialDescriptor
get() = TelegramBotAPIMessageDeserializationStrategy.descriptor
override fun deserialize(decoder: Decoder): Message {
return TelegramBotAPIMessageDeserializationStrategy.deserialize(decoder)
}
override fun serialize(encoder: Encoder, obj: Message) {
throw IllegalStateException("Currently, Message objects can't be serialized y this serializer")
}
}

View File

@ -4,7 +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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
data class ContactContent(
@ -15,7 +15,7 @@ data class ContactContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendContact(
): Request<Message> = SendContact(
chatId, contact, disableNotification, replyToMessageId, replyMarkup
)
}

View File

@ -6,7 +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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
data class GameContent(
@ -17,7 +17,7 @@ data class GameContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendGame(
): Request<Message> = SendGame(
chatId,
game.title,
disableNotification,

View File

@ -4,7 +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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
data class LocationContent(
@ -15,7 +15,7 @@ data class LocationContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendLocation(
): Request<Message> = SendLocation(
chatId,
location.latitude,
location.longitude,

View File

@ -5,7 +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.RawMessage
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 +17,7 @@ data class PollContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendPoll(
): Request<Message> = SendPoll(
chatId,
poll.question,
poll.options.map { it.text },

View File

@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEnt
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.RawMessage
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.toHtmlTexts
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownTexts
@ -21,7 +21,7 @@ data class TextContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendMessage(
): Request<Message> = SendMessage(
chatId,
toHtmlTexts().first(),
HTMLParseMode,
@ -36,7 +36,7 @@ data class TextContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): List<Request<RawMessage>> = createResends(
): List<Request<Message>> = createResends(
chatId,
disableNotification,
replyToMessageId,
@ -50,7 +50,7 @@ data class TextContent(
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?,
parseMode: ParseMode = HTMLParseMode
): List<Request<RawMessage>> = when (parseMode) {
): List<Request<Message>> = when (parseMode) {
is MarkdownParseMode -> toMarkdownTexts()
is HTMLParseMode -> toHtmlTexts()
}.map {

View File

@ -4,7 +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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
data class VenueContent(
@ -15,7 +15,7 @@ data class VenueContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendVenue(
): Request<Message> = SendVenue(
chatId, venue, disableNotification, replyToMessageId, replyMarkup
)
}

View File

@ -4,7 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
interface ResendableContent {
fun createResend(
@ -12,12 +12,12 @@ interface ResendableContent {
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage>
): Request<Message>
fun createResends(
chatId: ChatIdentifier,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): List<Request<RawMessage>> = listOf(createResend(chatId, disableNotification, replyToMessageId, replyMarkup))
): List<Request<Message>> = listOf(createResend(chatId, disableNotification, replyToMessageId, replyMarkup))
}

View File

@ -11,7 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
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.RawMessage
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
@ -26,22 +26,12 @@ data class AnimationContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = createResend(chatId, toHtmlCaptions().firstOrNull(), HTMLParseMode, disableNotification, replyToMessageId, replyMarkup)
@Deprecated("Will be fully replaced by default method")
fun createResend(
chatId: ChatIdentifier,
caption: String?,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> = SendAnimation(
): Request<Message> = SendAnimation(
chatId,
media.fileId,
media.thumb ?.fileId,
caption,
parseMode,
toHtmlCaptions().firstOrNull(),
HTMLParseMode,
media.duration,
media.width,
media.height,

View File

@ -9,7 +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.RawMessage
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 +23,7 @@ data class AudioContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendAudio(
): Request<Message> = SendAudio(
chatId,
media.fileId,
media.thumb ?.fileId,

View File

@ -9,7 +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.RawMessage
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 +23,7 @@ data class DocumentContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendDocument(
): Request<Message> = SendDocument(
chatId,
media.fileId,
media.thumb ?.fileId,

View File

@ -11,7 +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.RawMessage
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
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
@ -28,7 +28,7 @@ data class PhotoContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendPhoto(
): Request<Message> = SendPhoto(
chatId,
media.fileId,
toHtmlCaptions().firstOrNull(),

View File

@ -6,7 +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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
data class StickerContent(
@ -17,7 +17,7 @@ data class StickerContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendSticker(
): Request<Message> = SendSticker(
chatId,
media.fileId,
disableNotification,

View File

@ -10,7 +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.RawMessage
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 +24,7 @@ data class VideoContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendVideo(
): Request<Message> = SendVideo(
chatId,
media.fileId,
media.thumb ?.fileId,

View File

@ -7,7 +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.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
data class VideoNoteContent(
@ -18,7 +18,7 @@ data class VideoNoteContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = createResend(chatId, null, null, disableNotification, replyToMessageId, replyMarkup)
): Request<Message> = createResend(chatId, null, null, disableNotification, replyToMessageId, replyMarkup)
fun createResend(
chatId: ChatIdentifier,
@ -27,7 +27,7 @@ data class VideoNoteContent(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> = SendVideoNote(
): Request<Message> = SendVideoNote(
chatId,
media.fileId,
media.thumb ?.fileId,

View File

@ -9,7 +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.RawMessage
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 +23,7 @@ data class VoiceContent(
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendVoice(
): Request<Message> = SendVoice(
chatId,
media.fileId,
null,

View File

@ -5,6 +5,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.ChosenInli
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.query.RawInlineQuery
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuery
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingQuery
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
@ -18,10 +20,14 @@ import kotlinx.serialization.*
data class RawUpdate constructor(
@SerialName(updateIdField)
val updateId: UpdateIdentifier,
private val edited_message: RawMessage? = null,
private val message: RawMessage? = null,
private val edited_channel_post: RawMessage? = null,
private val channel_post: RawMessage? = null,
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
private val edited_message: Message? = null,
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
private val message: Message? = null,
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
private val edited_channel_post: Message? = null,
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
private val channel_post: Message? = null,
private val inline_query: RawInlineQuery? = null,
private val chosen_inline_result: RawChosenInlineResult? = null,
private val callback_query: RawCallbackQuery? = null,
@ -32,10 +38,10 @@ data class RawUpdate constructor(
@Transient
val asUpdate: Update by lazy {
when {
edited_message != null -> EditMessageUpdate(updateId, edited_message.asMessage)
message != null -> MessageUpdate(updateId, message.asMessage)
edited_channel_post != null -> EditChannelPostUpdate(updateId, edited_channel_post.asMessage)
channel_post != null -> ChannelPostUpdate(updateId, channel_post.asMessage)
edited_message != null -> EditMessageUpdate(updateId, edited_message)
message != null -> MessageUpdate(updateId, message)
edited_channel_post != null -> EditChannelPostUpdate(updateId, edited_channel_post)
channel_post != null -> ChannelPostUpdate(updateId, channel_post)
chosen_inline_result != null -> ChosenInlineResultUpdate(updateId, chosen_inline_result.asChosenInlineResult)
inline_query != null -> InlineQueryUpdate(updateId, inline_query.asInlineQuery)

View File

@ -9,7 +9,7 @@ import kotlinx.coroutines.*
fun <T: Any> RequestsExecutor.executeAsync(
request: Request<T>,
onFail: (suspend (Response<*>) -> Unit)? = null,
onFail: (suspend (Response) -> Unit)? = null,
scope: CoroutineScope = GlobalScope,
onSuccess: (suspend (T) -> Unit)? = null
): Job {