1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +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
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.exceptions.newRequestException
import dev.inmo.tgbotapi.requests.GetUpdates
@ -57,7 +58,7 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
val content = response.receive<String>()
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
return safely {
return safelyWithResult {
(responseObject.result?.let {
jsonFormatter.decodeFromJsonElement(request.resultDeserializer, it)
} ?: response.let {
@ -67,7 +68,7 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
"Can't get result object from $content"
)
})
}
}.getOrThrow()
}
}
@ -76,4 +77,4 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
urlsKeeper: TelegramAPIUrlsKeeper,
request: Request<T>
): Any?
}
}

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.types.*
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
sealed interface ChatJoinRequestAnswer : SimpleRequest<Boolean> {
@ -17,7 +15,9 @@ sealed interface ChatJoinRequestAnswer : SimpleRequest<Boolean> {
@Serializable
data class ApproveChatJoinRequest(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(userIdField)
override val userId: UserId
) : ChatJoinRequestAnswer {
override val requestSerializer: SerializationStrategy<*>
@ -28,7 +28,9 @@ data class ApproveChatJoinRequest(
@Serializable
data class DeclineChatJoinRequest(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(userIdField)
override val userId: UserId
) : ChatJoinRequestAnswer {
override val requestSerializer: SerializationStrategy<*>

View File

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