mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
commit
790885fd0d
30
CHANGELOG.md
30
CHANGELOG.md
@ -1,5 +1,35 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 0.17.0
|
||||
|
||||
Libraries updates:
|
||||
|
||||
* Kotlin version `1.3.31` -> `1.3.41`
|
||||
* Kotlin Coroutines version `1.2.1` -> `1.2.2`
|
||||
* Kotlin Serialization version `0.11.0` -> `0.11.1`
|
||||
* Joda Time version `2.10.1` -> `2.10.3`
|
||||
* ktor version `1.1.4` -> `1.2.3`
|
||||
|
||||
Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegram.org/bots/api#july-29-2019):
|
||||
|
||||
* `Sticker` and `StickerSet` now have field `isAnimated`
|
||||
* `ChatPermissions` object was added, `GroupChat` interface got `permissions` field, request `SetChatPermissions` was added
|
||||
* `GroupChat` object now have no field `allMembersAreAdmins`
|
||||
* `SpecialRightsChatMember` was added for administrators and restricted members rights union, chat members abstractions
|
||||
was replaced into `abstracts` package and available permissions was updated
|
||||
* `RestrictChatMember` request now accept `permissions` object instead of separated permissions
|
||||
* All `GroupChat` instances have description
|
||||
|
||||
Other important changes:
|
||||
|
||||
* Totally reworked chats hierarchy. `Extended` abstractions was added for cases when called `GetChat` request
|
||||
* `RawChat` boilerplate was removed and replaced by serializers
|
||||
* `BotCommandMessageEntity#command` will not contain `/`/`!` parts and also will cut outside of command begin token (`/`
|
||||
or `!`) and username token (`@`) or end of command (any space character)
|
||||
* `RequestsExecutor` now is `Closeable`
|
||||
* `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things
|
||||
like this
|
||||
|
||||
## 0.16.0 Bot API 4.3
|
||||
|
||||
* `LoginURL` and `LoginURLInlineKeyboardButton` has been added
|
||||
|
16
build.gradle
16
build.gradle
@ -1,4 +1,4 @@
|
||||
project.version = "0.16.1"
|
||||
project.version = "0.17.0"
|
||||
project.group = "com.github.insanusmokrassar"
|
||||
|
||||
buildscript {
|
||||
@ -30,15 +30,15 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
||||
implementation "joda-time:joda-time:$joda_time_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
||||
api "joda-time:joda-time:$joda_time_version"
|
||||
|
||||
implementation "io.ktor:ktor-client:$ktor_version"
|
||||
implementation "io.ktor:ktor-client-cio:$ktor_version"
|
||||
api "io.ktor:ktor-client:$ktor_version"
|
||||
api "io.ktor:ktor-client-cio:$ktor_version"
|
||||
|
||||
implementation "io.ktor:ktor-server:$ktor_version"
|
||||
implementation "io.ktor:ktor-server-host-common:$ktor_version"
|
||||
api "io.ktor:ktor-server:$ktor_version"
|
||||
api "io.ktor:ktor-server-host-common:$ktor_version"
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
|
@ -1,9 +1,9 @@
|
||||
kotlin.code.style=official
|
||||
kotlin_version=1.3.31
|
||||
kotlin_coroutines_version=1.2.1
|
||||
kotlin_serialisation_runtime_version=0.11.0
|
||||
joda_time_version=2.10.1
|
||||
ktor_version=1.1.4
|
||||
kotlin_version=1.3.41
|
||||
kotlin_coroutines_version=1.2.2
|
||||
kotlin_serialisation_runtime_version=0.11.1
|
||||
joda_time_version=2.10.3
|
||||
ktor_version=1.2.3
|
||||
|
||||
gradle_bintray_plugin_version=1.8.4
|
||||
|
||||
|
@ -1,8 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
|
||||
abstract class BaseRequestsExecutor(
|
||||
token: String,
|
||||
hostUrl: String = "https://api.telegram.org"
|
||||
protected val telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
||||
) : RequestsExecutor {
|
||||
protected val baseUrl: String = "$hostUrl/bot$token"
|
||||
@Deprecated("Deprecated due to new TelegramAPIUrlKeeper API", ReplaceWith("telegramAPIUrlsKeeper.commonAPIUrl"))
|
||||
protected val baseUrl: String
|
||||
get() = telegramAPIUrlsKeeper.commonAPIUrl
|
||||
|
||||
@Deprecated("Deprecated due to new TelegramAPIUrlKeeper API")
|
||||
constructor(
|
||||
token: String,
|
||||
hostUrl: String = "https://api.telegram.org"
|
||||
) : this (TelegramAPIUrlsKeeper(token, hostUrl))
|
||||
}
|
@ -9,6 +9,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.RequestL
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.HttpClientCall
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
@ -17,22 +18,33 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class KtorRequestsExecutor(
|
||||
token: String,
|
||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||
private val client: HttpClient = HttpClient(),
|
||||
hostUrl: String = "https://api.telegram.org",
|
||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||
excludeDefaultFactories: Boolean = false,
|
||||
private val requestsLimiter: RequestLimiter = EmptyLimiter,
|
||||
private val jsonFormatter: Json = Json.nonstrict
|
||||
) : BaseRequestsExecutor(token, hostUrl) {
|
||||
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
||||
|
||||
@Deprecated("Deprecated due to new TelegramAPIUrlKeeper API")
|
||||
constructor(
|
||||
token: String,
|
||||
client: HttpClient = HttpClient(),
|
||||
hostUrl: String = "https://api.telegram.org",
|
||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||
excludeDefaultFactories: Boolean = false,
|
||||
requestsLimiter: RequestLimiter = EmptyLimiter,
|
||||
jsonFormatter: Json = Json.nonstrict
|
||||
) : this(TelegramAPIUrlsKeeper(token, hostUrl), client, callsFactories, excludeDefaultFactories, requestsLimiter, jsonFormatter)
|
||||
|
||||
@Deprecated("Deprecated due to new TelegramAPIUrlKeeper API")
|
||||
constructor(
|
||||
token: String,
|
||||
engine: HttpClientEngine? = null,
|
||||
hostUrl: String = "https://api.telegram.org"
|
||||
) : this(
|
||||
token,
|
||||
engine ?.let { HttpClient(engine) } ?: HttpClient(),
|
||||
hostUrl
|
||||
TelegramAPIUrlsKeeper(token, hostUrl),
|
||||
engine ?.let { HttpClient(engine) } ?: HttpClient()
|
||||
)
|
||||
|
||||
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
||||
@ -49,7 +61,7 @@ class KtorRequestsExecutor(
|
||||
for (factory in callsFactories) {
|
||||
call = factory.prepareCall(
|
||||
client,
|
||||
baseUrl,
|
||||
telegramAPIUrlsKeeper.commonAPIUrl,
|
||||
request
|
||||
)
|
||||
if (call != null) {
|
||||
@ -83,4 +95,8 @@ class KtorRequestsExecutor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
client.close()
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
|
||||
accept(ContentType.Application.Json)
|
||||
|
||||
body = preparedBody
|
||||
build()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapWithCommonValues
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
import io.ktor.client.request.forms.formData
|
||||
import io.ktor.client.request.forms.*
|
||||
import io.ktor.http.Headers
|
||||
import io.ktor.http.HttpHeaders
|
||||
|
||||
@ -22,7 +21,9 @@ class MultipartRequestCallFactory : AbstractRequestCallFactory() {
|
||||
when (value) {
|
||||
is MultipartFile -> append(
|
||||
key,
|
||||
value.file.asInput(),
|
||||
InputProvider {
|
||||
value.file.asInput()
|
||||
},
|
||||
Headers.build {
|
||||
append(HttpHeaders.ContentType, value.mimeType)
|
||||
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
|
||||
|
@ -2,8 +2,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import kotlinx.io.core.Closeable
|
||||
|
||||
interface RequestsExecutor {
|
||||
interface RequestsExecutor : Closeable {
|
||||
@Throws(RequestException::class)
|
||||
suspend fun <T : Any> execute(request: Request<T>): T
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.io.core.Closeable
|
||||
|
||||
interface UpdatesPoller : Closeable {
|
||||
|
@ -3,7 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.RawChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ExtendedChatSerializer
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@ -11,7 +12,7 @@ import kotlinx.serialization.*
|
||||
data class GetChat(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<RawChat> {
|
||||
): ChatRequest, SimpleRequest<ExtendedChat> {
|
||||
override fun method(): String = "getChat"
|
||||
override fun resultSerializer(): KSerializer<RawChat> = RawChat.serializer()
|
||||
override fun resultSerializer(): KSerializer<ExtendedChat> = ExtendedChatSerializer
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@ -14,14 +15,8 @@ data class RestrictChatMember(
|
||||
override val userId: UserId,
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null,
|
||||
@SerialName(canSendMessagesField)
|
||||
private val canSendMessages: Boolean? = null,
|
||||
@SerialName(canSendMediaMessagesField)
|
||||
private val canSendMediaMessages: Boolean? = null,
|
||||
@SerialName(canSendOtherMessagesField)
|
||||
private val canSendOtherMessages: Boolean? = null,
|
||||
@SerialName(canAddWebPagePreviewsField)
|
||||
private val canAddWebPagePreviews: Boolean? = null
|
||||
@SerialName(permissionsField)
|
||||
val permissions: ChatPermissions
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "restrictChatMember"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class SetChatPermissions (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(permissionsField)
|
||||
val permissions: ChatPermissions
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "setChatPermissions"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -11,7 +11,7 @@ data class SetChatStickerSet(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(stickerSetNameField)
|
||||
val stickerSetName: String
|
||||
val stickerSetName: StickerSetName
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "setChatStickerSet"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
|
||||
data class AdministratorChatMemberImpl(
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
|
||||
data class CreatorChatMember(override val user: User) : AdministratorChatMember {
|
||||
data class CreatorChatMember(override val user: User) :
|
||||
AdministratorChatMember {
|
||||
override val canBeEdited: Boolean = true
|
||||
override val canChangeInfo: Boolean = true
|
||||
override val canPostMessages: Boolean = true
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.BannedChatMember
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.TelegramDate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
|
||||
data class LeftChatMember(override val user: User) : ChatMember
|
||||
data class LeftChatMember(override val user: User) :
|
||||
ChatMember
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
|
||||
data class MemberChatMember(override val user: User) : ChatMember
|
||||
data class MemberChatMember(override val user: User) :
|
||||
ChatMember
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
@ -32,6 +33,8 @@ data class RawChatMember(
|
||||
private val canSendMessages: Boolean = false,
|
||||
@SerialName(canSendMediaMessagesField)
|
||||
private val canSendMediaMessages: Boolean = false,
|
||||
@SerialName(canSendPollsField)
|
||||
private val canSendPolls: Boolean = false,
|
||||
@SerialName(canSendOtherMessagesField)
|
||||
private val canSendOtherMessages: Boolean = false,
|
||||
@SerialName(canAddWebPagePreviewsField)
|
||||
@ -60,8 +63,12 @@ data class RawChatMember(
|
||||
isMember,
|
||||
canSendMessages,
|
||||
canSendMediaMessages,
|
||||
canSendPolls,
|
||||
canSendOtherMessages,
|
||||
canAddWebPagePreviews
|
||||
canAddWebPagePreviews,
|
||||
canChangeInfo,
|
||||
canInviteUsers,
|
||||
canPinMessages
|
||||
)
|
||||
"left" -> LeftChatMember(user)
|
||||
"kicked" -> KickedChatMember(
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.BannedChatMember
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.SpecialRightsChatMember
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.TelegramDate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
|
||||
@ -9,6 +11,10 @@ data class RestrictedChatMember(
|
||||
val isMember: Boolean,
|
||||
val canSendMessages: Boolean,
|
||||
val canSendMediaMessages: Boolean,
|
||||
val canSendPolls: Boolean,
|
||||
val canSendOtherMessages: Boolean,
|
||||
val canAddWebpagePreviews: Boolean
|
||||
) : BannedChatMember
|
||||
val canAddWebpagePreviews: Boolean,
|
||||
override val canChangeInfo: Boolean,
|
||||
override val canInviteUsers: Boolean,
|
||||
override val canPinMessages: Boolean
|
||||
) : BannedChatMember, SpecialRightsChatMember
|
@ -1,13 +1,10 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts
|
||||
|
||||
interface AdministratorChatMember : ChatMember {
|
||||
interface AdministratorChatMember : SpecialRightsChatMember {
|
||||
val canBeEdited: Boolean
|
||||
val canChangeInfo: Boolean
|
||||
val canPostMessages: Boolean
|
||||
val canEditMessages: Boolean
|
||||
val canRemoveMessages: Boolean
|
||||
val canInviteUsers: Boolean
|
||||
val canRestrictMembers: Boolean
|
||||
val canPinMessages: Boolean
|
||||
val canPromoteMembers: Boolean
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts
|
||||
|
||||
interface SpecialRightsChatMember : ChatMember {
|
||||
val canChangeInfo: Boolean
|
||||
val canInviteUsers: Boolean
|
||||
val canPinMessages: Boolean
|
||||
}
|
@ -17,6 +17,7 @@ typealias ShippingOptionIdentifier = String
|
||||
typealias StartParameter = String
|
||||
typealias InlineMessageIdentifier = String
|
||||
typealias PollIdentifier = String
|
||||
typealias StickerSetName = String
|
||||
|
||||
val callbackQueryAnswerLength = 0 until 200
|
||||
val captionLength = 0 until 1024
|
||||
@ -55,6 +56,7 @@ const val lastNameField = "last_name"
|
||||
const val languageCodeField = "language_code"
|
||||
const val textEntitiesField = "text_entities"
|
||||
const val stickerSetNameField = "set_name"
|
||||
const val stickerSetNameFullField = "sticker_set_name"
|
||||
const val maskPositionField = "mask_position"
|
||||
const val phoneNumberField = "phone_number"
|
||||
const val userIdField = "user_id"
|
||||
@ -89,6 +91,9 @@ const val forwardTextField = "forward_text"
|
||||
const val botUsernameField = "bot_username"
|
||||
const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat"
|
||||
const val switchInlineQueryField = "switch_inline_query"
|
||||
const val isAnimatedField = "is_animated"
|
||||
const val inviteLinkField = "invite_link"
|
||||
const val pinnedMessageField = "pinned_message"
|
||||
|
||||
|
||||
const val requestWriteAccessField = "request_write_access"
|
||||
@ -145,7 +150,9 @@ const val isMemberField = "is_member"
|
||||
const val canSendMessagesField = "can_send_messages"
|
||||
const val canSendMediaMessagesField = "can_send_media_messages"
|
||||
const val canSendOtherMessagesField = "can_send_other_messages"
|
||||
const val canSendPollsField = "can_send_polls"
|
||||
const val canAddWebPagePreviewsField = "can_add_web_page_previews"
|
||||
const val canSetStickerSetField = "can_set_sticker_set"
|
||||
|
||||
const val canBeEditedField = "can_be_edited"
|
||||
const val canChangeInfoField = "can_change_info"
|
||||
@ -201,6 +208,8 @@ const val certificateField = "certificate"
|
||||
const val questionField = "question"
|
||||
const val optionsField = "options"
|
||||
const val payField = "pay"
|
||||
const val permissionsField = "permissions"
|
||||
const val typeField = "type"
|
||||
|
||||
const val pointField = "point"
|
||||
const val xShiftField = "x_shift"
|
||||
|
@ -3,6 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandMarkdown
|
||||
|
||||
private val commandRegex = Regex("[/!][^@\\s]*")
|
||||
|
||||
data class BotCommandMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
@ -12,6 +14,6 @@ data class BotCommandMessageEntity(
|
||||
override val asHtmlSource: String = sourceString.commandHTML()
|
||||
|
||||
val command: String by lazy {
|
||||
sourceString.substring(1)// skip first symbol like "/" or "!"
|
||||
commandRegex.find(sourceString) ?.value ?.substring(1) ?: sourceString.substring(1)// skip first symbol like "/" or "!"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(InlineKeyboardButtonSerializer::class)
|
||||
sealed class InlineKeyboardButton {
|
||||
|
@ -1,16 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
|
||||
data class ChannelChat(
|
||||
override val id: ChatId,
|
||||
override val title: String? = null,
|
||||
override val username: Username? = null,
|
||||
override val description: String? = null,
|
||||
override val inviteLink: String? = null,
|
||||
override val chatPhoto: ChatPhoto? = null,
|
||||
override val pinnedMessage: RawMessage?
|
||||
) : PublicChat, UsernameChat, DescriptionChat
|
@ -0,0 +1,16 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.ChannelChat
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ChannelChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(usernameField)
|
||||
override val username: Username? = null
|
||||
) : ChannelChat
|
@ -1,9 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
|
||||
@Deprecated(
|
||||
"Replaced into another package",
|
||||
ReplaceWith("Chat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat")
|
||||
)
|
||||
typealias Chat = Chat
|
@ -0,0 +1,25 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ChatPermissions(
|
||||
@SerialName(canSendMessagesField)
|
||||
val canSendMessages: Boolean = false,
|
||||
@SerialName(canSendMediaMessagesField)
|
||||
val canSendMediaMessages: Boolean = false,
|
||||
@SerialName(canSendPollsField)
|
||||
val canSendPolls: Boolean = false,
|
||||
@SerialName(canSendOtherMessagesField)
|
||||
val canSendOtherMessages: Boolean = false,
|
||||
@SerialName(canAddWebPagePreviewsField)
|
||||
val canAddWebPagePreviews: Boolean = false,
|
||||
@SerialName(canChangeInfoField)
|
||||
val canChangeInfo: Boolean = false,
|
||||
@SerialName(canInviteUsersField)
|
||||
val canInviteUsers: Boolean = false,
|
||||
@SerialName(canPinMessagesField)
|
||||
val canPinMessages: Boolean = false
|
||||
)
|
@ -0,0 +1,68 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.typeField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObjectSerializer
|
||||
|
||||
object PreviewChatSerializer : KSerializer<Chat> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer")
|
||||
|
||||
override fun deserialize(decoder: Decoder): Chat {
|
||||
val decodedJson = JsonObjectSerializer.deserialize(decoder)
|
||||
|
||||
val type = decodedJson.getPrimitive(typeField).content
|
||||
|
||||
return when (type) {
|
||||
"private" -> Json.nonstrict.fromJson(PrivateChatImpl.serializer(), decodedJson)
|
||||
"group" -> Json.nonstrict.fromJson(GroupChatImpl.serializer(), decodedJson)
|
||||
"supergroup" -> Json.nonstrict.fromJson(SupergroupChatImpl.serializer(), decodedJson)
|
||||
"channel" -> Json.nonstrict.fromJson(ChannelChatImpl.serializer(), decodedJson)
|
||||
else -> throw IllegalArgumentException("Unknown type of chat")
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, obj: Chat) {
|
||||
when (obj) {
|
||||
is ExtendedChat -> ExtendedChatSerializer.serialize(encoder, obj)
|
||||
is PrivateChatImpl -> PrivateChatImpl.serializer().serialize(encoder, obj)
|
||||
is GroupChatImpl -> GroupChatImpl.serializer().serialize(encoder, obj)
|
||||
is SupergroupChatImpl -> SupergroupChatImpl.serializer().serialize(encoder, obj)
|
||||
is ChannelChatImpl -> ChannelChatImpl.serializer().serialize(encoder, obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object ExtendedChatSerializer : KSerializer<ExtendedChat> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer")
|
||||
|
||||
override fun deserialize(decoder: Decoder): ExtendedChat {
|
||||
val decodedJson = JsonObjectSerializer.deserialize(decoder)
|
||||
|
||||
val type = decodedJson.getPrimitive(typeField).content
|
||||
|
||||
return when (type) {
|
||||
"private" -> Json.nonstrict.fromJson(ExtendedPrivateChatImpl.serializer(), decodedJson)
|
||||
"group" -> Json.nonstrict.fromJson(ExtendedGroupChatImpl.serializer(), decodedJson)
|
||||
"supergroup" -> Json.nonstrict.fromJson(ExtendedSupergroupChatImpl.serializer(), decodedJson)
|
||||
"channel" -> Json.nonstrict.fromJson(ExtendedChannelChatImpl.serializer(), decodedJson)
|
||||
else -> throw IllegalArgumentException("Unknown type of chat")
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, obj: ExtendedChat) {
|
||||
when (obj) {
|
||||
is ExtendedPrivateChatImpl -> ExtendedPrivateChatImpl.serializer().serialize(encoder, obj)
|
||||
is ExtendedGroupChatImpl -> ExtendedGroupChatImpl.serializer().serialize(encoder, obj)
|
||||
is ExtendedSupergroupChatImpl -> ExtendedSupergroupChatImpl.serializer().serialize(encoder, obj)
|
||||
is ExtendedChannelChatImpl -> ExtendedChannelChatImpl.serializer().serialize(encoder, obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
|
||||
|
||||
@Deprecated(
|
||||
"Replaced into another package",
|
||||
ReplaceWith("GroupChat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat")
|
||||
)
|
||||
typealias GroupChat = GroupChat
|
@ -1,15 +1,14 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GroupChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val title: String? = null,
|
||||
override val allMembersAreAdmins: Boolean,
|
||||
override val inviteLink: String? = null,
|
||||
override val chatPhoto: ChatPhoto? = null,
|
||||
override val pinnedMessage: RawMessage? = null
|
||||
@SerialName(titleField)
|
||||
override val title: String
|
||||
) : GroupChat
|
||||
|
@ -1,13 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat
|
||||
|
||||
data class PrivateChat(
|
||||
override val id: ChatId,
|
||||
override val username: Username? = null,
|
||||
val firstName: String? = null,
|
||||
val lastName: String? = null,
|
||||
override val chatPhoto: ChatPhoto? = null
|
||||
) : Chat, UsernameChat
|
@ -0,0 +1,18 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PrivateChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
@SerialName(usernameField)
|
||||
override val username: Username? = null,
|
||||
@SerialName(firstNameField)
|
||||
override val firstName: String = "",
|
||||
@SerialName(lastNameField)
|
||||
override val lastName: String = ""
|
||||
) : PrivateChat
|
@ -1,9 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
|
||||
@Deprecated(
|
||||
"Replaced into another package",
|
||||
ReplaceWith("PublicChat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat")
|
||||
)
|
||||
typealias PublicChat = PublicChat
|
@ -1,60 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class RawChat(
|
||||
override val id: ChatId,
|
||||
private val type: String,
|
||||
private val title: String? = null,
|
||||
private val username: Username? = null,
|
||||
private val first_name: String? = null,
|
||||
private val last_name: String? = null,
|
||||
private val all_members_are_administrators: Boolean? = null,
|
||||
private val description: String? = null,
|
||||
private val invite_link: String? = null,
|
||||
private val pinned_message: RawMessage? = null,
|
||||
private val sticker_set_name: String? = null,
|
||||
private val can_set_sticker_set: Boolean? = null,
|
||||
@SerialName("photo")
|
||||
override val chatPhoto: ChatPhoto? = null
|
||||
) : Chat {
|
||||
fun extractChat(): Chat {
|
||||
return when (type) {
|
||||
"private" -> PrivateChat(id, username, first_name, last_name, chatPhoto)
|
||||
"group" -> GroupChatImpl(
|
||||
id,
|
||||
title,
|
||||
all_members_are_administrators ?: false,
|
||||
invite_link,
|
||||
chatPhoto
|
||||
)
|
||||
"supergroup" -> SupergroupChat(
|
||||
id,
|
||||
title,
|
||||
username,
|
||||
description,
|
||||
all_members_are_administrators ?: false,
|
||||
invite_link,
|
||||
chatPhoto,
|
||||
pinned_message,
|
||||
sticker_set_name,
|
||||
can_set_sticker_set ?: false
|
||||
)
|
||||
"channel" -> ChannelChat(
|
||||
id,
|
||||
title,
|
||||
username,
|
||||
description,
|
||||
invite_link,
|
||||
chatPhoto,
|
||||
pinned_message
|
||||
)
|
||||
else -> throw IllegalArgumentException("Unknown type of chat")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
|
||||
data class SupergroupChat(
|
||||
override val id: ChatId,
|
||||
override val title: String? = null,
|
||||
override val username: Username? = null,
|
||||
override val description: String? = null,
|
||||
override val allMembersAreAdmins: Boolean,
|
||||
override val inviteLink: String? = null,
|
||||
override val chatPhoto: ChatPhoto? = null,
|
||||
override val pinnedMessage: RawMessage? = null,
|
||||
val stickerSetName: String? = null,
|
||||
val canSetStickerSet: Boolean
|
||||
) : GroupChat, UsernameChat, DescriptionChat
|
@ -0,0 +1,16 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class SupergroupChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(usernameField)
|
||||
override val username: Username? = null
|
||||
) : SupergroupChat
|
@ -1,5 +1,3 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
|
||||
|
||||
interface DescriptionChat : PublicChat {
|
||||
val description: String?
|
||||
}
|
||||
interface ChannelChat : SuperPublicChat
|
@ -1,9 +1,10 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.PreviewChatSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(PreviewChatSerializer::class)
|
||||
interface Chat {
|
||||
val id: ChatId
|
||||
val chatPhoto: ChatPhoto?
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
|
||||
|
||||
interface GroupChat : PublicChat {
|
||||
val allMembersAreAdmins: Boolean
|
||||
}
|
||||
interface GroupChat : PublicChat
|
||||
|
@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
|
||||
|
||||
interface PrivateChat : Chat, UsernameChat {
|
||||
val firstName: String
|
||||
val lastName: String
|
||||
}
|
@ -1,9 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
|
||||
interface PublicChat : Chat {
|
||||
val title: String?
|
||||
val inviteLink: String?
|
||||
val pinnedMessage: RawMessage?
|
||||
val title: String
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
|
||||
|
||||
interface SuperPublicChat : PublicChat, UsernameChat
|
@ -0,0 +1,3 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
|
||||
|
||||
interface SupergroupChat : GroupChat, SuperPublicChat
|
@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.ChannelChat
|
||||
|
||||
interface ExtendedChannelChat : ChannelChat, ExtendedPublicChat
|
@ -0,0 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ExtendedChatSerializer
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ExtendedChatSerializer::class)
|
||||
interface ExtendedChat : Chat {
|
||||
val chatPhoto: ChatPhoto?
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
|
||||
|
||||
interface ExtendedGroupChat : GroupChat, ExtendedPublicChat {
|
||||
val permissions: ChatPermissions
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||
|
||||
interface ExtendedPrivateChat : PrivateChat, ExtendedChat
|
@ -0,0 +1,10 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
|
||||
interface ExtendedPublicChat : ExtendedChat, PublicChat {
|
||||
val description: String
|
||||
val inviteLink: String?
|
||||
val pinnedMessage: RawMessage?
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.StickerSetName
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat
|
||||
|
||||
interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat {
|
||||
val stickerSetName: StickerSetName?
|
||||
val canSetStickerSet: Boolean
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChannelChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ExtendedChannelChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(usernameField)
|
||||
override val username: Username? = null,
|
||||
@SerialName(photoField)
|
||||
override val chatPhoto: ChatPhoto? = null,
|
||||
@SerialName(descriptionField)
|
||||
override val description: String = "",
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String? = null,
|
||||
@SerialName(pinnedMessageField)
|
||||
override val pinnedMessage: RawMessage? = null
|
||||
) : ExtendedChannelChat
|
@ -0,0 +1,26 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedGroupChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ExtendedGroupChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(photoField)
|
||||
override val chatPhoto: ChatPhoto? = null,
|
||||
@SerialName(permissionsField)
|
||||
override val permissions: ChatPermissions,
|
||||
@SerialName(descriptionField)
|
||||
override val description: String = "",
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String? = null,
|
||||
@SerialName(pinnedMessageField)
|
||||
override val pinnedMessage: RawMessage? = null
|
||||
) : ExtendedGroupChat
|
@ -0,0 +1,20 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedPrivateChat
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ExtendedPrivateChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
@SerialName(photoField)
|
||||
override val chatPhoto: ChatPhoto? = null,
|
||||
@SerialName(usernameField)
|
||||
override val username: Username? = null,
|
||||
@SerialName(firstNameField)
|
||||
override val firstName: String = "",
|
||||
@SerialName(lastNameField)
|
||||
override val lastName: String = ""
|
||||
) : ExtendedPrivateChat
|
@ -0,0 +1,32 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedSupergroupChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ExtendedSupergroupChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(usernameField)
|
||||
override val username: Username? = null,
|
||||
@SerialName(photoField)
|
||||
override val chatPhoto: ChatPhoto? = null,
|
||||
@SerialName(permissionsField)
|
||||
override val permissions: ChatPermissions,
|
||||
@SerialName(descriptionField)
|
||||
override val description: String = "",
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String? = null,
|
||||
@SerialName(pinnedMessageField)
|
||||
override val pinnedMessage: RawMessage? = null,
|
||||
@SerialName(stickerSetNameFullField)
|
||||
override val stickerSetName: StickerSetName? = null,
|
||||
@SerialName(canSetStickerSetField)
|
||||
override val canSetStickerSet: Boolean = false
|
||||
) : ExtendedSupergroupChat
|
@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@ -15,11 +16,16 @@ data class PathedFile(
|
||||
override val fileSize: Long? = null
|
||||
): TelegramMediaFile
|
||||
|
||||
fun TelegramAPIUrlsKeeper.resolveFileURL(file: PathedFile): String = "$fileBaseUrl/${file.filePath}"
|
||||
inline fun PathedFile.fullUrl(keeper: TelegramAPIUrlsKeeper): String = keeper.resolveFileURL(this)
|
||||
|
||||
@Deprecated("Deprecated due to old API", ReplaceWith("fullUrl(telegramApiUrlsKeeper)"))
|
||||
fun PathedFile.makeFileUrl(
|
||||
botToken: String,
|
||||
apiHost: String = "https://api.telegram.org"
|
||||
) = "${downloadingFilesBaseUrl(botToken, apiHost)}/$filePath"
|
||||
|
||||
@Deprecated("Deprecated due to old API", ReplaceWith("telegramApiUrlsKeeper.fileBaseUrl"))
|
||||
fun downloadingFilesBaseUrl(
|
||||
botToken: String,
|
||||
apiHost: String
|
||||
|
@ -20,7 +20,9 @@ data class Sticker(
|
||||
@SerialName(emojiField)
|
||||
val emoji: String? = null,
|
||||
@SerialName(stickerSetNameField)
|
||||
val stickerSetName: String? = null,
|
||||
val stickerSetName: StickerSetName? = null,
|
||||
@SerialName(isAnimatedField)
|
||||
val isAnimated: Boolean = false,
|
||||
@SerialName(maskPositionField)
|
||||
val maskPosition: MaskPosition? = null,
|
||||
@SerialName(fileSizeField)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChannelChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.ChannelChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.ChannelEvent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage
|
||||
import org.joda.time.DateTime
|
||||
|
@ -4,8 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntities
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntitiesSerializer
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.games.Game
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.*
|
||||
@ -31,11 +30,11 @@ data class RawMessage(
|
||||
@SerialName(dateField)
|
||||
val date: TelegramDate,
|
||||
@SerialName(chatField)
|
||||
private val chat: RawChat,
|
||||
private val chat: Chat,
|
||||
@SerialName(fromField)
|
||||
private val from: User? = null,
|
||||
private val forward_from: User? = null,
|
||||
private val forward_from_chat: RawChat? = null,
|
||||
private val forward_from_chat: Chat? = null,
|
||||
private val forward_from_message_id: MessageIdentifier? = null,
|
||||
private val forward_signature: ForwardSignature? = null,
|
||||
private val forward_sender_name: ForwardSenderName? = null,
|
||||
@ -150,7 +149,7 @@ data class RawMessage(
|
||||
forward_from_chat != null -> ForwardedFromChannelMessage(
|
||||
forward_date,
|
||||
forward_from_message_id ?: throw IllegalStateException("Channel forwarded message must contain message id, but was not"),
|
||||
forward_from_chat.extractChat(),
|
||||
forward_from_chat,
|
||||
forward_signature
|
||||
)
|
||||
forward_from != null -> UserForwardedMessage(
|
||||
@ -194,23 +193,21 @@ data class RawMessage(
|
||||
|
||||
@Transient
|
||||
val asMessage: Message by lazy {
|
||||
val chat = chat.extractChat()
|
||||
|
||||
chatEvent ?.let {
|
||||
chatEvent ->
|
||||
when (chat) {
|
||||
is GroupChat -> GroupEventMessage(
|
||||
messageId,
|
||||
chat,
|
||||
chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent),
|
||||
date.asDate
|
||||
)
|
||||
is SupergroupChat -> SupergroupEventMessage(
|
||||
messageId,
|
||||
chat,
|
||||
chatEvent as? SupergroupEvent ?: throwWrongChatEvent(SupergroupEvent::class, chatEvent),
|
||||
date.asDate
|
||||
)
|
||||
is GroupChat -> GroupEventMessage(
|
||||
messageId,
|
||||
chat,
|
||||
chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent),
|
||||
date.asDate
|
||||
)
|
||||
is ChannelChat -> ChannelEventMessage(
|
||||
messageId,
|
||||
chat,
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.SupergroupChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.SupergroupEvent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage
|
||||
import org.joda.time.DateTime
|
||||
|
@ -10,7 +10,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AudioFile
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
|
||||
|
||||
|
@ -12,7 +12,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.biggest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaCollectionContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
|
||||
|
||||
data class PhotoContent(
|
||||
|
@ -11,7 +11,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoFile
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
|
||||
|
||||
|
@ -10,7 +10,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VoiceFile
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
|
||||
|
||||
|
@ -13,6 +13,8 @@ data class StickerSet(
|
||||
val title: String,
|
||||
@SerialName(stickersField)
|
||||
val stickers: List<Sticker>,
|
||||
@SerialName(isAnimatedField)
|
||||
val isAnimated: Boolean = false,
|
||||
@SerialName(containsMasksField)
|
||||
val containsMasks: Boolean = false
|
||||
)
|
||||
|
@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.EditChannelPostUpdate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||
|
||||
data class EditChannelPostMediaGroupUpdate(
|
||||
override val origin: EditChannelPostUpdate
|
||||
|
@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.EditMessageUpdate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||
|
||||
data class EditMessageMediaGroupUpdate(
|
||||
override val origin: EditMessageUpdate
|
||||
|
@ -18,7 +18,7 @@ import io.ktor.client.engine.cio.CIO
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
fun KtorUpdatesPoller(
|
||||
token: String,
|
||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||
timeoutSeconds: Int? = null,
|
||||
oneTimeUpdatesLimit: Int? = null,
|
||||
allowedUpdates: List<String> = ALL_UPDATES_LIST,
|
||||
@ -26,7 +26,7 @@ fun KtorUpdatesPoller(
|
||||
updatesReceiver: UpdateReceiver<Update>
|
||||
): KtorUpdatesPoller {
|
||||
val executor = KtorRequestsExecutor(
|
||||
token,
|
||||
telegramAPIUrlsKeeper,
|
||||
HttpClient(
|
||||
CIO.create {
|
||||
timeoutSeconds ?.let { _ ->
|
||||
@ -50,6 +50,25 @@ fun KtorUpdatesPoller(
|
||||
)
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated due to new TelegramAPIUrlsKeeper")
|
||||
fun KtorUpdatesPoller(
|
||||
token: String,
|
||||
timeoutSeconds: Int? = null,
|
||||
oneTimeUpdatesLimit: Int? = null,
|
||||
allowedUpdates: List<String> = ALL_UPDATES_LIST,
|
||||
exceptionsHandler: (Exception) -> Boolean = { true },
|
||||
updatesReceiver: UpdateReceiver<Update>
|
||||
): KtorUpdatesPoller {
|
||||
return KtorUpdatesPoller(
|
||||
TelegramAPIUrlsKeeper(token),
|
||||
timeoutSeconds,
|
||||
oneTimeUpdatesLimit,
|
||||
allowedUpdates,
|
||||
exceptionsHandler,
|
||||
updatesReceiver
|
||||
)
|
||||
}
|
||||
|
||||
class KtorUpdatesPoller(
|
||||
private val executor: RequestsExecutor,
|
||||
private val timeoutSeconds: Int? = null,
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
class TelegramAPIUrlsKeeper(
|
||||
token: String,
|
||||
hostUrl: String = "https://api.telegram.org"
|
||||
) {
|
||||
val commonAPIUrl = "$hostUrl/bot$token"
|
||||
val fileBaseUrl = "$hostUrl/file/bot$token"
|
||||
}
|
@ -6,8 +6,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.KtorUpdatesPoller
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter
|
||||
import kotlinx.coroutines.*
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
|
@ -11,7 +11,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.webhook.WebhookPrivateKeyConfig
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.convertWithMediaGroupUpdates
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toSentMediaGroupUpdate
|
||||
import io.ktor.application.call
|
||||
import io.ktor.request.receiveText
|
||||
import io.ktor.response.respond
|
||||
|
Loading…
Reference in New Issue
Block a user