1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-12-29 09:29:23 +00:00

Compare commits

...

8 Commits

41 changed files with 992 additions and 49 deletions

View File

@@ -0,0 +1,19 @@
package dev.inmo.tgbotapi.extensions.api.get
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.get.GetUserChatBoosts
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.chat.Chat
suspend fun TelegramBot.getUserChatBoosts(
chatId: ChatIdentifier,
userId: UserId
) = execute(
GetUserChatBoosts(chatId = chatId, userId = userId)
)
suspend fun TelegramBot.getUserChatBoosts(
chat: Chat,
userId: UserId
) = getUserChatBoosts(chatId = chat.id, userId = userId)

View File

@@ -0,0 +1,17 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.utils.chatBoostRemovedUpdateOrNull
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.boosts.ChatBoostRemoved
import kotlinx.coroutines.flow.Flow
suspend fun BehaviourContext.waitChatBoostRemoved(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
): Flow<ChatBoostRemoved> = expectFlow(
initRequest,
errorFactory
) {
it.chatBoostRemovedUpdateOrNull() ?.data.let(::listOfNotNull)
}

View File

@@ -0,0 +1,17 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.utils.chatBoostUpdatedUpdateOrNull
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.boosts.ChatBoostUpdated
import kotlinx.coroutines.flow.Flow
suspend fun BehaviourContext.waitChatBoostUpdated(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
): Flow<ChatBoostUpdated> = expectFlow(
initRequest,
errorFactory
) {
it.chatBoostUpdatedUpdateOrNull() ?.data.let(::listOfNotNull)
}

View File

