1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 12:08:43 +00:00
This commit is contained in:
InsanusMokrassar 2021-11-09 00:32:04 +06:00
parent fc59ab0cdd
commit a85e7d7387
3 changed files with 13 additions and 10 deletions

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.bot.Ktor.base package dev.inmo.tgbotapi.bot.Ktor.base
import dev.inmo.micro_utils.coroutines.safely import dev.inmo.micro_utils.coroutines.safely
import dev.inmo.micro_utils.coroutines.safelyWithResult
import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory
import dev.inmo.tgbotapi.bot.exceptions.newRequestException import dev.inmo.tgbotapi.bot.exceptions.newRequestException
import dev.inmo.tgbotapi.requests.GetUpdates import dev.inmo.tgbotapi.requests.GetUpdates
@ -57,7 +58,7 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
val content = response.receive<String>() val content = response.receive<String>()
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content) val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
return safely { return safelyWithResult {
(responseObject.result?.let { (responseObject.result?.let {
jsonFormatter.decodeFromJsonElement(request.resultDeserializer, it) jsonFormatter.decodeFromJsonElement(request.resultDeserializer, it)
} ?: response.let { } ?: response.let {
@ -67,7 +68,7 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
"Can't get result object from $content" "Can't get result object from $content"
) )
}) })
} }.getOrThrow()
} }
} }

View File

@ -2,9 +2,7 @@ package dev.inmo.tgbotapi.requests.chat.invite_links
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.builtins.serializer import kotlinx.serialization.builtins.serializer
sealed interface ChatJoinRequestAnswer : SimpleRequest<Boolean> { sealed interface ChatJoinRequestAnswer : SimpleRequest<Boolean> {
@ -17,7 +15,9 @@ sealed interface ChatJoinRequestAnswer : SimpleRequest<Boolean> {
@Serializable @Serializable
data class ApproveChatJoinRequest( data class ApproveChatJoinRequest(
@SerialName(chatIdField)
override val chatId: ChatIdentifier, override val chatId: ChatIdentifier,
@SerialName(userIdField)
override val userId: UserId override val userId: UserId
) : ChatJoinRequestAnswer { ) : ChatJoinRequestAnswer {
override val requestSerializer: SerializationStrategy<*> override val requestSerializer: SerializationStrategy<*>
@ -28,7 +28,9 @@ data class ApproveChatJoinRequest(
@Serializable @Serializable
data class DeclineChatJoinRequest( data class DeclineChatJoinRequest(
@SerialName(chatIdField)
override val chatId: ChatIdentifier, override val chatId: ChatIdentifier,
@SerialName(userIdField)
override val userId: UserId override val userId: UserId
) : ChatJoinRequestAnswer { ) : ChatJoinRequestAnswer {
override val requestSerializer: SerializationStrategy<*> override val requestSerializer: SerializationStrategy<*>

View File

@ -9,12 +9,12 @@ import kotlinx.serialization.Serializable
data class ChatJoinRequest( data class ChatJoinRequest(
@SerialName(chatField) @SerialName(chatField)
val chat: PublicChat, val chat: PublicChat,
@SerialName(userField) @SerialName(fromField)
override val from: User, override val from: User,
@SerialName(dateField) @SerialName(dateField)
val date: TelegramDate, val date: TelegramDate,
@SerialName(bioField)
val bio: String,
@SerialName(inviteLinkField) @SerialName(inviteLinkField)
val inviteLink: ChatInviteLink val inviteLink: ChatInviteLink,
@SerialName(bioField)
val bio: String? = null
) : FromUser ) : FromUser