diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetBusinessConnection.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetBusinessConnection.kt new file mode 100644 index 0000000000..e2e6344cb4 --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetBusinessConnection.kt @@ -0,0 +1,17 @@ +package dev.inmo.tgbotapi.extensions.api.get + +import dev.inmo.micro_utils.common.Warning +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.get.GetBusinessConnection +import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId + +suspend fun TelegramBot.getBusinessConnection( + id: BusinessConnectionId +) = execute(GetBusinessConnection(id = id)) + +@Warning("This method may lead to error due to raw String type usage") +suspend fun TelegramBot.getBusinessConnection( + id: String +) = getBusinessConnection( + BusinessConnectionId(id) +) \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetBusinessConnection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetBusinessConnection.kt new file mode 100644 index 0000000000..db9d938c7f --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetBusinessConnection.kt @@ -0,0 +1,26 @@ +package dev.inmo.tgbotapi.requests.get + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.business_connection.BusinessConnection +import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId +import dev.inmo.tgbotapi.types.files.PathedFile +import dev.inmo.tgbotapi.types.idField +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationStrategy + +@Serializable +data class GetBusinessConnection( + @SerialName(idField) + val id: BusinessConnectionId +) : SimpleRequest { + override fun method(): String { + return "getBusinessConnection" + } + + override val resultDeserializer: DeserializationStrategy + get() = BusinessConnection.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} \ No newline at end of file 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 b60bbf4cde..c36d7368f0 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 @@ -156,6 +156,7 @@ 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" +const val canReplyField = "can_reply" const val supportInlineQueriesField = "supports_inline_queries" const val textEntitiesField = "text_entities" const val entitiesField = "entities" @@ -190,6 +191,7 @@ const val untilDateField = "until_date" const val errorMessageField = "error_message" const val messageTextField = "message_text" const val isPersonalField = "is_personal" +const val isEnabledField = "is_enabled" const val nextOffsetField = "next_offset" const val buttonField = "button" const val switchPmTextField = "switch_pm_text" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/business_connection/BusinessConnection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/business_connection/BusinessConnection.kt new file mode 100644 index 0000000000..67c4574ea2 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/business_connection/BusinessConnection.kt @@ -0,0 +1,70 @@ +package dev.inmo.tgbotapi.types.business_connection + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.PreviewUser +import kotlinx.serialization.EncodeDefault +import kotlinx.serialization.KSerializer +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable +sealed interface BusinessConnection { + val id: BusinessConnectionId + val user: PreviewUser + val userChatId: ChatId + val date: TelegramDate + val canReply: Boolean + val isEnabled: Boolean + + @Serializable + data class Enabled( + @SerialName(idField) + override val id: BusinessConnectionId, + @SerialName(userField) + override val user: PreviewUser, + @SerialName(userChatIdField) + override val userChatId: ChatId, + @SerialName(dateField) + override val date: TelegramDate, + @SerialName(canReplyField) + override val canReply: Boolean, + ) : BusinessConnection { + @EncodeDefault + override val isEnabled: Boolean = true + } + + @Serializable + data class Disabled( + @SerialName(idField) + override val id: BusinessConnectionId, + @SerialName(userField) + override val user: PreviewUser, + @SerialName(userChatIdField) + override val userChatId: ChatId, + @SerialName(dateField) + override val date: TelegramDate, + @SerialName(canReplyField) + override val canReply: Boolean, + ) : BusinessConnection { + @EncodeDefault + override val isEnabled: Boolean = false + } + + companion object : KSerializer { + override val descriptor: SerialDescriptor + get() = RawBusinessConnection.serializer().descriptor + + override fun deserialize(decoder: Decoder): BusinessConnection { + return RawBusinessConnection.serializer().deserialize(decoder).asBusinessConnection + + } + + override fun serialize(encoder: Encoder, value: BusinessConnection) { + + } + + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/business_connection/BusinessConnectionId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/business_connection/BusinessConnectionId.kt new file mode 100644 index 0000000000..c375dc27ba --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/business_connection/BusinessConnectionId.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.business_connection + +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +value class BusinessConnectionId( + val string: String +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/business_connection/RawBusinessConnection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/business_connection/RawBusinessConnection.kt new file mode 100644 index 0000000000..5b14aaf187 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/business_connection/RawBusinessConnection.kt @@ -0,0 +1,49 @@ +package dev.inmo.tgbotapi.types.business_connection + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.PreviewUser +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class RawBusinessConnection( + @SerialName(idField) + val id: BusinessConnectionId, + @SerialName(userField) + val user: PreviewUser, + @SerialName(userChatIdField) + val userChatId: ChatId, + @SerialName(dateField) + val date: TelegramDate, + @SerialName(canReplyField) + val canReply: Boolean, + @SerialName(isEnabledField) + val isEnabled: Boolean +) { + val asBusinessConnection + get() = when (isEnabled) { + true -> BusinessConnection.Enabled( + id = id, + user = user, + userChatId = userChatId, + date = date, + canReply = canReply + ) + false -> BusinessConnection.Disabled( + id = id, + user = user, + userChatId = userChatId, + date = date, + canReply = canReply + ) + } + + constructor(businessConnection: BusinessConnection) : this( + id = businessConnection.id, + user = businessConnection.user, + userChatId = businessConnection.userChatId, + date = businessConnection.date, + canReply = businessConnection.canReply, + isEnabled = businessConnection.isEnabled, + ) +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/BusinessConnectionUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/BusinessConnectionUpdate.kt new file mode 100644 index 0000000000..2db3f45bd1 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/BusinessConnectionUpdate.kt @@ -0,0 +1,12 @@ +package dev.inmo.tgbotapi.types.update + +import dev.inmo.tgbotapi.types.UpdateId +import dev.inmo.tgbotapi.types.business_connection.BusinessConnection +import dev.inmo.tgbotapi.types.update.abstracts.Update +import kotlinx.serialization.Serializable + +@Serializable +data class BusinessConnectionUpdate( + override val updateId: UpdateId, + override val data: BusinessConnection +) : Update diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt index ead3a2b09d..77e3645deb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt @@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.RawChosenInlineR 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.business_connection.BusinessConnection import dev.inmo.tgbotapi.types.chat.ChatJoinRequest import dev.inmo.tgbotapi.types.chat.ChatMessageReactionUpdated import dev.inmo.tgbotapi.types.chat.ChatMessageReactionsCountUpdated @@ -46,7 +47,8 @@ internal data class RawUpdate constructor( private val message_reaction: ChatMessageReactionUpdated? = null, private val message_reaction_count: ChatMessageReactionsCountUpdated? = null, private val chat_boost: ChatBoostUpdated? = null, - private val removed_chat_boost: ChatBoostRemoved? = null + private val removed_chat_boost: ChatBoostRemoved? = null, + private val business_connection: BusinessConnection? = null ) { @Transient private var initedUpdate: Update? = null @@ -78,6 +80,7 @@ internal data class RawUpdate constructor( 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) + business_connection != null -> BusinessConnectionUpdate(updateId, removed_chat_boost) else -> UnknownUpdate( updateId, raw diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt index b2886f2cf8..7653790999 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt @@ -30,6 +30,7 @@ interface FlowsUpdatesFilter : UpdatesFilter { val chosenInlineResultsFlow: Flow val inlineQueriesFlow: Flow val callbackQueriesFlow: Flow + val businessConnectionsFlow: Flow val shippingQueriesFlow: Flow val preCheckoutQueriesFlow: Flow val pollsFlow: Flow