@@ -55,7 +55,7 @@ suspend fun <BC : BehaviourContext> BC.onUnhandledInlineMessageIdDataCallbackQue
markerFactory: MarkerFactory<in InlineMessageIdDataCallbackQuery, Any> = ByUserCallbackQueryMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, InlineMessageIdDataCallbackQuery>
) = onCallbackQuery (
initialFilter * !SimpleFilter<MessageDataCallbackQuery> { triggersHolder.handleableCallbackQueriesDataHolder.isHandled(it) },
initialFilter * !SimpleFilter<InlineMessageIdDataCallbackQuery> { triggersHolder.handleableCallbackQueriesDataHolder.isHandled(it) },
subcontextUpdatesFilter,
markerFactory,
scenarioReceiver

View File

@@ -0,0 +1,34 @@
@file:Suppress("unused")
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.behaviour_builder.CustomBehaviourContextAndTwoTypesReceiver
import dev.inmo.tgbotapi.extensions.behaviour_builder.CustomBehaviourContextAndTypeReceiver
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByIdChatBoostRemovedMarkerFactory
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
import dev.inmo.tgbotapi.extensions.utils.chatBoostRemovedUpdateOrNull
import dev.inmo.tgbotapi.types.boosts.ChatBoostRemoved
import dev.inmo.tgbotapi.types.update.abstracts.Update
/**
* @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 : BehaviourContext> BC.onChatBoostRemoved(
initialFilter: SimpleFilter<ChatBoostRemoved>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatBoostRemoved, Update>? = null,
markerFactory: MarkerFactory<ChatBoostRemoved, Any> = ByIdChatBoostRemovedMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatBoostRemoved>
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
(it.chatBoostRemovedUpdateOrNull() ?.data) ?.let(::listOfNotNull)
}

View File

@@ -0,0 +1,34 @@
@file:Suppress("unused")
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.behaviour_builder.CustomBehaviourContextAndTwoTypesReceiver
import dev.inmo.tgbotapi.extensions.behaviour_builder.CustomBehaviourContextAndTypeReceiver
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByIdChatBoostUpdatedMarkerFactory
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
import dev.inmo.tgbotapi.extensions.utils.chatBoostUpdatedUpdateOrNull
import dev.inmo.tgbotapi.types.boosts.ChatBoostUpdated
import dev.inmo.tgbotapi.types.update.abstracts.Update
/**
* @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 : BehaviourContext> BC.onChatBoostUpdated(
initialFilter: SimpleFilter<ChatBoostUpdated>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatBoostUpdated, Update>? = null,
markerFactory: MarkerFactory<ChatBoostUpdated, Any> = ByIdChatBoostUpdatedMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatBoostUpdated>
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
(it.chatBoostUpdatedUpdateOrNull() ?.data) ?.let(::listOfNotNull)
}

View File

@@ -0,0 +1,9 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
import dev.inmo.tgbotapi.types.boosts.ChatBoostRemoved
import dev.inmo.tgbotapi.types.boosts.ChatBoostUpdated
import dev.inmo.tgbotapi.types.polls.PollAnswer
object ByIdChatBoostRemovedMarkerFactory : MarkerFactory<ChatBoostRemoved, Any> {
override suspend fun invoke(data: ChatBoostRemoved) = data.chat.id
}

View File

@@ -0,0 +1,8 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
import dev.inmo.tgbotapi.types.boosts.ChatBoostUpdated
import dev.inmo.tgbotapi.types.polls.PollAnswer
object ByIdChatBoostUpdatedMarkerFactory : MarkerFactory<ChatBoostUpdated, Any> {
override suspend fun invoke(data: ChatBoostUpdated) = data.chat.id
}

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.abstracts
import dev.inmo.tgbotapi.types.MessageId
/**
* All inheritors of this interface have [messageId] field and related to this [messageId]
*/
interface WithMessageId {
val messageId: MessageId
}

View File

@@ -0,0 +1,3 @@
package dev.inmo.tgbotapi.abstracts
interface WithPreviewChatAndMessageId : WithPreviewChat, WithMessageId

View File

@@ -1,7 +1,5 @@
package dev.inmo.tgbotapi.abstracts.types
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.abstracts.WithMessageId
interface MessageAction: ChatRequest {
val messageId: MessageId
}
interface MessageAction : ChatRequest, WithMessageId

View File

@@ -0,0 +1,24 @@
package dev.inmo.tgbotapi.requests.get
import dev.inmo.tgbotapi.abstracts.types.ChatRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.boosts.UserChatBoosts
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationStrategy
@Serializable
data class GetUserChatBoosts(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(userIdField)
val userId: UserId
) : SimpleRequest<UserChatBoosts>, ChatRequest {
override fun method(): String = "getUserChatBoosts"
override val resultDeserializer: DeserializationStrategy<UserChatBoosts>
get() = UserChatBoosts.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -202,6 +202,7 @@ const val tgWebAppStartParamField = "tgWebAppStartParam"
const val chatIdField = "chat_id"
const val senderChatIdField = "sender_chat_id"
const val messageIdField = "message_id"
const val giveawayMessageIdField = "giveaway_message_id"
const val messageIdsField = "message_ids"
const val actorChatField = "actor_chat"
const val messageThreadIdField = "message_thread_id"
@@ -481,6 +482,7 @@ const val isBigField = "is_big"
const val oldReactionField = "old_reaction"
const val newReactionField = "new_reaction"
const val chatField = "chat"
const val chatsField = "chats"
const val usernameField = "username"
const val bioField = "bio"
const val nameField = "name"
@@ -543,6 +545,7 @@ const val shippingQueryIdField = "shipping_query_id"
const val preCheckoutQueryIdField = "pre_checkout_query_id"
const val shippingOptionsField = "shipping_options"
const val countryCodeField = "country_code"
const val countryCodesField = "country_codes"
const val totalCountField = "total_count"
const val stateField = "state"
const val cityField = "city"
@@ -609,6 +612,7 @@ const val secretField = "secret"
const val errorsField = "errors"
const val sourceField = "source"
const val isUnclaimedField = "is_unclaimed"
const val fieldNameField = "field_name"
const val dataHashField = "data_hash"
const val fileHashField = "file_hash"
@@ -634,3 +638,20 @@ const val buttonTextField = "button_text"
const val webAppField = "web_app"
const val webAppNameField = "web_app_name"
const val menuButtonField = "menu_button"
const val boostIdField = "boost_id"
const val boostField = "boost"
const val addDateField = "add_date"
const val expirationDateField = "expiration_date"
const val removeDateField = "remove_date"
const val boostsField = "boosts"
const val winnersSelectionDateField = "winners_selection_date"
const val winnersCountField = "winner_count"
const val onlyNewMembersField = "only_new_members"
const val hasPublicWinnersField = "has_public_winners"
const val prizeDescriptionField = "prize_description"
const val premiumSubscriptionMonthCountField = "premium_subscription_month_count"
const val winnersField = "winners"
const val additionalChatCountField = "additional_chat_count"
const val unclaimedPrizeCountField = "unclaimed_prize_count"
const val wasRefundedField = "was_refunded"

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.types.boosts
import kotlinx.serialization.Serializable
import kotlin.jvm.JvmInline
@Serializable
@JvmInline
value class BoostId(
val string: String
)

View File

@@ -0,0 +1,17 @@
package dev.inmo.tgbotapi.types.boosts
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ChatBoost(
@SerialName(boostIdField)
val id: BoostId,
@SerialName(addDateField)
val addDate: TelegramDate,
@SerialName(expirationDateField)
val expirationDate: TelegramDate,
@SerialName(sourceField)
val source: ChatBoostSource
)

View File

@@ -0,0 +1,19 @@
package dev.inmo.tgbotapi.types.boosts
import dev.inmo.tgbotapi.abstracts.WithPreviewChat
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.PreviewChat
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ChatBoostRemoved(
@SerialName(chatField)
override val chat: PreviewChat,
@SerialName(boostIdField)
val boostId: BoostId,
@SerialName(removeDateField)
val removeDate: TelegramDate,
@SerialName(sourceField)
val source: ChatBoostSource
) : WithPreviewChat

View File

@@ -0,0 +1,171 @@
package dev.inmo.tgbotapi.types.boosts
import dev.inmo.tgbotapi.abstracts.WithMessageId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.PreviewUser
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Required
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.JsonDecoder
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.decodeFromJsonElement
@Serializable(ChatBoostSource.Companion::class)
@ClassCastsIncluded
sealed interface ChatBoostSource {
val sourceName: String
val user: PreviewUser?
sealed interface ByUser : ChatBoostSource {
override val user: PreviewUser
}
@Serializable(ChatBoostSource.Companion::class)
data class Premium(
@SerialName(userField)
override val user: PreviewUser
) : ByUser {
@Required
@SerialName(sourceField)
override val sourceName: String = sourceCode
companion object {
const val sourceCode = "premium"
}
}
@Serializable(ChatBoostSource.Companion::class)
data class GiftCode(
@SerialName(userField)
override val user: PreviewUser
) : ByUser {
@Required
@SerialName(sourceField)
override val sourceName: String = sourceCode
companion object {
const val sourceCode = "gift_code"
}
}
@Serializable(ChatBoostSource.Companion::class)
sealed interface Giveaway : ChatBoostSource, WithMessageId {
val unclaimed: Boolean
val claimed: Boolean
get() = !unclaimed
@Serializable(ChatBoostSource.Companion::class)
data class Claimed(
@SerialName(giveawayMessageIdField)
override val messageId: MessageId,
@SerialName(userField)
override val user: PreviewUser
) : Giveaway, ByUser {
@Required
@SerialName(sourceField)
override val sourceName: String = Giveaway.sourceCode
@Required
@SerialName(isUnclaimedField)
override val unclaimed: Boolean = false
}
@Serializable(ChatBoostSource.Companion::class)
data class Unclaimed(
@SerialName(giveawayMessageIdField)
override val messageId: MessageId
) : Giveaway {
@Required
@SerialName(sourceField)
override val sourceName: String = Giveaway.sourceCode
@Required
@SerialName(isUnclaimedField)
override val unclaimed: Boolean = true
@SerialName(userField)
override val user: PreviewUser? = null
}
companion object {
val sourceCode = "giveaway"
}
}
@Serializable(ChatBoostSource.Companion::class)
data class Unknown(
override val sourceName: String,
override val user: PreviewUser?,
val json: JsonElement?
) : ChatBoostSource
@Serializable
private data class Surrogate(
@Required
@SerialName(sourceField)
val sourceName: String,
@SerialName(userField)
val user: PreviewUser? = null,
@SerialName(giveawayMessageIdField)
val messageId: MessageId? = null,
@SerialName(isUnclaimedField)
val unclaimed: Boolean? = null
)
companion object : KSerializer<ChatBoostSource> {
override val descriptor: SerialDescriptor
get() = Surrogate.serializer().descriptor
override fun deserialize(decoder: Decoder): ChatBoostSource {
val (surrogate, json) = when {
decoder is JsonDecoder -> {
val json = decoder.decodeJsonElement()
val surrogate = decoder.json.decodeFromJsonElement(Surrogate.serializer(), json)
surrogate to json
}
else -> Surrogate.serializer().deserialize(decoder) to null
}
return when {
surrogate.sourceName == Premium.sourceCode && surrogate.user != null -> {
Premium(surrogate.user)
}
surrogate.sourceName == GiftCode.sourceCode && surrogate.user != null -> {
GiftCode(surrogate.user)
}
surrogate.sourceName == Giveaway.sourceCode && surrogate.messageId != null -> {
when {
surrogate.user != null && surrogate.unclaimed == false -> Giveaway.Claimed(
surrogate.messageId,
surrogate.user
)
surrogate.unclaimed == true -> Giveaway.Unclaimed(
surrogate.messageId
)
else -> null
}
}
else -> null
} ?: Unknown(surrogate.sourceName, surrogate.user, json)
}
override fun serialize(encoder: Encoder, value: ChatBoostSource) {
if (value is Unknown && value.json != null) {
JsonElement.serializer().serialize(encoder, value.json)
return
}
val surrogate = Surrogate(
value.sourceName,
value.user,
(value as? Giveaway) ?.messageId,
(value as? Giveaway) ?.unclaimed,
)
Surrogate.serializer().serialize(encoder, surrogate)
}
}
}

View File

@@ -0,0 +1,16 @@
package dev.inmo.tgbotapi.types.boosts
import dev.inmo.tgbotapi.abstracts.WithPreviewChat
import dev.inmo.tgbotapi.types.boostField
import dev.inmo.tgbotapi.types.chat.PreviewChat
import dev.inmo.tgbotapi.types.chatField
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ChatBoostUpdated(
@SerialName(chatField)
override val chat: PreviewChat,
@SerialName(boostField)
val boost: ChatBoost
) : WithPreviewChat

View File

@@ -0,0 +1,11 @@
package dev.inmo.tgbotapi.types.boosts
import dev.inmo.tgbotapi.types.boostsField
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class UserChatBoosts(
@SerialName(boostsField)
val boosts: List<ChatBoost>
)

View File

@@ -1,5 +1,7 @@
package dev.inmo.tgbotapi.types.chat
import dev.inmo.tgbotapi.abstracts.WithPreviewChat
import dev.inmo.tgbotapi.abstracts.WithPreviewChatAndMessageId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.reactions.Reaction
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
@@ -14,9 +16,7 @@ import kotlinx.serialization.json.JsonElement
@Serializable(ChatMessageReactionUpdated.Companion::class)
@ClassCastsIncluded
sealed interface ChatMessageReactionUpdated {
val chat: PreviewChat
val messageId: MessageIdentifier
sealed interface ChatMessageReactionUpdated : WithPreviewChatAndMessageId {
val reactedUser: PreviewUser?
val reactedChat: PreviewChat?
val date: TelegramDate

View File

@@ -1,5 +1,7 @@
package dev.inmo.tgbotapi.types.chat
import dev.inmo.tgbotapi.abstracts.WithPreviewChat
import dev.inmo.tgbotapi.abstracts.WithPreviewChatAndMessageId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.reactions.ReactionsCount
import kotlinx.serialization.SerialName
@@ -8,12 +10,12 @@ import kotlinx.serialization.Serializable
@Serializable
data class ChatMessageReactionsCountUpdated(
@SerialName(chatField)
val chat: PreviewChat,
override val chat: PreviewChat,
@SerialName(messageIdField)
val messageId: MessageIdentifier,
override val messageId: MessageIdentifier,
@Serializable(TelegramDateSerializer::class)
@SerialName(dateField)
val date: TelegramDate,
@SerialName(reactionsField)
val reactions: List<ReactionsCount>
)
) : WithPreviewChatAndMessageId

View File

@@ -35,7 +35,11 @@ data class ExtendedChannelChatImpl(
@SerialName(hasHiddenMembersField)
override val membersHidden: Boolean = false,
@SerialName(availableReactionsField)
override val availableReactions: List<Reaction>? = null
override val availableReactions: List<Reaction>? = null,
@SerialName(emojiStatusCustomEmojiIdField)
override val statusEmojiId: CustomEmojiId? = null,
@SerialName(emojiStatusExpirationDateField)
override val statusEmojiExpiration: TelegramDate? = null
) : ExtendedChannelChat
@Serializable
@@ -59,7 +63,11 @@ data class ExtendedGroupChatImpl(
@SerialName(hasHiddenMembersField)
override val membersHidden: Boolean = false,
@SerialName(availableReactionsField)
override val availableReactions: List<Reaction>? = null
override val availableReactions: List<Reaction>? = null,
@SerialName(emojiStatusCustomEmojiIdField)
override val statusEmojiId: CustomEmojiId? = null,
@SerialName(emojiStatusExpirationDateField)
override val statusEmojiExpiration: TelegramDate? = null
) : ExtendedGroupChat
@Serializable
@@ -132,7 +140,11 @@ data class ExtendedSupergroupChatImpl(
@SerialName(hasHiddenMembersField)
override val membersHidden: Boolean = false,
@SerialName(availableReactionsField)
override val availableReactions: List<Reaction>? = null
override val availableReactions: List<Reaction>? = null,
@SerialName(emojiStatusCustomEmojiIdField)
override val statusEmojiId: CustomEmojiId? = null,
@SerialName(emojiStatusExpirationDateField)
override val statusEmojiExpiration: TelegramDate? = null
) : ExtendedSupergroupChat
@Serializable
@@ -176,7 +188,11 @@ data class ExtendedForumChatImpl(
@SerialName(hasHiddenMembersField)
override val membersHidden: Boolean = false,
@SerialName(availableReactionsField)
override val availableReactions: List<Reaction>? = null
override val availableReactions: List<Reaction>? = null,
@SerialName(emojiStatusCustomEmojiIdField)
override val statusEmojiId: CustomEmojiId? = null,
@SerialName(emojiStatusExpirationDateField)
override val statusEmojiExpiration: TelegramDate? = null
) : ExtendedForumChat
@Serializable

View File

@@ -7,6 +7,17 @@ import dev.inmo.tgbotapi.types.reactions.Reaction
import korlibs.time.DateTime
import kotlinx.serialization.Serializable
@Serializable(ExtendedChatSerializer.Companion::class)
sealed interface ExtendedChat : Chat {
val chatPhoto: ChatPhoto?
}
@Serializable(ExtendedChatSerializer.Companion::class)
sealed interface ExtendedNonBotChat : ExtendedChat {
val statusEmojiId: CustomEmojiId?
val statusEmojiExpiration: TelegramDate?
}
@Serializable(ExtendedChatSerializer.Companion::class)
sealed interface ExtendedChannelChat : ChannelChat, ExtendedPublicChat, ExtendedChatWithUsername {
val linkedGroupChatId: IdChatIdentifier?
@@ -18,18 +29,16 @@ sealed interface ExtendedGroupChat : GroupChat, ExtendedPublicChat {
}
@Serializable(ExtendedChatSerializer.Companion::class)
sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChatWithUsername {
sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChatWithUsername, ExtendedNonBotChat {
val bio: String
val hasPrivateForwards: Boolean
val hasRestrictedVoiceAndVideoMessages: Boolean
val statusEmojiId: CustomEmojiId?
val statusEmojiExpiration: TelegramDate?
val allowCreateUserIdLink: Boolean
get() = hasPrivateForwards
}
sealed interface ExtendedPublicChat : ExtendedChat, PublicChat {
sealed interface ExtendedPublicChat : ExtendedChat, PublicChat, ExtendedNonBotChat {
val description: String
val inviteLink: String?
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
@@ -65,11 +74,6 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat, Ext
@Serializable(ExtendedChatSerializer.Companion::class)
sealed interface ExtendedForumChat : ExtendedSupergroupChat, ForumChat
@Serializable(ExtendedChatSerializer.Companion::class)
sealed interface ExtendedChat : Chat {
val chatPhoto: ChatPhoto?
}
@Serializable(ExtendedChatSerializer.Companion::class)
sealed interface ExtendedChatWithUsername : UsernameChat, ExtendedChat {
val activeUsernames: List<Username>

View File

@@ -0,0 +1,30 @@
package dev.inmo.tgbotapi.types.giveaway
import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.PreviewChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class Giveaway(
@SerialName(chatsField)
val chats: List<PreviewChat>,
@SerialName(winnersSelectionDateField)
override val selectionDate: TelegramDate,
@SerialName(winnersCountField)
val count: Int,
@SerialName(onlyNewMembersField)
override val onlyNewMembers: Boolean = false,
@SerialName(hasPublicWinnersField)
val publicWinners: Boolean = false,
@SerialName(prizeDescriptionField)
override val additionalPrizeDescription: String? = null,
@SerialName(countryCodesField)
val countries: List<IetfLang>? = null,
@SerialName(premiumSubscriptionMonthCountField)
override val premiumMonths: Int? = null
) : GiveawayInfo, ChatEvent, PublicChatEvent

View File

@@ -0,0 +1,8 @@
package dev.inmo.tgbotapi.types.giveaway
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
import kotlinx.serialization.Serializable
@Serializable
object GiveawayCreated : ChatEvent, PublicChatEvent

View File

@@ -0,0 +1,15 @@
package dev.inmo.tgbotapi.types.giveaway
import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.PreviewChat
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
sealed interface GiveawayInfo {
val selectionDate: TelegramDate
val onlyNewMembers: Boolean
val premiumMonths: Int?
val additionalPrizeDescription: String?
}

View File

@@ -0,0 +1,16 @@
package dev.inmo.tgbotapi.types.giveaway
import dev.inmo.tgbotapi.types.chat.PreviewChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent
import dev.inmo.tgbotapi.types.message.abstracts.Message
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@Serializable
data class GiveawayPrivateResults(
override val chat: PreviewChat,
override val unclaimedCount: Int,
@Transient // TODO::Add message serializer
val message: Message? = null
) : GiveawayResults

View File

@@ -0,0 +1,161 @@
package dev.inmo.tgbotapi.types.giveaway
import dev.inmo.tgbotapi.abstracts.WithPreviewChatAndMessageId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.PreviewChat
import dev.inmo.tgbotapi.types.chat.PreviewUser
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Required
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializable(GiveawayPublicResults.Companion::class)
sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPreviewChatAndMessageId {
val count: Int
val winners: List<PreviewUser>
val additionalChats: Int
val publicWinners: Boolean
val refunded: Boolean
@Serializable
data class Refunded(
@SerialName(chatsField)
override val chat: PreviewChat,
@SerialName(giveawayMessageIdField)
override val messageId: MessageId,
@SerialName(winnersSelectionDateField)
override val selectionDate: TelegramDate,
) : GiveawayPublicResults {
@SerialName(wasRefundedField)
@Required
override val refunded: Boolean = true
@SerialName(winnersCountField)
override val count: Int = 0
@SerialName(winnersField)
override val winners: List<PreviewUser> = emptyList()
@SerialName(additionalChatCountField)
override val additionalChats: Int = 0
@SerialName(unclaimedPrizeCountField)
override val unclaimedCount: Int = 0
@SerialName(onlyNewMembersField)
override val onlyNewMembers: Boolean = false
@SerialName(hasPublicWinnersField)
override val publicWinners: Boolean = false
@SerialName(prizeDescriptionField)
override val additionalPrizeDescription: String? = null
@SerialName(premiumSubscriptionMonthCountField)
override val premiumMonths: Int? = null
}
@Serializable
data class Winners (
@SerialName(chatsField)
override val chat: PreviewChat,
@SerialName(giveawayMessageIdField)
override val messageId: MessageId,
@SerialName(winnersSelectionDateField)
override val selectionDate: TelegramDate,
@SerialName(winnersCountField)
override val count: Int,
@SerialName(winnersField)
override val winners: List<PreviewUser>,
@SerialName(additionalChatCountField)
override val additionalChats: Int = 0,
@SerialName(unclaimedPrizeCountField)
override val unclaimedCount: Int = 0,
@SerialName(onlyNewMembersField)
override val onlyNewMembers: Boolean = false,
@SerialName(hasPublicWinnersField)
override val publicWinners: Boolean = false,
@SerialName(prizeDescriptionField)
override val additionalPrizeDescription: String? = null,
@SerialName(premiumSubscriptionMonthCountField)
override val premiumMonths: Int? = null
) : GiveawayPublicResults {
@SerialName(wasRefundedField)
@Required
override val refunded: Boolean = false
}
@Serializable
private data class Surrogate(
@SerialName(chatsField)
val chat: PreviewChat,
@SerialName(giveawayMessageIdField)
val messageId: MessageId,
@SerialName(winnersSelectionDateField)
val selectionDate: TelegramDate,
@SerialName(winnersCountField)
val count: Int,
@SerialName(winnersField)
val winners: List<PreviewUser>,
@SerialName(additionalChatCountField)
val additionalChats: Int = 0,
@SerialName(unclaimedPrizeCountField)
val unclaimedCount: Int = 0,
@SerialName(onlyNewMembersField)
val onlyNewMembers: Boolean = false,
@SerialName(hasPublicWinnersField)
val publicWinners: Boolean = false,
@SerialName(wasRefundedField)
val refunded: Boolean = false,
@SerialName(prizeDescriptionField)
val additionalPrizeDescription: String? = null,
@SerialName(premiumSubscriptionMonthCountField)
val premiumMonths: Int? = null
)
companion object : KSerializer<GiveawayPublicResults> {
override val descriptor: SerialDescriptor
get() = Surrogate.serializer().descriptor
override fun deserialize(decoder: Decoder): GiveawayPublicResults {
val surrogate = Surrogate.serializer().deserialize(decoder)
return when (surrogate.refunded) {
true -> Refunded(
chat = surrogate.chat,
messageId = surrogate.messageId,
selectionDate = surrogate.selectionDate
)
false -> {
Winners(
chat = surrogate.chat,
messageId = surrogate.messageId,
selectionDate = surrogate.selectionDate,
count = surrogate.count,
winners = surrogate.winners,
additionalChats = surrogate.additionalChats,
unclaimedCount = surrogate.unclaimedCount,
onlyNewMembers = surrogate.onlyNewMembers,
publicWinners = surrogate.publicWinners,
additionalPrizeDescription = surrogate.additionalPrizeDescription,
premiumMonths = surrogate.premiumMonths,
)
}
}
}
override fun serialize(encoder: Encoder, value: GiveawayPublicResults) {
val surrogate = Surrogate(
chat = value.chat,
messageId = value.messageId,
selectionDate = value.selectionDate,
count = value.count,
winners = value.winners,
additionalChats = value.additionalChats,
unclaimedCount = value.unclaimedCount,
onlyNewMembers = value.onlyNewMembers,
publicWinners = value.publicWinners,
additionalPrizeDescription = value.additionalPrizeDescription,
premiumMonths = value.premiumMonths,
refunded = value.refunded
)
Surrogate.serializer().serialize(encoder, surrogate)
}
}
}

View File

@@ -0,0 +1,11 @@
package dev.inmo.tgbotapi.types.giveaway
import dev.inmo.tgbotapi.abstracts.WithPreviewChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
import kotlinx.serialization.Serializable
@Serializable
sealed interface GiveawayResults : WithPreviewChat, ChatEvent, PublicChatEvent {
val unclaimedCount: Int
}

View File

@@ -9,6 +9,10 @@ import dev.inmo.tgbotapi.types.dice.Dice
import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.files.Sticker
import dev.inmo.tgbotapi.types.games.RawGame
import dev.inmo.tgbotapi.types.giveaway.Giveaway
import dev.inmo.tgbotapi.types.giveaway.GiveawayCreated
import dev.inmo.tgbotapi.types.giveaway.GiveawayPrivateResults
import dev.inmo.tgbotapi.types.giveaway.GiveawayResults
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.message.ChatEvents.*
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
@@ -130,7 +134,13 @@ internal data class RawMessage(
private val link_preview_options: LinkPreviewOptions? = null,
private val reply_markup: InlineKeyboardMarkup? = null
private val reply_markup: InlineKeyboardMarkup? = null,
// Giveaways
private val giveaway_created: GiveawayCreated? = null,
private val giveaway: Giveaway? = null,
private val giveaway_winners: GiveawayResults? = null,
private val giveaway_completed: GiveawayPrivateResults? = null,
) {
private val content: MessageContent? by lazy {
val adaptedCaptionEntities = caption ?.let {
@@ -268,6 +278,10 @@ internal data class RawMessage(
web_app_data != null -> web_app_data
users_shared != null -> users_shared
chat_shared != null -> chat_shared
giveaway_created != null -> giveaway_created
giveaway != null -> giveaway
giveaway_winners != null -> giveaway_winners
giveaway_completed != null -> giveaway_completed
else -> null
}
}

View File

@@ -1,7 +1,9 @@
package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.abstracts.WithMessageId
import korlibs.time.DateTime
import dev.inmo.tgbotapi.abstracts.WithPreviewChat
import dev.inmo.tgbotapi.abstracts.WithPreviewChatAndMessageId
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.chat.Chat
@@ -13,8 +15,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@ClassCastsIncluded(excludeRegex = ".*Impl")
interface Message : WithPreviewChat {
val messageId: MessageId
interface Message : WithPreviewChatAndMessageId {
val date: DateTime
}

View File

@@ -0,0 +1,14 @@
package dev.inmo.tgbotapi.types.update
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.boosts.ChatBoostRemoved
import dev.inmo.tgbotapi.types.boosts.ChatBoostUpdated
import dev.inmo.tgbotapi.types.chat.ChatMessageReactionUpdated
import dev.inmo.tgbotapi.types.update.abstracts.Update
import kotlinx.serialization.Serializable
@Serializable
data class ChatBoostRemovedUpdate(
override val updateId: UpdateIdentifier,
override val data: ChatBoostRemoved
) : Update

View File

@@ -0,0 +1,13 @@
package dev.inmo.tgbotapi.types.update
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.boosts.ChatBoostUpdated
import dev.inmo.tgbotapi.types.chat.ChatMessageReactionUpdated
import dev.inmo.tgbotapi.types.update.abstracts.Update
import kotlinx.serialization.Serializable
@Serializable
data class ChatBoostUpdatedUpdate(
override val updateId: UpdateIdentifier,
override val data: ChatBoostUpdated
) : Update

View File

@@ -4,6 +4,8 @@ import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.queries.callback.RawCallbackQuery
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.RawChosenInlineResult
import dev.inmo.tgbotapi.types.InlineQueries.query.RawInlineQuery
import dev.inmo.tgbotapi.types.boosts.ChatBoostRemoved
import dev.inmo.tgbotapi.types.boosts.ChatBoostUpdated
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
import dev.inmo.tgbotapi.types.chat.ChatMessageReactionUpdated
import dev.inmo.tgbotapi.types.chat.ChatMessageReactionsCountUpdated
@@ -42,8 +44,11 @@ internal data class RawUpdate constructor(
private val chat_member: ChatMemberUpdated? = null,
private val chat_join_request: ChatJoinRequest? = null,
private val message_reaction: ChatMessageReactionUpdated? = null,
private val message_reaction_count: ChatMessageReactionsCountUpdated? = null
private val message_reaction_count: ChatMessageReactionsCountUpdated? = null,
private val chat_boost: ChatBoostUpdated? = null,
private val removed_chat_boost: ChatBoostRemoved? = null
) {
@Transient
private var initedUpdate: Update? = null
/**
* @return One of children of [Update] interface or null in case of unknown type of update
@@ -71,6 +76,8 @@ internal data class RawUpdate constructor(
chat_join_request != null -> ChatJoinRequestUpdate(updateId, chat_join_request)
message_reaction != null -> ChatMessageReactionUpdatedUpdate(updateId, message_reaction)
message_reaction_count != null -> ChatMessageReactionsCountUpdatedUpdate(updateId, message_reaction_count)
chat_boost != null -> ChatBoostUpdatedUpdate(updateId, chat_boost)
removed_chat_boost != null -> ChatBoostRemovedUpdate(updateId, removed_chat_boost)
else -> UnknownUpdate(
updateId,
raw

View File

@@ -39,6 +39,8 @@ interface FlowsUpdatesFilter : UpdatesFilter {
val chatJoinRequestUpdateFlow: Flow<ChatJoinRequestUpdate>
val chatMessageReactionUpdatedUpdateFlow: Flow<ChatMessageReactionUpdatedUpdate>
val chatMessageReactionsCountUpdatedUpdateFlow: Flow<ChatMessageReactionsCountUpdatedUpdate>
val chatBoostUpdatedUpdateFlow: Flow<ChatBoostUpdatedUpdate>
val chatBoostRemovedUpdateFlow: Flow<ChatBoostRemovedUpdate>
val unknownUpdatesFlow: Flow<UnknownUpdate>
}
@@ -60,6 +62,8 @@ abstract class AbstractFlowsUpdatesFilter : FlowsUpdatesFilter {
override val chatMessageReactionUpdatedUpdateFlow: Flow<ChatMessageReactionUpdatedUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
override val chatMessageReactionsCountUpdatedUpdateFlow: Flow<ChatMessageReactionsCountUpdatedUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
override val unknownUpdatesFlow: Flow<UnknownUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
override val chatBoostUpdatedUpdateFlow: Flow<ChatBoostUpdatedUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
override val chatBoostRemovedUpdateFlow: Flow<ChatBoostRemovedUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
}
/**

View File

@@ -1,9 +1,7 @@
package dev.inmo.tgbotapi.types.message.ChatEvents
import dev.inmo.tgbotapi.TestsJsonFormat
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
import dev.inmo.tgbotapi.extensions.utils.asMigratedToSupergroup
import dev.inmo.tgbotapi.extensions.utils.asSupergroupEventMessage
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy
import kotlin.test.Test
@@ -41,9 +39,9 @@ class MigratedToSupergroupTest {
}
""".trimIndent()
val update = TestsJsonFormat.decodeFromString(UpdateDeserializationStrategy, payload)
val message = update.asMessageUpdate() ?: fail("update should be of MessageUpdate subtype")
val data = message.data.asSupergroupEventMessage() ?: fail("message should be of SupergroupEventMessage subtype")
val event = data.chatEvent.asMigratedToSupergroup() ?: fail("event should be of SupergroupChatCreated subtype")
val message = update.messageUpdateOrThrow()
val data = message.data.supergroupEventMessageOrThrow()
val event = data.chatEvent.migratedToSupergroupOrThrow()
assertEquals(IdChatIdentifier(57005), event.migratedFrom)
}

View File

@@ -90,6 +90,7 @@ import dev.inmo.tgbotapi.types.actions.UploadPhotoAction
import dev.inmo.tgbotapi.types.actions.UploadVideoAction
import dev.inmo.tgbotapi.types.actions.UploadVideoNoteAction
import dev.inmo.tgbotapi.types.actions.UploadVoiceAction
import dev.inmo.tgbotapi.types.boosts.ChatBoostSource
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackGameInlineKeyboardButton
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.InlineKeyboardButton
@@ -195,6 +196,11 @@ import dev.inmo.tgbotapi.types.files.VideoFile
import dev.inmo.tgbotapi.types.files.VideoNoteFile
import dev.inmo.tgbotapi.types.files.VideoSticker
import dev.inmo.tgbotapi.types.files.VoiceFile
import dev.inmo.tgbotapi.types.giveaway.Giveaway
import dev.inmo.tgbotapi.types.giveaway.GiveawayCreated
import dev.inmo.tgbotapi.types.giveaway.GiveawayPrivateResults
import dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults
import dev.inmo.tgbotapi.types.giveaway.GiveawayResults
import dev.inmo.tgbotapi.types.location.LiveLocation
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.location.StaticLocation
@@ -314,6 +320,7 @@ import dev.inmo.tgbotapi.types.message.content.VideoNoteContent
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.VoiceContent
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
import dev.inmo.tgbotapi.types.message.textsources.BlockquoteTextSource
import dev.inmo.tgbotapi.types.message.textsources.BoldTextSource
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
import dev.inmo.tgbotapi.types.message.textsources.CashTagTextSource
@@ -423,6 +430,8 @@ import dev.inmo.tgbotapi.types.request.RequestResponse
import dev.inmo.tgbotapi.types.request.UsersShared
import dev.inmo.tgbotapi.types.update.CallbackQueryUpdate
import dev.inmo.tgbotapi.types.update.ChannelPostUpdate
import dev.inmo.tgbotapi.types.update.ChatBoostRemovedUpdate
import dev.inmo.tgbotapi.types.update.ChatBoostUpdatedUpdate
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
import dev.inmo.tgbotapi.types.update.ChatMessageReactionUpdatedUpdate
import dev.inmo.tgbotapi.types.update.ChatMessageReactionsCountUpdatedUpdate
@@ -1619,6 +1628,69 @@ public inline fun BotAction.customBotActionOrThrow(): CustomBotAction = this as
public inline fun <T> BotAction.ifCustomBotAction(block: (CustomBotAction) -> T): T? =
customBotActionOrNull() ?.let(block)
public inline fun ChatBoostSource.byUserOrNull(): ChatBoostSource.ByUser? = this as?
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.ByUser
public inline fun ChatBoostSource.byUserOrThrow(): ChatBoostSource.ByUser = this as
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.ByUser
public inline fun <T> ChatBoostSource.ifByUser(block: (ChatBoostSource.ByUser) -> T): T? =
byUserOrNull() ?.let(block)
public inline fun ChatBoostSource.giftCodeOrNull(): ChatBoostSource.GiftCode? = this as?
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.GiftCode
public inline fun ChatBoostSource.giftCodeOrThrow(): ChatBoostSource.GiftCode = this as
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.GiftCode
public inline fun <T> ChatBoostSource.ifGiftCode(block: (ChatBoostSource.GiftCode) -> T): T? =
giftCodeOrNull() ?.let(block)
public inline fun ChatBoostSource.claimedOrNull(): ChatBoostSource.Giveaway.Claimed? = this as?
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.Giveaway.Claimed
public inline fun ChatBoostSource.claimedOrThrow(): ChatBoostSource.Giveaway.Claimed = this as
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.Giveaway.Claimed
public inline fun <T> ChatBoostSource.ifClaimed(block: (ChatBoostSource.Giveaway.Claimed) -> T): T?
= claimedOrNull() ?.let(block)
public inline fun ChatBoostSource.premiumOrNull(): ChatBoostSource.Premium? = this as?
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.Premium
public inline fun ChatBoostSource.premiumOrThrow(): ChatBoostSource.Premium = this as
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.Premium
public inline fun <T> ChatBoostSource.ifPremium(block: (ChatBoostSource.Premium) -> T): T? =
premiumOrNull() ?.let(block)
public inline fun ChatBoostSource.giveawayOrNull(): ChatBoostSource.Giveaway? = this as?
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.Giveaway
public inline fun ChatBoostSource.giveawayOrThrow(): ChatBoostSource.Giveaway = this as
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.Giveaway
public inline fun <T> ChatBoostSource.ifGiveaway(block: (ChatBoostSource.Giveaway) -> T): T? =
giveawayOrNull() ?.let(block)
public inline fun ChatBoostSource.unclaimedOrNull(): ChatBoostSource.Giveaway.Unclaimed? = this as?
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.Giveaway.Unclaimed
public inline fun ChatBoostSource.unclaimedOrThrow(): ChatBoostSource.Giveaway.Unclaimed = this as
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.Giveaway.Unclaimed
public inline fun <T> ChatBoostSource.ifUnclaimed(block: (ChatBoostSource.Giveaway.Unclaimed) -> T):
T? = unclaimedOrNull() ?.let(block)
public inline fun ChatBoostSource.unknownOrNull(): ChatBoostSource.Unknown? = this as?
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.Unknown
public inline fun ChatBoostSource.unknownOrThrow(): ChatBoostSource.Unknown = this as
dev.inmo.tgbotapi.types.boosts.ChatBoostSource.Unknown
public inline fun <T> ChatBoostSource.ifUnknown(block: (ChatBoostSource.Unknown) -> T): T? =
unknownOrNull() ?.let(block)
public inline fun InlineKeyboardButton.unknownInlineKeyboardButtonOrNull():
UnknownInlineKeyboardButton? = this as?
dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.UnknownInlineKeyboardButton
@@ -1741,8 +1813,9 @@ public inline fun KeyboardButtonRequestUsers.anyOrNull(): KeyboardButtonRequestU
public inline fun KeyboardButtonRequestUsers.anyOrThrow(): KeyboardButtonRequestUsers.Any = this as
dev.inmo.tgbotapi.types.buttons.KeyboardButtonRequestUsers.Any
public inline fun <T> KeyboardButtonRequestUsers.ifAny(block: (KeyboardButtonRequestUsers.Any) -> T):
T? = anyOrNull() ?.let(block)
public inline fun <T>
KeyboardButtonRequestUsers.ifAny(block: (KeyboardButtonRequestUsers.Any) -> T): T? = anyOrNull()
?.let(block)
public inline fun KeyboardButtonRequestUsers.botOrNull(): KeyboardButtonRequestUsers.Bot? = this as?
dev.inmo.tgbotapi.types.buttons.KeyboardButtonRequestUsers.Bot
@@ -1750,14 +1823,15 @@ public inline fun KeyboardButtonRequestUsers.botOrNull(): KeyboardButtonRequestU
public inline fun KeyboardButtonRequestUsers.botOrThrow(): KeyboardButtonRequestUsers.Bot = this as
dev.inmo.tgbotapi.types.buttons.KeyboardButtonRequestUsers.Bot
public inline fun <T> KeyboardButtonRequestUsers.ifBot(block: (KeyboardButtonRequestUsers.Bot) -> T):
T? = botOrNull() ?.let(block)
public inline fun <T>
KeyboardButtonRequestUsers.ifBot(block: (KeyboardButtonRequestUsers.Bot) -> T): T? = botOrNull()
?.let(block)
public inline fun KeyboardButtonRequestUsers.commonOrNull(): KeyboardButtonRequestUsers.Common? = this
as? dev.inmo.tgbotapi.types.buttons.KeyboardButtonRequestUsers.Common
public inline fun KeyboardButtonRequestUsers.commonOrNull(): KeyboardButtonRequestUsers.Common? =
this as? dev.inmo.tgbotapi.types.buttons.KeyboardButtonRequestUsers.Common
public inline fun KeyboardButtonRequestUsers.commonOrThrow(): KeyboardButtonRequestUsers.Common = this
as dev.inmo.tgbotapi.types.buttons.KeyboardButtonRequestUsers.Common
public inline fun KeyboardButtonRequestUsers.commonOrThrow(): KeyboardButtonRequestUsers.Common =
this as dev.inmo.tgbotapi.types.buttons.KeyboardButtonRequestUsers.Common
public inline fun <T>
KeyboardButtonRequestUsers.ifCommon(block: (KeyboardButtonRequestUsers.Common) -> T): T? =
@@ -2645,6 +2719,51 @@ public inline fun TelegramMedia.titledTelegramMediaOrThrow(): TitledTelegramMedi
public inline fun <T> TelegramMedia.ifTitledTelegramMedia(block: (TitledTelegramMedia) -> T): T? =
titledTelegramMediaOrNull() ?.let(block)
public inline fun ChatEvent.giveawayOrNull(): Giveaway? = this as?
dev.inmo.tgbotapi.types.giveaway.Giveaway
public inline fun ChatEvent.giveawayOrThrow(): Giveaway = this as
dev.inmo.tgbotapi.types.giveaway.Giveaway
public inline fun <T> ChatEvent.ifGiveaway(block: (Giveaway) -> T): T? = giveawayOrNull()
?.let(block)
public inline fun ChatEvent.giveawayCreatedOrNull(): GiveawayCreated? = this as?
dev.inmo.tgbotapi.types.giveaway.GiveawayCreated
public inline fun ChatEvent.giveawayCreatedOrThrow(): GiveawayCreated = this as
dev.inmo.tgbotapi.types.giveaway.GiveawayCreated
public inline fun <T> ChatEvent.ifGiveawayCreated(block: (GiveawayCreated) -> T): T? =
giveawayCreatedOrNull() ?.let(block)
public inline fun ChatEvent.giveawayPrivateResultsOrNull(): GiveawayPrivateResults? = this as?
dev.inmo.tgbotapi.types.giveaway.GiveawayPrivateResults
public inline fun ChatEvent.giveawayPrivateResultsOrThrow(): GiveawayPrivateResults = this as
dev.inmo.tgbotapi.types.giveaway.GiveawayPrivateResults
public inline fun <T> ChatEvent.ifGiveawayPrivateResults(block: (GiveawayPrivateResults) -> T): T? =
giveawayPrivateResultsOrNull() ?.let(block)
public inline fun ChatEvent.giveawayPublicResultsOrNull(): GiveawayPublicResults? = this as?
dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults
public inline fun ChatEvent.giveawayPublicResultsOrThrow(): GiveawayPublicResults = this as
dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults
public inline fun <T> ChatEvent.ifGiveawayPublicResults(block: (GiveawayPublicResults) -> T): T? =
giveawayPublicResultsOrNull() ?.let(block)
public inline fun ChatEvent.giveawayResultsOrNull(): GiveawayResults? = this as?
dev.inmo.tgbotapi.types.giveaway.GiveawayResults
public inline fun ChatEvent.giveawayResultsOrThrow(): GiveawayResults = this as
dev.inmo.tgbotapi.types.giveaway.GiveawayResults
public inline fun <T> ChatEvent.ifGiveawayResults(block: (GiveawayResults) -> T): T? =
giveawayResultsOrNull() ?.let(block)
public inline fun ChatEvent.channelChatCreatedOrNull(): ChannelChatCreated? = this as?
dev.inmo.tgbotapi.types.message.ChatEvents.ChannelChatCreated
@@ -2972,13 +3091,13 @@ public inline fun ChatEvent.chatSharedRequestOrThrow(): ChatSharedRequest = this
public inline fun <T> ChatEvent.ifChatSharedRequest(block: (ChatSharedRequest) -> T): T? =
chatSharedRequestOrNull() ?.let(block)
public inline fun ChatEvent.userSharedOrNull(): UsersShared? = this as?
public inline fun ChatEvent.usersSharedOrNull(): UsersShared? = this as?
dev.inmo.tgbotapi.types.request.UsersShared
public inline fun ChatEvent.userSharedOrThrow(): UsersShared = this as
public inline fun ChatEvent.usersSharedOrThrow(): UsersShared = this as
dev.inmo.tgbotapi.types.request.UsersShared
public inline fun <T> ChatEvent.ifUserShared(block: (UsersShared) -> T): T? = userSharedOrNull()
public inline fun <T> ChatEvent.ifUsersShared(block: (UsersShared) -> T): T? = usersSharedOrNull()
?.let(block)
public inline fun ForwardInfo.byAnonymousOrNull(): ForwardInfo.ByAnonymous? = this as?
@@ -3679,6 +3798,15 @@ public inline fun ResendableContent.voiceContentOrThrow(): VoiceContent = this a
public inline fun <T> ResendableContent.ifVoiceContent(block: (VoiceContent) -> T): T? =
voiceContentOrNull() ?.let(block)
public inline fun TextSource.blockquoteTextSourceOrNull(): BlockquoteTextSource? = this as?
dev.inmo.tgbotapi.types.message.textsources.BlockquoteTextSource
public inline fun TextSource.blockquoteTextSourceOrThrow(): BlockquoteTextSource = this as
dev.inmo.tgbotapi.types.message.textsources.BlockquoteTextSource
public inline fun <T> TextSource.ifBlockquoteTextSource(block: (BlockquoteTextSource) -> T): T? =
blockquoteTextSourceOrNull() ?.let(block)
public inline fun TextSource.boldTextSourceOrNull(): BoldTextSource? = this as?
dev.inmo.tgbotapi.types.message.textsources.BoldTextSource
@@ -4564,14 +4692,14 @@ public inline fun RequestResponse.chatSharedRequestOrThrow(): ChatSharedRequest
public inline fun <T> RequestResponse.ifChatSharedRequest(block: (ChatSharedRequest) -> T): T? =
chatSharedRequestOrNull() ?.let(block)
public inline fun RequestResponse.userSharedOrNull(): UsersShared? = this as?
public inline fun RequestResponse.usersSharedOrNull(): UsersShared? = this as?
dev.inmo.tgbotapi.types.request.UsersShared
public inline fun RequestResponse.userSharedOrThrow(): UsersShared = this as
public inline fun RequestResponse.usersSharedOrThrow(): UsersShared = this as
dev.inmo.tgbotapi.types.request.UsersShared
public inline fun <T> RequestResponse.ifUserShared(block: (UsersShared) -> T): T? =
userSharedOrNull() ?.let(block)
public inline fun <T> RequestResponse.ifUsersShared(block: (UsersShared) -> T): T? =
usersSharedOrNull() ?.let(block)
public inline fun Update.callbackQueryUpdateOrNull(): CallbackQueryUpdate? = this as?
dev.inmo.tgbotapi.types.update.CallbackQueryUpdate
@@ -4591,6 +4719,24 @@ public inline fun Update.channelPostUpdateOrThrow(): ChannelPostUpdate = this as
public inline fun <T> Update.ifChannelPostUpdate(block: (ChannelPostUpdate) -> T): T? =
channelPostUpdateOrNull() ?.let(block)
public inline fun Update.chatBoostRemovedUpdateOrNull(): ChatBoostRemovedUpdate? = this as?
dev.inmo.tgbotapi.types.update.ChatBoostRemovedUpdate
public inline fun Update.chatBoostRemovedUpdateOrThrow(): ChatBoostRemovedUpdate = this as
dev.inmo.tgbotapi.types.update.ChatBoostRemovedUpdate
public inline fun <T> Update.ifChatBoostRemovedUpdate(block: (ChatBoostRemovedUpdate) -> T): T? =
chatBoostRemovedUpdateOrNull() ?.let(block)
public inline fun Update.chatBoostUpdatedUpdateOrNull(): ChatBoostUpdatedUpdate? = this as?
dev.inmo.tgbotapi.types.update.ChatBoostUpdatedUpdate
public inline fun Update.chatBoostUpdatedUpdateOrThrow(): ChatBoostUpdatedUpdate = this as
dev.inmo.tgbotapi.types.update.ChatBoostUpdatedUpdate
public inline fun <T> Update.ifChatBoostUpdatedUpdate(block: (ChatBoostUpdatedUpdate) -> T): T? =
chatBoostUpdatedUpdateOrNull() ?.let(block)
public inline fun Update.chatJoinRequestUpdateOrNull(): ChatJoinRequestUpdate? = this as?
dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate

View File

@@ -42,6 +42,8 @@ fun Update.sourceChatWithConverters(
myChatMemberUpdatedUpdateConverter: (MyChatMemberUpdatedUpdate) -> Chat? = { it.data.chat },
chatMessageReactionUpdatedUpdateConverter: (ChatMessageReactionUpdatedUpdate) -> Chat? = { it.data.chat },
chatMessageReactionsCountUpdatedUpdateConverter: (ChatMessageReactionsCountUpdatedUpdate) -> Chat? = { it.data.chat },
chatBoostUpdatedUpdateFlow: (ChatBoostUpdatedUpdate) -> Chat? = { it.data.chat },
chatBoostRemovedUpdateFlow: (ChatBoostRemovedUpdate) -> Chat? = { it.data.chat },
commonChatMemberUpdatedUpdateConverter: (CommonChatMemberUpdatedUpdate) -> Chat? = { it.data.chat }
): Chat? = when (this) {
is BaseMessageUpdate -> baseMessageUpdateConverter(this)
@@ -61,6 +63,8 @@ fun Update.sourceChatWithConverters(
is CommonChatMemberUpdatedUpdate -> commonChatMemberUpdatedUpdateConverter(this)
is ChatMessageReactionUpdatedUpdate -> chatMessageReactionUpdatedUpdateConverter(this)
is ChatMessageReactionsCountUpdatedUpdate -> chatMessageReactionsCountUpdatedUpdateConverter(this)
is ChatBoostUpdatedUpdate -> chatBoostUpdatedUpdateFlow(this)
is ChatBoostRemovedUpdate -> chatBoostRemovedUpdateFlow(this)
else -> {
when (val data = data) {
is FromUser -> data.from

View File

@@ -0,0 +1,11 @@
package dev.inmo.tgbotapi.webapps
external interface SettingsButton {
val isVisible: Boolean
fun onClick(callback: () -> Unit)
fun offClick(callback: () -> Unit)
fun show()
fun hide()
}

View File

@@ -30,4 +30,17 @@ external interface ThemeParams {
val buttonColorHex: Color.Hex?
@JsName("button_text_color")
val buttonTextColorHex: Color.Hex?
@JsName("header_bg_color")
val headerBgColor: Color.Hex?
@JsName("accent_text_color")
val accentTextColor: Color.Hex?
@JsName("section_bg_color")
val sectionBgColor: Color.Hex?
@JsName("section_header_text_color")
val sectionHeaderTextColor: Color.Hex?
@JsName("subtitle_text_color")
val subtitleTextColor: Color.Hex?
@JsName("destructive_text_color")
val destructiveTextColor: Color.Hex?
}

View File

@@ -54,6 +54,9 @@ external class WebApp {
@JsName("CloudStorage")
val cloudStorage: CloudStorage
@JsName("SettingsButton")
val settingsButton: SettingsButton
internal fun onEvent(type: String, callback: () -> Unit)
@JsName("onEvent")
internal fun onEventWithViewportChangedData(type: String, callback: (ViewportChangedData) -> Unit)
@@ -69,6 +72,8 @@ external class WebApp {
internal fun onEventWithWriteAccessRequested(type: String, callback: (RequestStatus) -> Unit)
@JsName("onEvent")
internal fun onEventWithContactRequested(type: String, callback: (RequestStatus) -> Unit)
@JsName("onEvent")
internal fun onEventWithSettingsButtonClicked(type: String, callback: () -> Unit)
fun offEvent(type: String, callback: () -> Unit)
@JsName("offEvent")
@@ -194,6 +199,18 @@ fun WebApp.onEvent(type: EventType.ContactRequested, eventHandler: ContactReques
)
}
/**
* @return The callback which should be used in case you want to turn off events handling
*/
fun WebApp.onEvent(type: EventType.SettingsButtonClicked, eventHandler: EventHandler) = {
eventHandler(js("this").unsafeCast<WebApp>())
}.also {
onEventWithSettingsButtonClicked(
type.typeName,
callback = it
)
}
/**
* @return The callback which should be used in case you want to turn off events handling
*/