Skip to content

Commit

Permalink
7.6.1 (#300)
Browse files Browse the repository at this point in the history
* Fixed `ChatMemberUpdated` serde issue.
  • Loading branch information
vendelieu authored Dec 9, 2024
1 parent 9ff0209 commit 78f23c3
Show file tree
Hide file tree
Showing 27 changed files with 180 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Telegram-bot (KtGram) Changelog

### 7.6.1

* Fixed `ChatMemberUpdated` serde issue.

## 7.6.0

* Supported Telegram API [8.1](https://core.telegram.org/bots/api-changelog#december-4-2024).
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
ktor = "3.0.1"
ktor = "3.0.2"
redis = "0.1.7"
logback = "1.5.12"

Expand Down
15 changes: 9 additions & 6 deletions telegram-bot/api/telegram-bot.api
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public abstract interface annotation class eu/vendeli/tgbot/annotations/UpdateHa
public abstract fun type ()[Leu/vendeli/tgbot/types/internal/UpdateType;
}

public abstract interface annotation class eu/vendeli/tgbot/annotations/dsl/ConfigurationDSL : java/lang/annotation/Annotation {
}

public abstract interface annotation class eu/vendeli/tgbot/annotations/dsl/FunctionalDSL : java/lang/annotation/Annotation {
}

public abstract interface annotation class eu/vendeli/tgbot/annotations/internal/ExperimentalFeature : java/lang/annotation/Annotation {
}

Expand Down Expand Up @@ -4205,8 +4211,7 @@ public final class eu/vendeli/tgbot/types/boost/ChatBoostRemoved$Companion {

public abstract class eu/vendeli/tgbot/types/boost/ChatBoostSource {
public static final field Companion Leu/vendeli/tgbot/types/boost/ChatBoostSource$Companion;
public synthetic fun <init> (ILjava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public synthetic fun <init> (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ILkotlinx/serialization/internal/SerializationConstructorMarker;)V
public final fun getSource ()Ljava/lang/String;
public abstract fun getUser ()Leu/vendeli/tgbot/types/User;
public static final synthetic fun write$Self (Leu/vendeli/tgbot/types/boost/ChatBoostSource;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
Expand Down Expand Up @@ -5211,8 +5216,7 @@ public final class eu/vendeli/tgbot/types/chat/ChatLocation$Companion {

public abstract class eu/vendeli/tgbot/types/chat/ChatMember : eu/vendeli/tgbot/interfaces/marker/MultipleResponse {
public static final field Companion Leu/vendeli/tgbot/types/chat/ChatMember$Companion;
public synthetic fun <init> (ILjava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public synthetic fun <init> (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ILkotlinx/serialization/internal/SerializationConstructorMarker;)V
public final fun getStatus ()Ljava/lang/String;
public abstract fun getUser ()Leu/vendeli/tgbot/types/User;
public static final synthetic fun write$Self (Leu/vendeli/tgbot/types/chat/ChatMember;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
Expand Down Expand Up @@ -12728,8 +12732,7 @@ public final class eu/vendeli/tgbot/types/passport/PassportData$Companion {

public abstract class eu/vendeli/tgbot/types/passport/PassportElementError {
public static final field Companion Leu/vendeli/tgbot/types/passport/PassportElementError$Companion;
public synthetic fun <init> (ILjava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public synthetic fun <init> (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ILkotlinx/serialization/internal/SerializationConstructorMarker;)V
public final fun getSource ()Ljava/lang/String;
public static final synthetic fun write$Self (Leu/vendeli/tgbot/types/passport/PassportElementError;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}
Expand Down
10 changes: 9 additions & 1 deletion telegram-bot/api/telegram-bot.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
// - Show declarations: true

// Library unique name: <eu.vendeli:telegram-bot>
open annotation class eu.vendeli.tgbot.annotations.dsl/ConfigurationDSL : kotlin/Annotation { // eu.vendeli.tgbot.annotations.dsl/ConfigurationDSL|null[0]
constructor <init>() // eu.vendeli.tgbot.annotations.dsl/ConfigurationDSL.<init>|<init>(){}[0]
}

open annotation class eu.vendeli.tgbot.annotations.dsl/FunctionalDSL : kotlin/Annotation { // eu.vendeli.tgbot.annotations.dsl/FunctionalDSL|null[0]
constructor <init>() // eu.vendeli.tgbot.annotations.dsl/FunctionalDSL.<init>|<init>(){}[0]
}

open annotation class eu.vendeli.tgbot.annotations.internal/ExperimentalFeature : kotlin/Annotation { // eu.vendeli.tgbot.annotations.internal/ExperimentalFeature|null[0]
constructor <init>() // eu.vendeli.tgbot.annotations.internal/ExperimentalFeature.<init>|<init>(){}[0]
}
Expand Down Expand Up @@ -1598,7 +1606,7 @@ final class eu.vendeli.tgbot.core/FunctionalHandlingDsl { // eu.vendeli.tgbot.co
final fun inputChain(kotlin/String, eu.vendeli.tgbot.types.internal.configuration/RateLimits = ..., eu.vendeli.tgbot.interfaces.helper/Guard = ..., kotlin.coroutines/SuspendFunction1<eu.vendeli.tgbot.types.internal/ActivityCtx<eu.vendeli.tgbot.types.internal/ProcessedUpdate>, kotlin/Unit>): eu.vendeli.tgbot.types.internal.chain/SingleInputChain // eu.vendeli.tgbot.core/FunctionalHandlingDsl.inputChain|inputChain(kotlin.String;eu.vendeli.tgbot.types.internal.configuration.RateLimits;eu.vendeli.tgbot.interfaces.helper.Guard;kotlin.coroutines.SuspendFunction1<eu.vendeli.tgbot.types.internal.ActivityCtx<eu.vendeli.tgbot.types.internal.ProcessedUpdate>,kotlin.Unit>){}[0]
final fun onCommand(kotlin/String, kotlin.collections/Set<eu.vendeli.tgbot.types.internal/UpdateType> = ..., eu.vendeli.tgbot.types.internal.configuration/RateLimits = ..., eu.vendeli.tgbot.interfaces.helper/Guard = ..., kotlin.reflect/KClass<out eu.vendeli.tgbot.interfaces.helper/ArgumentParser> = ..., kotlin.coroutines/SuspendFunction1<eu.vendeli.tgbot.types.internal/CommandContext<eu.vendeli.tgbot.types.internal/ProcessedUpdate>, kotlin/Unit>) // eu.vendeli.tgbot.core/FunctionalHandlingDsl.onCommand|onCommand(kotlin.String;kotlin.collections.Set<eu.vendeli.tgbot.types.internal.UpdateType>;eu.vendeli.tgbot.types.internal.configuration.RateLimits;eu.vendeli.tgbot.interfaces.helper.Guard;kotlin.reflect.KClass<out|eu.vendeli.tgbot.interfaces.helper.ArgumentParser>;kotlin.coroutines.SuspendFunction1<eu.vendeli.tgbot.types.internal.CommandContext<eu.vendeli.tgbot.types.internal.ProcessedUpdate>,kotlin.Unit>){}[0]
final fun onInput(kotlin/String, eu.vendeli.tgbot.types.internal.configuration/RateLimits = ..., eu.vendeli.tgbot.interfaces.helper/Guard = ..., kotlin.coroutines/SuspendFunction1<eu.vendeli.tgbot.types.internal/ActivityCtx<eu.vendeli.tgbot.types.internal/ProcessedUpdate>, kotlin/Unit>) // eu.vendeli.tgbot.core/FunctionalHandlingDsl.onInput|onInput(kotlin.String;eu.vendeli.tgbot.types.internal.configuration.RateLimits;eu.vendeli.tgbot.interfaces.helper.Guard;kotlin.coroutines.SuspendFunction1<eu.vendeli.tgbot.types.internal.ActivityCtx<eu.vendeli.tgbot.types.internal.ProcessedUpdate>,kotlin.Unit>){}[0]
final fun whenNotHandled(kotlin.coroutines/SuspendFunction1<eu.vendeli.tgbot.types.internal/ProcessedUpdate, kotlin/Unit>) // eu.vendeli.tgbot.core/FunctionalHandlingDsl.whenNotHandled|whenNotHandled(kotlin.coroutines.SuspendFunction1<eu.vendeli.tgbot.types.internal.ProcessedUpdate,kotlin.Unit>){}[0]
final fun whenNotHandled(kotlin.coroutines/SuspendFunction1<eu.vendeli.tgbot.types.internal/ActivityCtx<eu.vendeli.tgbot.types.internal/ProcessedUpdate>, kotlin/Unit>) // eu.vendeli.tgbot.core/FunctionalHandlingDsl.whenNotHandled|whenNotHandled(kotlin.coroutines.SuspendFunction1<eu.vendeli.tgbot.types.internal.ActivityCtx<eu.vendeli.tgbot.types.internal.ProcessedUpdate>,kotlin.Unit>){}[0]
}

final class eu.vendeli.tgbot.core/TgUpdateHandler { // eu.vendeli.tgbot.core/TgUpdateHandler|null[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import eu.vendeli.tgbot.types.internal.configuration.BotConfiguration
import eu.vendeli.tgbot.types.media.File
import eu.vendeli.tgbot.utils.BotConfigurator
import eu.vendeli.tgbot.utils.FunctionalHandlingBlock
import eu.vendeli.tgbot.utils.fqName
import eu.vendeli.tgbot.utils.getConfiguredHttpClient
import eu.vendeli.tgbot.utils.getLogger
import io.ktor.client.HttpClient
Expand Down Expand Up @@ -48,7 +49,7 @@ class TelegramBot(
}

internal val config = BotConfiguration().apply(botConfiguration)
internal val logger = getLogger(config.logging.botLogLevel, "eu.vendeli.TelegramBot")
internal val logger = getLogger(config.logging.botLogLevel, this::class.fqName)

internal val baseUrl by lazy { "${config.apiHost}/bot$token" + if (config.isTestEnv) "/test/" else "/" }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eu.vendeli.tgbot.annotations.dsl

@DslMarker
@Target(
AnnotationTarget.CLASS,
AnnotationTarget.FUNCTION,
AnnotationTarget.TYPE,
AnnotationTarget.VALUE_PARAMETER,
AnnotationTarget.TYPEALIAS,
)
annotation class ConfigurationDSL
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eu.vendeli.tgbot.annotations.dsl

@DslMarker
@Target(
AnnotationTarget.FUNCTION,
AnnotationTarget.CLASS,
AnnotationTarget.TYPE,
AnnotationTarget.VALUE_PARAMETER,
AnnotationTarget.TYPEALIAS,
)
annotation class FunctionalDSL
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import eu.vendeli.tgbot.types.passport.PassportElementError
import eu.vendeli.tgbot.utils.builders.ListingBuilder
import eu.vendeli.tgbot.utils.encodeWith
import eu.vendeli.tgbot.utils.getReturnType
import eu.vendeli.tgbot.utils.serde.DynamicLookupSerializer
import eu.vendeli.tgbot.utils.toJsonElement
import kotlinx.serialization.builtins.ListSerializer

Expand All @@ -23,7 +22,7 @@ class SetPassportDataErrorsAction(

init {
parameters["user_id"] = userId.toJsonElement()
parameters["errors"] = errors.encodeWith(ListSerializer(DynamicLookupSerializer))
parameters["errors"] = errors.encodeWith(ListSerializer(PassportElementError.serializer()))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.vendeli.tgbot.core

import eu.vendeli.tgbot.TelegramBot
import eu.vendeli.tgbot.annotations.dsl.FunctionalDSL
import eu.vendeli.tgbot.implementations.DefaultArgParser
import eu.vendeli.tgbot.implementations.DefaultFilter
import eu.vendeli.tgbot.implementations.DefaultGuard
Expand All @@ -20,6 +21,7 @@ import eu.vendeli.tgbot.utils.DEFAULT_SCOPE
import eu.vendeli.tgbot.utils.OnCommandActivity
import eu.vendeli.tgbot.utils.OnInputActivity
import eu.vendeli.tgbot.utils.WhenNotHandledActivity
import eu.vendeli.tgbot.utils.fqName
import eu.vendeli.tgbot.utils.getLogger
import kotlin.reflect.KClass

Expand All @@ -29,11 +31,12 @@ import kotlin.reflect.KClass
* @property bot
*/
@Suppress("unused", "MemberVisibilityCanBePrivate", "TooManyFunctions")
@FunctionalDSL
class FunctionalHandlingDsl internal constructor(
internal val bot: TelegramBot,
) {
internal val functionalActivities = FunctionalActivities()
internal val logger = getLogger(bot.config.logging.botLogLevel, "eu.vendeli.FunctionalHandler")
internal val logger = getLogger(bot.config.logging.botLogLevel, this::class.fqName)

/**
* The action that is performed when the command is matched.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import eu.vendeli.tgbot.utils.checkIsLimited
import eu.vendeli.tgbot.utils.coHandle
import eu.vendeli.tgbot.utils.debug
import eu.vendeli.tgbot.utils.error
import eu.vendeli.tgbot.utils.fqName
import eu.vendeli.tgbot.utils.getLogger
import eu.vendeli.tgbot.utils.getParameters
import eu.vendeli.tgbot.utils.handleFailure
Expand Down Expand Up @@ -60,7 +61,7 @@ class TgUpdateHandler internal constructor(
CoroutineScope(SupervisorJob() + dispatcher + CoroutineName("TgBot"))
}
internal val functionalHandlingBehavior by lazy { FunctionalHandlingDsl(bot) }
internal val logger = getLogger(bot.config.logging.botLogLevel, "eu.vendeli.core.TgUpdateHandler")
internal val logger = getLogger(bot.config.logging.botLogLevel, this::class.fqName)

/**
* The channel where errors caught during update processing is stored with update that caused them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ import kotlinx.serialization.json.JsonClassDiscriminator
@Serializable
@JsonClassDiscriminator("source")
@OptIn(ExperimentalSerializationApi::class)
sealed class ChatBoostSource(
val source: String,
) {
sealed class ChatBoostSource {
abstract val user: User?
val source: String by lazy {
serializer().descriptor.serialName
}

@Serializable
@SerialName("premium")
data class Premium(
override val user: User,
) : ChatBoostSource("premium")
) : ChatBoostSource()

@Serializable
@SerialName("gift_code")
data class GiftCode(
override val user: User,
) : ChatBoostSource("gift_code")
) : ChatBoostSource()

@Serializable
@SerialName("giveaway")
Expand All @@ -33,5 +34,5 @@ sealed class ChatBoostSource(
override val user: User? = null,
val isUnclaimed: Boolean? = null,
val prizeStarCount: Int? = null,
) : ChatBoostSource("giveaway")
) : ChatBoostSource()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import kotlinx.serialization.json.JsonClassDiscriminator
@Serializable
@OptIn(ExperimentalSerializationApi::class)
@JsonClassDiscriminator("status")
sealed class ChatMember(
val status: String,
) : MultipleResponse {
sealed class ChatMember : MultipleResponse {
abstract val user: User
val status: String by lazy {
serializer().descriptor.serialName
}

@Serializable
@SerialName("creator")
data class Owner(
override val user: User,
val isAnonymous: Boolean,
val customTitle: String? = null,
) : ChatMember("creator")
) : ChatMember()

@Serializable
@SerialName("administrator")
Expand All @@ -46,15 +47,15 @@ sealed class ChatMember(
val canEditStories: Boolean,
val canDeleteStories: Boolean,
val customTitle: String? = null,
) : ChatMember("administrator")
) : ChatMember()

@Serializable
@SerialName("member")
data class Member(
override val user: User,
@Serializable(InstantSerializer::class)
val untilDate: Instant? = null,
) : ChatMember("member")
) : ChatMember()

@Serializable
@SerialName("restricted")
Expand All @@ -77,19 +78,19 @@ sealed class ChatMember(
val canManageTopics: Boolean,
@Serializable(InstantSerializer::class)
val untilDate: Instant,
) : ChatMember("restricted")
) : ChatMember()

@Serializable
@SerialName("left")
data class Left(
override val user: User,
) : ChatMember("left")
) : ChatMember()

@Serializable
@SerialName("kicked")
data class Banned(
override val user: User,
@Serializable(InstantSerializer::class)
val untilDate: Instant,
) : ChatMember("kicked")
) : ChatMember()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package eu.vendeli.tgbot.types.internal

import eu.vendeli.tgbot.annotations.dsl.FunctionalDSL

@FunctionalDSL
data class ActivityCtx<out T : ProcessedUpdate>(
val update: T,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package eu.vendeli.tgbot.types.internal

import eu.vendeli.tgbot.annotations.dsl.FunctionalDSL

@FunctionalDSL
data class CommandContext<out T : ProcessedUpdate>(
val update: T,
val parameters: Map<String, String>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.vendeli.tgbot.types.internal.configuration

import eu.vendeli.tgbot.annotations.dsl.ConfigurationDSL
import eu.vendeli.tgbot.implementations.ClassManagerImpl
import eu.vendeli.tgbot.implementations.InputListenerMapImpl
import eu.vendeli.tgbot.interfaces.ctx.ClassManager
Expand All @@ -21,6 +22,7 @@ import kotlinx.serialization.Transient
* @property throwExOnActionsFailure Throw exception when the action (any bot request) ends with failure.
*/
@Serializable
@ConfigurationDSL
data class BotConfiguration(
var identifier: String = "KtGram",
var apiHost: String = "https://api.telegram.org",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.vendeli.tgbot.types.internal.configuration

import eu.vendeli.tgbot.annotations.dsl.ConfigurationDSL
import kotlinx.serialization.Serializable

/**
Expand All @@ -15,6 +16,7 @@ import kotlinx.serialization.Serializable
* By default, it's just omitted.
*/
@Serializable
@ConfigurationDSL
data class CommandParsingConfiguration(
var commandDelimiter: Char = '?',
var parametersDelimiter: Char = '&',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.vendeli.tgbot.types.internal.configuration

import eu.vendeli.tgbot.annotations.dsl.ConfigurationDSL
import eu.vendeli.tgbot.utils.RetryStrategy
import io.ktor.client.engine.ProxyConfig
import io.ktor.client.statement.HttpResponse
Expand All @@ -25,6 +26,7 @@ import kotlinx.serialization.Transient
* @property additionalHeaders Headers that will be applied to every request.
*/
@Serializable
@ConfigurationDSL
data class HttpConfiguration(
var requestTimeoutMillis: Long? = null,
var connectTimeoutMillis: Long? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.vendeli.tgbot.types.internal.configuration

import eu.vendeli.tgbot.annotations.dsl.ConfigurationDSL
import eu.vendeli.tgbot.types.internal.HttpLogLevel
import eu.vendeli.tgbot.types.internal.LogLvl
import kotlinx.serialization.Serializable
Expand All @@ -11,6 +12,7 @@ import kotlinx.serialization.Serializable
* @property httpLogLevel The level of http request logs.
*/
@Serializable
@ConfigurationDSL
data class LoggingConfiguration(
var botLogLevel: LogLvl = LogLvl.INFO,
var httpLogLevel: HttpLogLevel = HttpLogLevel.NONE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.vendeli.tgbot.types.internal.configuration

import eu.vendeli.tgbot.TelegramBot
import eu.vendeli.tgbot.annotations.dsl.ConfigurationDSL
import eu.vendeli.tgbot.api.message.message
import eu.vendeli.tgbot.implementations.TokenBucketLimiterImpl
import eu.vendeli.tgbot.interfaces.helper.RateLimitMechanism
Expand All @@ -13,6 +14,7 @@ import eu.vendeli.tgbot.interfaces.helper.RateLimitMechanism
* Default is [TokenBucket](https://en.wikipedia.org/wiki/Token_bucket) algorithm.
* @property exceededAction Action that will be applied when the limit is exceeded.
*/
@ConfigurationDSL
data class RateLimiterConfiguration(
var limits: RateLimits = RateLimits(),
var mechanism: RateLimitMechanism = TokenBucketLimiterImpl(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.vendeli.tgbot.types.internal.configuration

import eu.vendeli.tgbot.annotations.dsl.ConfigurationDSL
import eu.vendeli.tgbot.utils.PROCESSING_DISPATCHER
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
Expand All @@ -16,6 +17,7 @@ import kotlinx.serialization.Transient
* @property updatesPollingTimeout timeout option in getUpdates request for a long-polling mechanism.
*/
@Serializable
@ConfigurationDSL
data class UpdatesListenerConfiguration(
@Transient
var dispatcher: CoroutineDispatcher = Dispatchers.Default,
Expand Down
Loading

0 comments on commit 78f23c3

Please sign in to comment.