1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

almost completed adding of BusinessConnection

This commit is contained in:
InsanusMokrassar 2024-04-15 01:19:33 +06:00
parent 0e0af73633
commit b8061966be
9 changed files with 191 additions and 1 deletions

View File

@ -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)
)

View File

@ -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<BusinessConnection> {
override fun method(): String {
return "getBusinessConnection"
}
override val resultDeserializer: DeserializationStrategy<BusinessConnection>
get() = BusinessConnection.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -156,6 +156,7 @@ const val customEmojiStickerSetNameField = "custom_emoji_sticker_set_name"
const val iconCustomEmojiIdField = "icon_custom_emoji_id" const val iconCustomEmojiIdField = "icon_custom_emoji_id"
const val canJoinGroupsField = "can_join_groups" const val canJoinGroupsField = "can_join_groups"
const val canReadAllGroupMessagesField = "can_read_all_group_messages" const val canReadAllGroupMessagesField = "can_read_all_group_messages"
const val canReplyField = "can_reply"
const val supportInlineQueriesField = "supports_inline_queries" const val supportInlineQueriesField = "supports_inline_queries"
const val textEntitiesField = "text_entities" const val textEntitiesField = "text_entities"
const val entitiesField = "entities" const val entitiesField = "entities"
@ -190,6 +191,7 @@ const val untilDateField = "until_date"
const val errorMessageField = "error_message" const val errorMessageField = "error_message"
const val messageTextField = "message_text" const val messageTextField = "message_text"
const val isPersonalField = "is_personal" const val isPersonalField = "is_personal"
const val isEnabledField = "is_enabled"
const val nextOffsetField = "next_offset" const val nextOffsetField = "next_offset"
const val buttonField = "button" const val buttonField = "button"
const val switchPmTextField = "switch_pm_text" const val switchPmTextField = "switch_pm_text"

View File

@ -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<BusinessConnection> {
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) {
}
}
}

View File

@ -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
)

View File

@ -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,
)
}

View File

@ -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

View File

@ -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.InlineQueries.query.RawInlineQuery
import dev.inmo.tgbotapi.types.boosts.ChatBoostRemoved import dev.inmo.tgbotapi.types.boosts.ChatBoostRemoved
import dev.inmo.tgbotapi.types.boosts.ChatBoostUpdated 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.ChatJoinRequest
import dev.inmo.tgbotapi.types.chat.ChatMessageReactionUpdated import dev.inmo.tgbotapi.types.chat.ChatMessageReactionUpdated
import dev.inmo.tgbotapi.types.chat.ChatMessageReactionsCountUpdated 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: ChatMessageReactionUpdated? = null,
private val message_reaction_count: ChatMessageReactionsCountUpdated? = null, private val message_reaction_count: ChatMessageReactionsCountUpdated? = null,
private val chat_boost: ChatBoostUpdated? = 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 @Transient
private var initedUpdate: Update? = null private var initedUpdate: Update? = null
@ -78,6 +80,7 @@ internal data class RawUpdate constructor(
message_reaction_count != null -> ChatMessageReactionsCountUpdatedUpdate(updateId, message_reaction_count) message_reaction_count != null -> ChatMessageReactionsCountUpdatedUpdate(updateId, message_reaction_count)
chat_boost != null -> ChatBoostUpdatedUpdate(updateId, chat_boost) chat_boost != null -> ChatBoostUpdatedUpdate(updateId, chat_boost)
removed_chat_boost != null -> ChatBoostRemovedUpdate(updateId, removed_chat_boost) removed_chat_boost != null -> ChatBoostRemovedUpdate(updateId, removed_chat_boost)
business_connection != null -> BusinessConnectionUpdate(updateId, removed_chat_boost)
else -> UnknownUpdate( else -> UnknownUpdate(
updateId, updateId,
raw raw

View File

@ -30,6 +30,7 @@ interface FlowsUpdatesFilter : UpdatesFilter {
val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate> val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate>
val inlineQueriesFlow: Flow<InlineQueryUpdate> val inlineQueriesFlow: Flow<InlineQueryUpdate>
val callbackQueriesFlow: Flow<CallbackQueryUpdate> val callbackQueriesFlow: Flow<CallbackQueryUpdate>
val businessConnectionsFlow: Flow<BusinessConnectionUpdate>
val shippingQueriesFlow: Flow<ShippingQueryUpdate> val shippingQueriesFlow: Flow<ShippingQueryUpdate>
val preCheckoutQueriesFlow: Flow<PreCheckoutQueryUpdate> val preCheckoutQueriesFlow: Flow<PreCheckoutQueryUpdate>
val pollsFlow: Flow<PollUpdate> val pollsFlow: Flow<PollUpdate>