From 9177e01910299d412f75e08df24229273971d13e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Feb 2024 19:39:20 +0600 Subject: [PATCH 1/9] start 10.1.0 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 216a85bd5a..ff9c72e32e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 10.1.0 + ## 10.0.1 * `Version`: diff --git a/gradle.properties b/gradle.properties index 91874c618e..b634e5c5ef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=10.0.1 +library_version=10.1.0 From 468c54a30fe01f22ff0d8fbe3dd25fc6bfe5624d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Feb 2024 21:13:37 +0600 Subject: [PATCH 2/9] add support of ChatBoostAdded --- .../expectations/WaitEventAction.kt | 5 +++++ .../expectations/WaitEventActionMessages.kt | 5 +++++ .../triggers_handling/EventTriggers.kt | 21 +++++++++++++++++++ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 + .../message/ChatEvents/ChatBoostAdded.kt | 12 +++++++++++ .../inmo/tgbotapi/types/message/RawMessage.kt | 4 ++++ .../extensions/utils/ClassCastsNew.kt | 10 +++++++++ 7 files changed, 58 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ChatBoostAdded.kt diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt index 286e2f3c88..196dcbf149 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt @@ -214,3 +214,8 @@ suspend fun BehaviourContext.waitChatShared( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } ) = waitEvents(initRequest, errorFactory) + +suspend fun BehaviourContext.waitChatBoostAdded( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitEvents(initRequest, errorFactory) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt index 55d89bbc75..61246132b7 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt @@ -208,3 +208,8 @@ suspend fun BehaviourContext.waitChatSharedEventsMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } ) = waitEventsMessages(initRequest, errorFactory) + +suspend fun BehaviourContext.waitChatBoostAddedEventsMessages( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitEventsMessages(initRequest, errorFactory) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index 6fe38413da..55ff317b64 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -823,3 +823,24 @@ suspend fun BC.onChatShared( markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) + + + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BC.onChatBoostAdded( + initialFilter: SimpleFilter>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> +) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 44b0f6df67..9b1ef20df7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -656,6 +656,7 @@ const val menuButtonField = "menu_button" const val boostIdField = "boost_id" const val boostField = "boost" +const val boostCountField = "boost_count" const val addDateField = "add_date" const val expirationDateField = "expiration_date" const val removeDateField = "remove_date" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ChatBoostAdded.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ChatBoostAdded.kt new file mode 100644 index 0000000000..2153239057 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ChatBoostAdded.kt @@ -0,0 +1,12 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents + +import dev.inmo.tgbotapi.types.boostCountField +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ChatBoostAdded( + @SerialName(boostCountField) + val count: Int +) : PublicChatEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 0a8735da19..2b97286d0c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -117,6 +117,9 @@ internal data class RawMessage( private val general_forum_topic_unhidden: GeneralForumTopicUnhidden? = null, private val write_access_allowed: WriteAccessAllowed? = null, + // Boost added to groups + private val boost_added: ChatBoostAdded? = null, + // AutoDelete Message time changed private val message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged? = null, @@ -247,6 +250,7 @@ internal data class RawMessage( giveaway_created != null -> giveaway_created giveaway_winners is GiveawayPrivateResults -> giveaway_winners giveaway_completed != null -> giveaway_completed + boost_added != null -> boost_added else -> null } } diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt index e73520d8cd..428d4eb8d6 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt @@ -222,6 +222,7 @@ import dev.inmo.tgbotapi.types.media.TitledTelegramMedia import dev.inmo.tgbotapi.types.media.VisualMediaGroupMemberTelegramMedia import dev.inmo.tgbotapi.types.message.ChannelEventMessage import dev.inmo.tgbotapi.types.message.ChatEvents.ChannelChatCreated +import dev.inmo.tgbotapi.types.message.ChatEvents.ChatBoostAdded import dev.inmo.tgbotapi.types.message.ChatEvents.DeleteChatPhoto import dev.inmo.tgbotapi.types.message.ChatEvents.GroupChatCreated import dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMemberEvent @@ -2882,6 +2883,15 @@ public inline fun ChatEvent.channelChatCreatedOrThrow(): ChannelChatCreated = th public inline fun ChatEvent.ifChannelChatCreated(block: (ChannelChatCreated) -> T): T? = channelChatCreatedOrNull() ?.let(block) +public inline fun ChatEvent.chatBoostAddedOrNull(): ChatBoostAdded? = this as? + dev.inmo.tgbotapi.types.message.ChatEvents.ChatBoostAdded + +public inline fun ChatEvent.chatBoostAddedOrThrow(): ChatBoostAdded = this as + dev.inmo.tgbotapi.types.message.ChatEvents.ChatBoostAdded + +public inline fun ChatEvent.ifChatBoostAdded(block: (ChatBoostAdded) -> T): T? = + chatBoostAddedOrNull() ?.let(block) + public inline fun ChatEvent.deleteChatPhotoOrNull(): DeleteChatPhoto? = this as? dev.inmo.tgbotapi.types.message.ChatEvents.DeleteChatPhoto From a9a01e315496fa341dbd21d3a675b68e6ad1c7ae Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Feb 2024 21:38:28 +0600 Subject: [PATCH 3/9] add support of sender_boost_count --- .../inmo/tgbotapi/types/message/GroupMessages.kt | 8 ++++++-- .../dev/inmo/tgbotapi/types/message/RawMessage.kt | 10 +++++++--- .../types/message/abstracts/GroupMessages.kt | 8 ++++++-- .../extensions/MediaGroupContentMessageCreator.kt | 6 ++++-- .../inmo/tgbotapi/extensions/utils/ClassCastsNew.kt | 13 +++++++++++++ 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt index c9d42f2bf6..de7930b18a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt @@ -123,6 +123,7 @@ data class CommonGroupContentMessageImpl( override val content: T, override val senderBot: CommonBot?, override val mediaGroupId: MediaGroupIdentifier?, + override val senderBoostsCount: Int? ) : CommonGroupContentMessage { constructor( chat: PreviewGroupChat, @@ -137,8 +138,9 @@ data class CommonGroupContentMessageImpl( content: T, senderBot: CommonBot?, mediaGroupId: MediaGroupIdentifier?, + senderBoostsCount: Int?, ) : this( - chat, messageId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId + chat, messageId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId, senderBoostsCount ) } @@ -226,6 +228,7 @@ data class CommonForumContentMessageImpl( override val content: T, override val senderBot: CommonBot?, override val mediaGroupId: MediaGroupIdentifier?, + override val senderBoostsCount: Int?, ) : CommonForumContentMessage { constructor( chat: PreviewForumChat, @@ -241,7 +244,8 @@ data class CommonForumContentMessageImpl( content: T, senderBot: CommonBot?, mediaGroupId: MediaGroupIdentifier?, + senderBoostsCount: Int?, ) : this( - chat, messageId, threadId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId + chat, messageId, threadId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId, senderBoostsCount ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 2b97286d0c..4436bd9827 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -98,6 +98,7 @@ internal data class RawMessage( private val successful_payment: SuccessfulPayment? = null, private val giveaway: Giveaway? = null, private val giveaway_winners: GiveawayResults? = null, + private val sender_boost_count: Int? = null, private val users_shared: UsersShared? = null, private val chat_shared: ChatShared? = null, @@ -371,7 +372,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - media_group_id + media_group_id, + sender_boost_count ) } } else { @@ -435,7 +437,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - media_group_id + media_group_id, + sender_boost_count ) } } @@ -499,7 +502,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - media_group_id + media_group_id, + sender_boost_count ) } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt index 0ea78e8887..4f7f00be72 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt @@ -8,6 +8,10 @@ sealed interface GroupContentMessage : PublicContentMessage< override val chat: PreviewGroupChat } +sealed interface PotentiallyFromUserGroupContentMessage : GroupContentMessage { + val senderBoostsCount: Int? +} + sealed interface ForumContentMessage : GroupContentMessage, PossiblyTopicMessage { override val chat: PreviewForumChat override val threadId: MessageThreadId @@ -28,7 +32,7 @@ interface AnonymousGroupContentMessage : GroupContentMessage get() = chat } -interface CommonGroupContentMessage : GroupContentMessage, FromUserMessage +interface CommonGroupContentMessage : GroupContentMessage, PotentiallyFromUserGroupContentMessage, FromUserMessage interface FromChannelForumContentMessage : FromChannelGroupContentMessage, ForumContentMessage @@ -37,4 +41,4 @@ interface AnonymousForumContentMessage : ForumContentMessage get() = chat } -interface CommonForumContentMessage : ForumContentMessage, FromUserMessage +interface CommonForumContentMessage : ForumContentMessage, PotentiallyFromUserGroupContentMessage, FromUserMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt index f8764c212f..a81465abeb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt @@ -86,7 +86,8 @@ fun List>.asMedia sourceMessage.replyMarkup, content, sourceMessage.senderBot, - sourceMessage.mediaGroupId + sourceMessage.mediaGroupId, + sourceMessage.senderBoostsCount ) is ConnectedFromChannelGroupContentMessage -> ConnectedFromChannelGroupContentMessageImpl( sourceMessage.chat, @@ -146,7 +147,8 @@ fun List>.asMedia sourceMessage.replyMarkup, content, sourceMessage.senderBot, - sourceMessage.mediaGroupId + sourceMessage.mediaGroupId, + sourceMessage.senderBoostsCount ) is FromChannelForumContentMessage -> FromChannelForumContentMessageImpl( sourceMessage.chat, diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt index 428d4eb8d6..7ad2015604 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt @@ -285,6 +285,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaymentMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage +import dev.inmo.tgbotapi.types.message.abstracts.PotentiallyFromUserGroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage import dev.inmo.tgbotapi.types.message.abstracts.PublicContentMessage import dev.inmo.tgbotapi.types.message.abstracts.SignedMessage @@ -3397,6 +3398,18 @@ public inline fun Message.ifGroupContentMessage(block: (GroupContentMessage) -> T): T? = groupContentMessageOrNull() ?.let(block) +public inline fun Message.potentiallyFromUserGroupContentMessageOrNull(): + PotentiallyFromUserGroupContentMessage? = this as? + dev.inmo.tgbotapi.types.message.abstracts.PotentiallyFromUserGroupContentMessage + +public inline fun Message.potentiallyFromUserGroupContentMessageOrThrow(): + PotentiallyFromUserGroupContentMessage = this as + dev.inmo.tgbotapi.types.message.abstracts.PotentiallyFromUserGroupContentMessage + +public inline fun + Message.ifPotentiallyFromUserGroupContentMessage(block: (PotentiallyFromUserGroupContentMessage) -> T): + T? = potentiallyFromUserGroupContentMessageOrNull() ?.let(block) + public inline fun Message.forumContentMessageOrNull(): ForumContentMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.ForumContentMessage From a01ca438378547c9dd831ab7a87663bbf335e0b8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Feb 2024 21:54:13 +0600 Subject: [PATCH 4/9] add support of Story content and reply_to_story field --- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 5 +++++ .../kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt | 9 ++++++++- .../dev/inmo/tgbotapi/types/message/RawMessage.kt | 2 ++ .../kotlin/dev/inmo/tgbotapi/types/stories/Story.kt | 12 +++++++++++- .../inmo/tgbotapi/extensions/utils/ClassCastsNew.kt | 9 +++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 9b1ef20df7..788dd7401c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -45,6 +45,11 @@ value class CustomEmojiId( val appLink get() = "${internalTgAppLinksBeginning}emoji?id=$this" } +@Serializable +@JvmInline +value class StoryId( + val long: Long +) typealias Seconds = Int typealias MilliSeconds = Long diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt index 419a3bba83..445749a753 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt @@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults import dev.inmo.tgbotapi.types.giveaway.Giveaway import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.message.MessageOrigin -import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.payments.Invoice import dev.inmo.tgbotapi.types.polls.Poll @@ -34,6 +33,14 @@ sealed interface ReplyInfo { get() = message.metaInfo } + @Serializable + data class ToStory( + val story: Story + ): ReplyInfo { + override val messageMeta: Message.MetaInfo? + get() = null + } + @Serializable(External.Companion::class) sealed interface External : ReplyInfo { val origin: MessageOrigin diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 4436bd9827..86aa9e29cb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -54,6 +54,7 @@ internal data class RawMessage( private val is_topic_message: Boolean? = null, private val is_automatic_forward: Boolean? = null, private val reply_to_message: RawMessage? = null, + private val reply_to_story: Story? = null, private val external_reply: ReplyInfo.External? = null, private val quote: TextQuote? = null, private val via_bot: CommonBot? = null, @@ -300,6 +301,7 @@ internal data class RawMessage( reply_to_message != null -> ReplyInfo.Internal( reply_to_message.asMessage ) + reply_to_story != null -> ReplyInfo.ToStory(reply_to_story) external_reply != null -> external_reply else -> null } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt index 35154fd101..e6c71e9f5c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt @@ -1,7 +1,17 @@ package dev.inmo.tgbotapi.types.stories import dev.inmo.tgbotapi.types.ReplyInfo +import dev.inmo.tgbotapi.types.StoryId +import dev.inmo.tgbotapi.types.chat.PreviewChat +import dev.inmo.tgbotapi.types.chatField +import dev.inmo.tgbotapi.types.idField +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -class Story : ReplyInfo.External.ContentVariant +class Story( + @SerialName(idField) + val id: StoryId, + @SerialName(chatField) + val chat: PreviewChat +) : ReplyInfo.External.ContentVariant diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt index 7ad2015604..7db7709e5b 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt @@ -1631,6 +1631,15 @@ public inline fun ReplyInfo.internalOrThrow(): ReplyInfo.Internal = this as public inline fun ReplyInfo.ifInternal(block: (ReplyInfo.Internal) -> T): T? = internalOrNull() ?.let(block) +public inline fun ReplyInfo.toStoryOrNull(): ReplyInfo.ToStory? = this as? + dev.inmo.tgbotapi.types.ReplyInfo.ToStory + +public inline fun ReplyInfo.toStoryOrThrow(): ReplyInfo.ToStory = this as + dev.inmo.tgbotapi.types.ReplyInfo.ToStory + +public inline fun ReplyInfo.ifToStory(block: (ReplyInfo.ToStory) -> T): T? = toStoryOrNull() + ?.let(block) + public inline fun BotAction.typingActionOrNull(): TypingAction? = this as? dev.inmo.tgbotapi.types.actions.TypingAction From 4908bb2cfee1b28b551197c7c916b921a8d8292c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Feb 2024 21:57:03 +0600 Subject: [PATCH 5/9] add support of unrestrict_boost_count --- .../src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 + .../kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt | 4 ++++ .../kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt | 1 + 3 files changed, 6 insertions(+) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 788dd7401c..077e5ceb53 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -251,6 +251,7 @@ const val profileAccentColorIdField = "profile_accent_color_id" const val backgroundCustomEmojiIdField = "background_custom_emoji_id" const val profileBackgroundCustomEmojiIdField = "profile_background_custom_emoji_id" const val hasVisibleHistoryField = "has_visible_history" +const val unrestrictBoostsCountField = "unrestrict_boost_count" const val iconCustomEmojiIdField = "icon_custom_emoji_id" const val canJoinGroupsField = "can_join_groups" const val canReadAllGroupMessagesField = "can_read_all_group_messages" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt index 0041828a48..cb4a28ea5a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt @@ -184,6 +184,8 @@ data class ExtendedSupergroupChatImpl( override val profileBackgroundCustomEmojiId: CustomEmojiId? = null, @SerialName(hasVisibleHistoryField) override val newMembersSeeHistory: Boolean = false, + @SerialName(unrestrictBoostsCountField) + override val unrestrictBoostsCount: Int? = null ) : ExtendedSupergroupChat @Serializable @@ -242,6 +244,8 @@ data class ExtendedForumChatImpl( override val profileBackgroundCustomEmojiId: CustomEmojiId? = null, @SerialName(hasVisibleHistoryField) override val newMembersSeeHistory: Boolean = false, + @SerialName(unrestrictBoostsCountField) + override val unrestrictBoostsCount: Int? = null, ) : ExtendedForumChat @Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt index b3887e7579..8261df7435 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt @@ -59,6 +59,7 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat, Ext val stickerSetName: StickerSetName? val canSetStickerSet: Boolean val linkedChannelChatId: IdChatIdentifier? + val unrestrictBoostsCount: Int? val location: ChatLocation? /** From 5c13047a0b5b940e8a6daec238c738e6c4936efe Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Feb 2024 21:59:10 +0600 Subject: [PATCH 6/9] add support of custom_emoji_sticker_set_name --- .../src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 + .../kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt | 6 +++++- .../dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 077e5ceb53..601b755768 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -252,6 +252,7 @@ const val backgroundCustomEmojiIdField = "background_custom_emoji_id" const val profileBackgroundCustomEmojiIdField = "profile_background_custom_emoji_id" const val hasVisibleHistoryField = "has_visible_history" const val unrestrictBoostsCountField = "unrestrict_boost_count" +const val customEmojiStickerSetNameField = "custom_emoji_sticker_set_name" const val iconCustomEmojiIdField = "icon_custom_emoji_id" const val canJoinGroupsField = "can_join_groups" const val canReadAllGroupMessagesField = "can_read_all_group_messages" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt index cb4a28ea5a..c8af805302 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt @@ -185,7 +185,9 @@ data class ExtendedSupergroupChatImpl( @SerialName(hasVisibleHistoryField) override val newMembersSeeHistory: Boolean = false, @SerialName(unrestrictBoostsCountField) - override val unrestrictBoostsCount: Int? = null + override val unrestrictBoostsCount: Int? = null, + @SerialName(customEmojiStickerSetNameField) + override val customEmojiStickerSetName: StickerSetName? = null, ) : ExtendedSupergroupChat @Serializable @@ -246,6 +248,8 @@ data class ExtendedForumChatImpl( override val newMembersSeeHistory: Boolean = false, @SerialName(unrestrictBoostsCountField) override val unrestrictBoostsCount: Int? = null, + @SerialName(customEmojiStickerSetNameField) + override val customEmojiStickerSetName: StickerSetName? = null, ) : ExtendedForumChat @Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt index 8261df7435..bdb3e4c2f9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt @@ -61,6 +61,7 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat, Ext val linkedChannelChatId: IdChatIdentifier? val unrestrictBoostsCount: Int? val location: ChatLocation? + val customEmojiStickerSetName: StickerSetName? /** * This field represents field "join_to_send_messages" from API From 6571e8f592c628fdc202889ef226e9d06d1d0977 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Feb 2024 23:29:29 +0600 Subject: [PATCH 7/9] update dependencies --- CHANGELOG.md | 4 ++++ gradle/libs.versions.toml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff9c72e32e..4faf111f33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 10.1.0 +* `Version`: + * `Coroutines`: `1.7.3` -> `1.8.0` + * `MicroUtils`: `0.20.32` -> `0.20.34` + ## 10.0.1 * `Version`: diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fc5b4460e7..8e3312cedd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ kotlin = "1.9.22" kotlin-serialization = "1.6.2" -kotlin-coroutines = "1.7.3" +kotlin-coroutines = "1.8.0" javax-activation = "1.1.1" @@ -13,7 +13,7 @@ ktor = "2.3.8" ksp = "1.9.22-1.0.17" kotlin-poet = "1.16.0" -microutils = "0.20.32" +microutils = "0.20.34" kslog = "1.3.2" versions = "0.51.0" From 3da4ee48087caefa97a285fd76cf2792b4ccbe28 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 17 Feb 2024 01:46:26 +0600 Subject: [PATCH 8/9] make Story to be data class --- .../commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt index e6c71e9f5c..68ab2a34d8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt @@ -9,7 +9,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -class Story( +data class Story( @SerialName(idField) val id: StoryId, @SerialName(chatField) From b9bc40187f3a1ccdfc1ed0840b719e05ed5c1399 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 17 Feb 2024 01:53:00 +0600 Subject: [PATCH 9/9] fixes in changelog and readme --- CHANGELOG.md | 2 ++ README.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4faf111f33..0a36957944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 10.1.0 +**Add support of [Telegram Bots API 7.1](https://core.telegram.org/bots/api-changelog#february-16-2024)** + * `Version`: * `Coroutines`: `1.7.3` -> `1.8.0` * `MicroUtils`: `0.20.32` -> `0.20.34` diff --git a/README.md b/README.md index bf5b95739d..734d3b1bac 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-7.0-blue)](https://core.telegram.org/bots/api-changelog#december-29-2023) +# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-7.1-blue)](https://core.telegram.org/bots/api-changelog#february-16-2024) | Docs | [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Mk&message=Docs&color=blue&logo=mkdocs)](https://docs.inmo.dev/tgbotapi/index.html) | |:----------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|