1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-12-01 20:05:43 +00:00

Compare commits

..

31 Commits

Author SHA1 Message Date
a4bf6911c7 Update micro_utils version note 2021-01-19 00:40:29 +06:00
73b3daa68b Update micro_utils dependency 2021-01-19 00:39:46 +06:00
09748615ae optimize imports 2021-01-18 23:43:21 +06:00
2dc8521aed now all data field are predecrypted with Base64StringSerializer 2021-01-17 16:44:56 +06:00
81de59f37c fix of translations in UtilityBill 2021-01-17 16:34:05 +06:00
fb61a94c5e fix defaults in encrypted passport data 2021-01-17 16:30:25 +06:00
26fd5e51bf filesSize in PassportFile is nullable for now 2021-01-17 16:24:33 +06:00
c1ab9da4c4 fix error with deserialization of passport data 2021-01-17 16:11:38 +06:00
6b414d64b0 remove redundant imports 2021-01-17 15:45:20 +06:00
5a3edc2b44 add passportMessages extension 2021-01-17 15:43:08 +06:00
6dcdc2ab7f now PassportMessage contains user too 2021-01-17 15:35:25 +06:00
a2ae4f71de new PassportMessage type 2021-01-15 16:27:22 +06:00
5d87b86afe update passport data to use Base64StringSerializer 2021-01-15 16:02:16 +06:00
ef22735894 add base64 serialization dependency and update micro_utils up to 0.4.17 2021-01-14 21:27:58 +06:00
c0ea479fe3 add primitives for Telegram Passport API 2021-01-14 14:03:25 +06:00
0846e816e9 start 0.31.1 2021-01-14 12:37:31 +06:00
d837c9d605 update publication scripts 2021-01-13 14:21:35 +06:00
d1993842c3 Merge pull request #257 from InsanusMokrassar/0.31.0
0.31.0
2021-01-10 13:08:00 +06:00
4e8a9dcff0 update changelog 2021-01-09 22:35:41 +06:00
10eb15e172 several RiskFeature updates 2021-01-09 22:18:31 +06:00
0320da7614 updates in long polling methods 2021-01-09 22:10:38 +06:00
7aa3ff180e several refactoring things and docs appending 2021-01-09 21:50:02 +06:00
a882a212c2 remove different internal strings things 2021-01-09 21:24:13 +06:00
1b15748f65 optimize imports 2021-01-09 20:59:37 +06:00
044fe5eadf full removing of old redundant "fullEntitiesList" 2021-01-09 20:52:21 +06:00
9453ec37e7 update gradle wrapper 2021-01-09 19:01:14 +06:00
3d0cbc2d2b small refactor 2021-01-09 19:00:41 +06:00
198b551ebf deprecations removing 2021-01-09 18:25:11 +06:00
1452e32293 behaviours documentatio and changing of buildBehaviour signature 2021-01-09 18:04:45 +06:00
946b7abcae start 0.31.0 2021-01-08 16:58:25 +06:00
879943622a Merge pull request #254 from InsanusMokrassar/0.30.13
0.30.13
2021-01-08 16:50:14 +06:00
121 changed files with 784 additions and 592 deletions

View File

@@ -1,5 +1,25 @@
# TelegramBotAPI changelog
## 0.31.1
* `Common`:
* `Version`:
* `MicroUtils`: `0.4.16` -> `0.4.18`
## 0.31.0
**THIS UPDATE CONTAINS BREAKING CHANGES**
* `Common`:
* **ALL DEPRECATIONS CREATED SINCE 0.30.0 WERE REMOVED**
* `Behaviour Builder`:
* Extension `TelegramBot#buildBehaviour` have changed its return value: now it is `Job` instead of
`FlowsUpdatesFilter`
* `Utils`
* New extensions `TelegramBot#longPolling` were added as new recommended way to start getting updates via long
polling
* Old extensions `RequestsExecutor#startGettingFlowsUpdatesByLongPolling` has been deprecated
## 0.30.13
* `Common`:

View File

@@ -12,11 +12,11 @@ klock_version=2.0.3
uuid_version=0.2.3
ktor_version=1.5.0
micro_utils_version=0.4.16
micro_utils_version=0.4.18
javax_activation_version=1.1.1
library_group=dev.inmo
library_version=0.30.13
library_version=0.31.1
github_release_plugin_version=2.2.12

View File

@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip

View File

@@ -47,6 +47,7 @@ kotlin {
api "com.benasher44:uuid:$uuid_version"
api "dev.inmo:micro_utils.coroutines:$micro_utils_version"
api "dev.inmo:micro_utils.serialization.base64:$micro_utils_version"
api "io.ktor:ktor-client-core:$ktor_version"
}

View File

@@ -1 +1 @@
{"bintrayConfig":{"repo":"TelegramBotAPI","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Core","description":"Library for Object-Oriented and type-safe work with Telegram Bot API","url":"https://insanusmokrassar.github.io/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}
{"bintrayConfig":{"repo":"TelegramBotAPI","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Core","description":"Library for Object-Oriented and type-safe work with Telegram Bot API","url":"https://insanusmokrassar.github.io/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","includeGpgSigning":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}

View File

@@ -1,8 +1,12 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
task sourceJar (type : Jar) {
classifier = 'sources'
}
afterEvaluate {
project.publishing.publications.all {
@@ -10,6 +14,7 @@ afterEvaluate {
groupId "${project.group}"
if (it.name.contains('kotlinMultiplatform')) {
artifactId = "${project.name}"
artifact sourceJar
} else {
artifactId = "${project.name}-$name"
}
@@ -62,4 +67,9 @@ publishing {
}
}
}
}
signing {
useGpgCmd()
publishing.publications.forEach { sign it }
}

View File

@@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
interface Captioned {
val caption: String?
@@ -13,8 +12,7 @@ interface CaptionedOutput : Captioned {
interface CaptionedInput : Captioned {
/**
* Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
* @see [CaptionedInput.fullEntitiesList]
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
val captionEntities: List<TextPart>
}
@@ -25,10 +23,3 @@ interface CaptionedInput : Captioned {
*/
val CaptionedInput.textSources
get() = captionEntities.justTextSources()
/**
* Convert its [CaptionedInput.captionEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
@Deprecated("Currently list of entities already full. This method is redundant")
fun CaptionedInput.fullEntitiesList(): TextSourcesList = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList()

View File

@@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
interface Explained {
val explanation: String?
@@ -19,8 +18,7 @@ interface ExplainedOutput : ParsableExplainedOutput, EntitiesExplainedOutput
interface ExplainedInput : Explained {
/**
* Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
* @see [ExplainedInput.fullEntitiesList]
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
val explanationEntities: List<TextPart>
}
@@ -31,10 +29,3 @@ interface ExplainedInput : Explained {
*/
val ExplainedInput.textSources
get() = explanationEntities.justTextSources()
/**
* Convert its [ExplainedInput.explanationEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
@Deprecated("Currently list of entities already full. This method is redundant")
fun ExplainedInput.fullEntitiesList(): TextSourcesList = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList()

View File

@@ -8,10 +8,6 @@ import dev.inmo.tgbotapi.types.textLength
const val DirectInvocationOfTextSourceConstructor = "It is strongly not recommended to use constructors directly instead of factory methods"
typealias TextSourcesList = List<TextSource>
@Deprecated("All lists of TextSource in public API now are full. So, this typealias is redundant")
typealias FullTextSourcesList = List<TextSource>
@Deprecated("All lists of TextPart in public API now are full. So, this typealias is redundant")
typealias FullTextPartsList = List<TextPart>
interface TextSource {
val markdown: String
@@ -21,16 +17,6 @@ interface TextSource {
val asText: String
get() = source
@Deprecated("Rename", ReplaceWith("markdown"))
val asMarkdownSource: String
get() = markdown
@Deprecated("Rename", ReplaceWith("markdownV2"))
val asMarkdownV2Source: String
get() = markdownV2
@Deprecated("Rename", ReplaceWith("html"))
val asHtmlSource: String
get() = html
}
@Suppress("NOTHING_TO_INLINE")
@@ -43,13 +29,7 @@ inline operator fun TextSource.plus(text: String) = listOf(this, regular(text))
inline operator fun List<TextSource>.plus(text: String) = this + regular(text)
interface MultilevelTextSource : TextSource {
@Deprecated("Will be removed in near major release")
val textParts: List<TextPart>
get() = textParts(0)
val subsources: List<TextSource>
@Deprecated("Will be removed in near major release", ReplaceWith("subsources"))
val textSources: List<TextSource>
get() = subsources
}
data class TextPart(

View File

@@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
interface Texted {
val text: String?
@@ -22,7 +21,6 @@ interface TextedInput : Texted {
* Here must be full list of entities. This list must contains [TextPart]s with
* [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] in case if source text contains parts of
* regular text
* @see [CaptionedInput.fullEntitiesList]
*/
val textEntities: List<TextPart>
}
@@ -35,10 +33,3 @@ interface TextedInput : Texted {
*/
val TextedInput.textSources
get() = textEntities.justTextSources()
/**
* Convert its [TextedInput.textEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
@Deprecated("Currently list of entities already full. This method is redundant")
fun TextedInput.fullEntitiesList(): TextSourcesList = text ?.fullListOfSubSource(textEntities) ?.map { it.source } ?: emptyList()

View File

@@ -5,7 +5,8 @@ import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
import dev.inmo.tgbotapi.bot.Ktor.base.*
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.bot.exceptions.newRequestException
import dev.inmo.tgbotapi.bot.settings.limiters.*
import dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter
import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.Response
import dev.inmo.tgbotapi.utils.*
@@ -67,7 +68,7 @@ class KtorRequestsExecutor(
return safely(
{ e ->
throw if (e is ClientRequestException) {
val content = e.response ?.readText() ?: throw e
val content = e.response.readText()
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
newRequestException(
responseObject,

View File

@@ -6,7 +6,6 @@ import dev.inmo.tgbotapi.bot.exceptions.newRequestException
import dev.inmo.tgbotapi.requests.GetUpdates
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.Response
import dev.inmo.tgbotapi.types.RetryAfterError
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import io.ktor.client.HttpClient
import io.ktor.client.call.receive
@@ -14,7 +13,6 @@ import io.ktor.client.features.timeout
import io.ktor.client.request.*
import io.ktor.client.statement.HttpResponse
import io.ktor.http.ContentType
import kotlinx.coroutines.delay
import kotlinx.serialization.json.Json
import kotlin.collections.set

View File

@@ -25,10 +25,9 @@ object MultipartRequestCallFactory : AbstractRequestCallFactory() {
Headers.build {
append(HttpHeaders.ContentType, value.mimeType)
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
}
) {
value.file.asInput()
}
},
block = value.file::input
)
is FileId -> append(key, value.fileId)
else -> append(key, value.toString())
}

View File

@@ -1,7 +1,8 @@
package dev.inmo.tgbotapi.bot.exceptions
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.Response
import dev.inmo.tgbotapi.types.RetryAfterError
import io.ktor.utils.io.errors.IOException
fun newRequestException(

View File

@@ -1,15 +1,11 @@
package dev.inmo.tgbotapi.bot.settings.limiters
import com.soywiz.klock.DateTime
import dev.inmo.micro_utils.coroutines.*
import dev.inmo.tgbotapi.types.MilliSeconds
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.sync.Semaphore
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlin.coroutines.Continuation
import kotlin.math.roundToLong
private fun now(): Long = DateTime.nowUnixLong()

View File

@@ -2,11 +2,13 @@ package dev.inmo.tgbotapi.bot.settings.limiters
import dev.inmo.micro_utils.coroutines.safely
import dev.inmo.tgbotapi.bot.exceptions.TooMuchRequestsException
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MilliSeconds
import dev.inmo.tgbotapi.types.RetryAfterError
import io.ktor.client.features.ClientRequestException
import io.ktor.http.HttpStatusCode
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
/**
* This limiter will limit requests only after getting a [RetryAfterError] or [ClientRequestException] with
@@ -60,6 +62,3 @@ class ExceptionsOnlyLimiter(
}
}
}
@Deprecated("Renamed", ReplaceWith("ExceptionsOnlyLimiter", "dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter"))
typealias EmptyLimiter = ExceptionsOnlyLimiter

View File

@@ -1,9 +1,9 @@
package dev.inmo.tgbotapi.bot.settings.limiters
import dev.inmo.micro_utils.coroutines.*
import dev.inmo.micro_utils.coroutines.actor
import dev.inmo.micro_utils.coroutines.safely
import dev.inmo.tgbotapi.types.MilliSeconds
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlin.coroutines.*

View File

@@ -2,10 +2,7 @@ package dev.inmo.tgbotapi.requests.chat.modify
import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.chatIdField
import dev.inmo.tgbotapi.types.messageIdField
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer

View File

@@ -9,8 +9,6 @@ import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import kotlinx.serialization.*
fun CopyMessage(

View File

@@ -87,7 +87,7 @@ fun Poll.createRequest(
correctOptionId,
isAnonymous,
isClosed,
fullEntitiesList(),
textSources,
scheduledCloseInfo,
disableNotification,
replyToMessageId,

View File

@@ -1,7 +1,8 @@
package dev.inmo.tgbotapi.requests.webhook
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.media.base.*
import dev.inmo.tgbotapi.requests.send.media.base.DataRequest
import dev.inmo.tgbotapi.requests.send.media.base.MultipartRequestImpl
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer

View File

@@ -62,12 +62,6 @@ val inlineQueryAnswerResultsLimit = 0 .. 50
val customTitleLength = 0 .. 16
val dartsCubeAndBowlingDiceResultLimit = 1 .. 6
@Deprecated("Renamed", ReplaceWith("dartsCubeAndBowlingDiceResultLimit", "dev.inmo.tgbotapi.types.dartsCubeAndBowlingDiceResultLimit"))
val dartsAndCubeDiceResultLimit
get() = dartsCubeAndBowlingDiceResultLimit
@Deprecated("Renamed", ReplaceWith("dartsCubeAndBowlingDiceResultLimit", "dev.inmo.tgbotapi.types.dartsCubeAndBowlingDiceResultLimit"))
val diceResultLimit
get() = dartsCubeAndBowlingDiceResultLimit
val basketballAndFootballDiceResultLimit = 1 .. 5
val slotMachineDiceResultLimit = 1 .. 64
@@ -363,3 +357,13 @@ const val forceField = "force"
const val regularPollType = "regular"
const val quizPollType = "quiz"
const val dataField = "data"
const val credentialsField = "credentials"
const val hashField = "hash"
const val translationField = "translation"
const val filesField = "files"
const val frontSideField = "front_side"
const val reverseSideField = "reverse_side"
const val selfieField = "selfie"
const val secretField = "secret"

View File

@@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.WithInputMessageContentInlineQueryResult
@@ -8,10 +7,5 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.WithInp
const val inlineQueryResultAudioType = "audio"
interface InlineQueryResultAudioCommon : InlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
@@ -9,10 +8,5 @@ const val inlineQueryResultDocumentType = "document"
interface InlineQueryResultDocumentCommon : InlineQueryResult,
TitledInlineQueryResult,
DescribedInlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
@@ -8,10 +7,5 @@ const val inlineQueryResultGifType = "gif"
interface InlineQueryResultGifCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
@@ -8,10 +7,5 @@ const val inlineQueryResultMpeg4GifType = "mpeg4_gif"
interface InlineQueryResultMpeg4GifCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
@@ -9,10 +8,5 @@ const val inlineQueryResultPhotoType = "photo"
interface InlineQueryResultPhotoCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
DescribedInlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
@@ -9,10 +8,5 @@ const val inlineQueryResultVideoType = "video"
interface InlineQueryResultVideoCommon : InlineQueryResult,
TitledInlineQueryResult,
DescribedInlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@@ -1,17 +1,11 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultVoiceType = "voice"
interface InlineQueryResultVoiceCommon : InlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult,
TitledInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
TitledInlineQueryResult

View File

@@ -37,10 +37,7 @@ data class InputTextMessageContent internal constructor(
private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(disableWebPagePreviewField)
override val disableWebPagePreview: Boolean? = null
) : CaptionedOutput, TextedOutput, DisableWebPagePreview, InputMessageContent {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
) : TextedOutput, DisableWebPagePreview, InputMessageContent {
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text) ?.justTextSources()
}

View File

@@ -3,9 +3,6 @@ package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.requests.abstracts.InputFile
import kotlinx.serialization.Serializable
@Deprecated("Will be removed due to redundancy for end-side users")
fun String.toInputMediaFileAttachmentName() = "attach://$this"
@Serializable(InputMediaSerializer::class)
interface InputMedia {
val type: String

View File

@@ -42,16 +42,12 @@ data class InputMediaAnimation internal constructor(
override val height: Int? = null,
override val duration: Long? = null,
override val thumb: InputFile? = null
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, TextedOutput, CaptionedOutput {
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, TextedOutput {
override val type: String = "animation"
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
}
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
@SerialName(mediaField)
override val media: String
init { media = file.fileIdToSend } // crutch until js compiling will be fixed

View File

@@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import kotlinx.serialization.*
import kotlinx.serialization.json.Json
@@ -16,10 +15,7 @@ internal fun <T> T.buildArguments(withSerializer: SerializationStrategy<T>) = ar
)
@Serializable(MediaGroupMemberInputMediaSerializer::class)
interface MediaGroupMemberInputMedia : InputMedia, CaptionedOutput, TextedOutput {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
interface MediaGroupMemberInputMedia : InputMedia, TextedOutput {
fun serialize(format: StringFormat): String
}

View File

@@ -1,6 +1,6 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.abstracts.InputFile
interface ThumbedInputMedia : InputMedia {
val thumb: InputFile?

View File

@@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.boldMarkdown
import dev.inmo.tgbotapi.utils.internal.boldMarkdownV2
/**
* @see bold

View File

@@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.commandMarkdown
import dev.inmo.tgbotapi.utils.internal.commandMarkdownV2
private val commandRegex = Regex("[/!][^@\\s]*")

View File

@@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.cashTagMarkdown
import dev.inmo.tgbotapi.utils.internal.cashTagMarkdownV2
/**
* @see cashTag

View File

@@ -2,10 +2,8 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.codeMarkdown
import dev.inmo.tgbotapi.utils.internal.codeMarkdownV2
/**
* @see code

View File

@@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.emailMarkdown
import dev.inmo.tgbotapi.utils.internal.emailMarkdownV2
/**
* @see email

View File

@@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.hashTagMarkdown
import dev.inmo.tgbotapi.utils.internal.hashTagMarkdownV2
/**
* @see hashtag

View File

@@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.italicMarkdown
import dev.inmo.tgbotapi.utils.internal.italicMarkdownV2
/**
* @see italic

View File

@@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.mentionMarkdown
import dev.inmo.tgbotapi.utils.internal.mentionMarkdownV2
private val String.withoutCommercialAt
get() = if (startsWith("@")) {

View File

@@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.phoneMarkdown
import dev.inmo.tgbotapi.utils.internal.phoneMarkdownV2
/**
* @see phone

View File

@@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.preMarkdown
import dev.inmo.tgbotapi.utils.internal.preMarkdownV2
/**
* @see pre

View File

@@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.regularMarkdown
import dev.inmo.tgbotapi.utils.internal.regularMarkdownV2
/**
* @see regular

View File

@@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdown
import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdownV2
/**
* @see strikethrough

View File

@@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.linkMarkdown
import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2
/**
* @see link

View File

@@ -2,10 +2,8 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.textMentionMarkdown
import dev.inmo.tgbotapi.utils.internal.textMentionMarkdownV2
/**
* @see mention

View File

@@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.linkMarkdown
import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2
/**
* @see link

View File

@@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.underlineMarkdown
import dev.inmo.tgbotapi.utils.internal.underlineMarkdownV2
/**
* @see underline

View File

@@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.chat.abstracts
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer
import kotlinx.serialization.Serializable

View File

@@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.types.FileUniqueId
internal const val fileIdField = "file_id"
internal const val fileSizeField = "file_size"
internal const val fileDateField = "file_date"
internal const val filePathField = "file_path"
/**

View File

@@ -4,7 +4,6 @@ import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
data class ChannelEventMessage<T : ChannelEvent>(

View File

@@ -20,6 +20,3 @@ data class ChannelMessageImpl<T: MessageContent>(
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
) : ChannelMessage<T>
@Deprecated("Renamed", ReplaceWith("ChannelMessageImpl", "dev.inmo.tgbotapi.types.message.ChannelMessageImpl"))
typealias ChannelMessage<T> = ChannelMessageImpl<T>

View File

@@ -7,9 +7,6 @@ import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent
import dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage
@Deprecated("Renamed", ReplaceWith("CommonGroupEventMessage"))
typealias GroupEventMessage = CommonGroupEventMessage<*>
data class CommonGroupEventMessage<T : GroupEvent>(
override val messageId: MessageIdentifier,
override val user: User,

View File

@@ -4,13 +4,9 @@ import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.abstracts.SupergroupChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent
import dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage
@Deprecated("Renamed", ReplaceWith("CommonSupergroupEventMessage"))
typealias SupergroupEventMessage = CommonSupergroupEventMessage<*>
data class CommonSupergroupEventMessage<T : SupergroupEvent>(
override val messageId: MessageIdentifier,
override val user: User,

View File

@@ -0,0 +1,17 @@
package dev.inmo.tgbotapi.types.message
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.passport.PassportData
data class PassportMessage(
override val messageId: MessageIdentifier,
override val chat: Chat,
override val user: User,
override val date: DateTime,
val passportData: PassportData
) : Message, FromUserMessage

View File

@@ -22,6 +22,3 @@ data class PrivateMessageImpl<T: MessageContent>(
override val senderBot: CommonBot?,
val paymentInfo: SuccessfulPaymentInfo?
) : PrivateMessage<T>
@Deprecated("Renamed", ReplaceWith("PrivateMessageImpl", "dev.inmo.tgbotapi.types.message.PrivateMessageImpl"))
typealias CommonMessageImpl<T> = PrivateMessageImpl<T>

View File

@@ -18,6 +18,7 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.types.message.content.media.*
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
import dev.inmo.tgbotapi.types.passport.PassportData
import dev.inmo.tgbotapi.types.payments.Invoice
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
import dev.inmo.tgbotapi.types.polls.Poll
@@ -84,7 +85,7 @@ internal data class RawMessage(
private val connected_website: String? = null,
// passport property
private val passport_data: Unit? = null,
private val passport_data: PassportData? = null,
private val proximity_alert_triggered: ProximityAlertTriggered? = null,
private val reply_markup: InlineKeyboardMarkup? = null
@@ -324,6 +325,14 @@ internal data class RawMessage(
)
else -> error("Unknown type of chat: $chat")
}
} ?: passport_data ?.let{
PassportMessage(
messageId,
chat,
from ?: error("For passport must be provided user, but got null"),
date.asDate,
passport_data
)
} ?: error("Was not found supported type of data")
} catch (e: Exception) {
UnknownMessageType(

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
import dev.inmo.tgbotapi.CommonAbstracts.TextedInput
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.SendTextMessage
import dev.inmo.tgbotapi.types.ChatIdentifier
@@ -10,17 +11,11 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
import dev.inmo.tgbotapi.utils.internal.toMarkdownTexts
data class TextContent(
override val text: String,
override val textEntities: List<TextPart> = emptyList()
) : MessageContent, TextedInput {
@Deprecated("Has been renamed", ReplaceWith("textEntities"))
val entities: List<TextPart>
get() = textEntities
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
@@ -77,10 +72,3 @@ data class TextContent(
)
}
}
/**
* Convert its [TextContent.entities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
@Deprecated("Useless due to the fact that currently every message contains full list of sources")
fun TextContent.fullEntitiesList(): TextSourcesList = text.fullListOfSubSource(entities).map { it.source }

View File

@@ -0,0 +1,23 @@
package dev.inmo.tgbotapi.types.passport
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
typealias EncryptedAndBase64EncodedData = String
typealias EncryptedByBotPublicKeyData = String
typealias EncryptedData = String
@Serializable
data class EncryptedCredentials(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
val data: EncryptedData,
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
val hash: String,
@SerialName(secretField)
@Serializable(Base64StringSerializer::class)
val secret: EncryptedByBotPublicKeyData
)

View File

@@ -0,0 +1,15 @@
package dev.inmo.tgbotapi.types.passport
import dev.inmo.tgbotapi.types.credentialsField
import dev.inmo.tgbotapi.types.dataField
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class PassportData(
@SerialName(dataField)
val data: List<EncryptedPassportElement>,
@SerialName(credentialsField)
val credentials: EncryptedCredentials
)

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.tgbotapi.types.emailField
import dev.inmo.tgbotapi.types.hashField
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithEmail
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class Email(
@SerialName(emailField)
override val email: String,
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : WithEmail {
}

View File

@@ -0,0 +1,17 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.tgbotapi.types.dataField
import dev.inmo.tgbotapi.types.passport.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class EncryptedAddress(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
override val data: EncryptedData,
@Serializable(Base64StringSerializer::class)
override val hash: String
) : WithData

View File

@@ -0,0 +1,87 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
import dev.inmo.tgbotapi.types.hashField
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.UnknownEncryptedPassportElement
import dev.inmo.tgbotapi.types.typeField
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.*
@Serializer(EncryptedPassportElement::class)
object EncryptedElementSerializer : KSerializer<EncryptedPassportElement> {
private val jsonSerializer = JsonObject.serializer()
override val descriptor: SerialDescriptor = jsonSerializer.descriptor
override fun deserialize(decoder: Decoder): EncryptedPassportElement {
val json = jsonSerializer.deserialize(decoder)
return when (json[typeField] ?.jsonPrimitive ?.content) {
"personal_details" -> nonstrictJsonFormat.decodeFromJsonElement(EncryptedPersonalDetails.serializer(), json)
"passport" -> nonstrictJsonFormat.decodeFromJsonElement(CommonPassport.serializer(), json)
"driver_license" -> nonstrictJsonFormat.decodeFromJsonElement(DriverLicense.serializer(), json)
"identity_card" -> nonstrictJsonFormat.decodeFromJsonElement(IdentityCard.serializer(), json)
"internal_passport" -> nonstrictJsonFormat.decodeFromJsonElement(InternalPassport.serializer(), json)
"address" -> nonstrictJsonFormat.decodeFromJsonElement(EncryptedAddress.serializer(), json)
"utility_bill" -> nonstrictJsonFormat.decodeFromJsonElement(UtilityBill.serializer(), json)
"bank_statement" -> nonstrictJsonFormat.decodeFromJsonElement(BankStatement.serializer(), json)
"rental_agreement" -> nonstrictJsonFormat.decodeFromJsonElement(RentalAgreement.serializer(), json)
"passport_registration" -> nonstrictJsonFormat.decodeFromJsonElement(PassportRegistration.serializer(), json)
"temporary_registration" -> nonstrictJsonFormat.decodeFromJsonElement(TemporaryRegistration.serializer(), json)
"phone_number" -> nonstrictJsonFormat.decodeFromJsonElement(PhoneNumber.serializer(), json)
"email" -> nonstrictJsonFormat.decodeFromJsonElement(Email.serializer(), json)
else -> UnknownEncryptedPassportElement(json, json[hashField] ?.jsonPrimitive ?.content ?: "")
}
}
override fun serialize(encoder: Encoder, value: EncryptedPassportElement) {
val json = when (value) {
is EncryptedPersonalDetails -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(EncryptedPersonalDetails.serializer(), value).jsonObject + (typeField to JsonPrimitive("personal_details"))
)
is CommonPassport -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(CommonPassport.serializer(), value).jsonObject + (typeField to JsonPrimitive("passport"))
)
is DriverLicense -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(DriverLicense.serializer(), value).jsonObject + (typeField to JsonPrimitive("driver_license"))
)
is IdentityCard -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(IdentityCard.serializer(), value).jsonObject + (typeField to JsonPrimitive("identity_card"))
)
is InternalPassport -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(InternalPassport.serializer(), value).jsonObject + (typeField to JsonPrimitive("internal_passport"))
)
is EncryptedAddress -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(EncryptedAddress.serializer(), value).jsonObject + (typeField to JsonPrimitive("address"))
)
is UtilityBill -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(UtilityBill.serializer(), value).jsonObject + (typeField to JsonPrimitive("utility_bill"))
)
is BankStatement -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(BankStatement.serializer(), value).jsonObject + (typeField to JsonPrimitive("bank_statement"))
)
is RentalAgreement -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(RentalAgreement.serializer(), value).jsonObject + (typeField to JsonPrimitive("rental_agreement"))
)
is PassportRegistration -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(PassportRegistration.serializer(), value).jsonObject + (typeField to JsonPrimitive("passport_registration"))
)
is TemporaryRegistration -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(TemporaryRegistration.serializer(), value).jsonObject + (typeField to JsonPrimitive("temporary_registration"))
)
is PhoneNumber -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(PhoneNumber.serializer(), value).jsonObject + (typeField to JsonPrimitive("phone_number"))
)
is Email -> JsonObject(
nonstrictJsonFormat.encodeToJsonElement(Email.serializer(), value).jsonObject + (typeField to JsonPrimitive("email"))
)
is UnknownEncryptedPassportElement -> value.rawJson
else -> return
}
jsonSerializer.serialize(encoder, json)
}
}

View File

@@ -0,0 +1,17 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.tgbotapi.types.dataField
import dev.inmo.tgbotapi.types.passport.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class EncryptedPersonalDetails(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
override val data: EncryptedData,
@Serializable(Base64StringSerializer::class)
override val hash: String
) : WithData

View File

@@ -0,0 +1,42 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.passport.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
sealed class Passport : WithData, WithFrontSide, WithSelfie, Translatable
@Serializable
data class CommonPassport(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
override val data: EncryptedData,
@SerialName(frontSideField)
override val frontSide: PassportFile? = null,
@SerialName(selfieField)
override val selfie: PassportFile? = null,
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : Passport()
@Serializable
data class InternalPassport(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
override val data: EncryptedData,
@SerialName(frontSideField)
override val frontSide: PassportFile? = null,
@SerialName(selfieField)
override val selfie: PassportFile? = null,
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : Passport()

View File

@@ -0,0 +1,23 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.files.abstracts.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
/**
* This object represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format
* when decrypted and don't exceed 10MB.
*/
@Serializable
data class PassportFile(
@SerialName(fileIdField)
override val fileId: FileId,
@SerialName(fileUniqueIdField)
override val fileUniqueId: FileUniqueId,
@SerialName(fileDateField)
val uploadingDate: TelegramDate,
@SerialName(fileSizeField)
override val fileSize: Long? = null
) : TelegramMediaFile

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.tgbotapi.types.hashField
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithPhoneNumber
import dev.inmo.tgbotapi.types.phoneNumberField
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class PhoneNumber(
@SerialName(phoneNumberField)
override val phoneNumber: String,
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : WithPhoneNumber {
}

View File

@@ -0,0 +1,63 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.FilesCollection
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.Translatable
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
sealed class TranslatableFilesCollection : Translatable, FilesCollection
@Serializable
data class UtilityBill(
@SerialName(filesField)
override val files: List<PassportFile>,
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableFilesCollection()
@Serializable
data class BankStatement(
@SerialName(filesField)
override val files: List<PassportFile>,
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableFilesCollection()
@Serializable
data class RentalAgreement(
@SerialName(filesField)
override val files: List<PassportFile>,
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableFilesCollection()
@Serializable
data class PassportRegistration(
@SerialName(filesField)
override val files: List<PassportFile>,
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableFilesCollection()
@Serializable
data class TemporaryRegistration(
@SerialName(filesField)
override val files: List<PassportFile>,
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableFilesCollection()

View File

@@ -0,0 +1,47 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.passport.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
sealed class TranslatableIDDocument : WithData, WithFrontSide, WithReverseSide, WithSelfie, Translatable
@Serializable
data class DriverLicense(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
override val data: EncryptedData,
@SerialName(frontSideField)
override val frontSide: PassportFile? = null,
@SerialName(reverseSideField)
override val reverseSide: PassportFile? = null,
@SerialName(selfieField)
override val selfie: PassportFile? = null,
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableIDDocument()
@Serializable
data class IdentityCard(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
override val data: EncryptedData,
@SerialName(frontSideField)
override val frontSide: PassportFile? = null,
@SerialName(reverseSideField)
override val reverseSide: PassportFile? = null,
@SerialName(selfieField)
override val selfie: PassportFile? = null,
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableIDDocument()

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject
@Serializable(EncryptedElementSerializer::class)
interface EncryptedPassportElement {
val hash: String
}
@Serializable(EncryptedElementSerializer::class)
data class UnknownEncryptedPassportElement(
val rawJson: JsonObject,
@Serializable(Base64StringSerializer::class)
override val hash: String
) : EncryptedPassportElement

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts
import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer
import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
interface FilesCollection : EncryptedPassportElement {
val files: List<PassportFile>
}

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts
import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer
import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
interface Translatable : EncryptedPassportElement {
val translations: List<PassportFile>
}

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts
import dev.inmo.tgbotapi.types.passport.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
interface WithData : EncryptedPassportElement {
val data: EncryptedData
}

View File

@@ -0,0 +1,9 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts
import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
interface WithEmail : EncryptedPassportElement {
val email: String
}

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts
import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer
import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
interface WithFrontSide : EncryptedPassportElement {
val frontSide: PassportFile?
}

View File

@@ -0,0 +1,9 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts
import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
interface WithPhoneNumber : EncryptedPassportElement {
val phoneNumber: String
}

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts
import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer
import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
interface WithReverseSide : EncryptedPassportElement {
val reverseSide: PassportFile?
}

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts
import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer
import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
interface WithSelfie : EncryptedPassportElement {
val selfie: PassportFile?
}

View File

@@ -18,6 +18,7 @@ package dev.inmo.tgbotapi.utils
)
annotation class PreviewFeature
const val lowLevelRiskFeatureMessage = "This method is low-level and not recommended to direct use"
@RequiresOptIn(
"This feature can work unstable and may have some restrictions in Telegram System",
RequiresOptIn.Level.WARNING

View File

@@ -1,21 +0,0 @@
package dev.inmo.tgbotapi.utils
import dev.inmo.micro_utils.coroutines.ExceptionHandler
import dev.inmo.micro_utils.coroutines.safely
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.supervisorScope
@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("ExceptionHandler", "dev.inmo.micro_utils.coroutines.ExceptionHandler"))
typealias ExceptionHandler<T> = ExceptionHandler<T>
/**
* It will run [block] inside of [supervisorScope] to avoid problems with catching of exceptions
*
* @param [onException] Will be called when happen exception inside of [block]. By default will throw exception - this
* exception will be available for catching
*/
@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("safely", "dev.inmo.micro_utils.coroutines.safely"))
suspend inline fun <T> handleSafely(
noinline onException: ExceptionHandler<T> = { throw it },
noinline block: suspend CoroutineScope.() -> T
): T = safely(onException, block)

View File

@@ -5,19 +5,40 @@ import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.core.Input
import kotlinx.serialization.Serializable
/**
* Information about file for [StorageFile]
*
* @param contentType Raw type like "application/json"
* @param fileName This filename will be used in telegram system as name of file
*/
@Serializable
data class StorageFileInfo(
val contentType: String,
val fileName: String
) {
/**
* This methods is required for random generation of name for keeping warranties about unique file name
*/
fun generateCustomName() = "${uuid4()}.${fileName.fileExtension}"
}
/**
* Contains info about file, which potentially can be sent to telegram system.
*
* @param storageFileInfo Information about this file
* @param inputSource Lambda which able to allocate [Input] for uploading/manipulating data
*
* @see StorageFileInfo
* @see asStorageFile
*/
data class StorageFile(
val storageFileInfo: StorageFileInfo,
private val inputSource: () -> Input
) {
fun asInput() = inputSource()
val input: Input
get() = inputSource()
@Deprecated("This method will be fully replaced with input property", ReplaceWith("input"))
fun asInput() = input
}
@Suppress("NOTHING_TO_INLINE")
@@ -31,5 +52,8 @@ inline fun StorageFile(
ByteReadPacket(bytes)
}
@Suppress("NOTHING_TO_INLINE")
/**
*
*/
@Suppress("NOTHING_TO_INLINE", "unused")
inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType)

View File

@@ -1,55 +0,0 @@
package dev.inmo.tgbotapi.utils.internal
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.update.*
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.*
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
private inline val Pair<MediaGroupMessage, *>.message
get() = first
internal fun List<BaseMessageUpdate>.convertWithMediaGroupUpdates(): List<Update> {
val resultUpdates = mutableListOf<Update>()
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<BaseMessageUpdate>>()
for (update in this) {
val asEditMediaGroupMessage = update.toEditMediaGroupUpdate()
if (asEditMediaGroupMessage != null) {
resultUpdates.add(asEditMediaGroupMessage)
} else {
val data = update.data
if (data is MediaGroupMessage) {
(mediaGroups[data.mediaGroupId] ?: mutableListOf<BaseMessageUpdate>().also { mediaGroups[data.mediaGroupId] = it }).add(update)
} else {
resultUpdates.add(update)
}
}
}
mediaGroups.values.map {
it.toSentMediaGroupUpdate() ?.let { mediaGroupUpdate ->
resultUpdates.add(mediaGroupUpdate)
}
}
return resultUpdates.sortedBy { it.updateId }
}
internal fun List<BaseMessageUpdate>.toSentMediaGroupUpdate(): SentMediaGroupUpdate? = (this as? SentMediaGroupUpdate) ?: let {
if (isEmpty()) {
return@let null
}
val resultList = sortedBy { it.updateId }
when (first()) {
is MessageUpdate -> MessageMediaGroupUpdate(resultList)
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList)
else -> null
}
}
internal fun BaseMessageUpdate.toEditMediaGroupUpdate(): EditMediaGroupUpdate? = (this as? EditMediaGroupUpdate) ?: let {
when (this) {
is EditMessageUpdate -> EditMessageMediaGroupUpdate(this)
is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(this)
else -> null
}
}

View File

@@ -1,10 +1,10 @@
package dev.inmo.tgbotapi.utils.internal
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.ParseMode.*
import dev.inmo.tgbotapi.types.captionLength
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.content.fullEntitiesList
import dev.inmo.tgbotapi.types.textLength
internal fun createFormattedText(
entities: TextSourcesList,
@@ -56,13 +56,7 @@ internal fun TextSourcesList.toMarkdownTexts(): List<String> = createMarkdownTex
this,
textLength.last
)
internal fun TextContent.toMarkdownTexts(): List<String> = fullEntitiesList().toMarkdownTexts()
internal fun TextSourcesList.toMarkdownExplanations(): List<String> = createMarkdownText(
this,
explanationLimit.last
)
internal fun ExplainedInput.toMarkdownExplanations(): List<String> = fullEntitiesList().toMarkdownTexts()
internal fun TextContent.toMarkdownTexts(): List<String> = textSources.toMarkdownTexts()
internal fun createMarkdownV2Text(
@@ -74,19 +68,13 @@ internal fun TextSourcesList.toMarkdownV2Captions(): List<String> = createMarkdo
this,
captionLength.last
)
internal fun CaptionedInput.toMarkdownV2Captions(): List<String> = fullEntitiesList().toMarkdownV2Captions()
internal fun CaptionedInput.toMarkdownV2Captions(): List<String> = textSources.toMarkdownV2Captions()
internal fun TextSourcesList.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
this,
textLength.last
)
internal fun TextContent.toMarkdownV2Texts(): List<String> = fullEntitiesList().toMarkdownV2Texts()
internal fun TextSourcesList.toMarkdownV2Explanations(): List<String> = createMarkdownV2Text(
this,
explanationLimit.last
)
internal fun ExplainedInput.toMarkdownV2Explanations(): List<String> = fullEntitiesList().toMarkdownV2Texts()
internal fun TextContent.toMarkdownV2Texts(): List<String> = textSources.toMarkdownV2Texts()
internal fun createHtmlText(
@@ -98,12 +86,12 @@ internal fun TextSourcesList.toHtmlCaptions(): List<String> = createHtmlText(
this,
captionLength.last
)
internal fun CaptionedInput.toHtmlCaptions(): List<String> = fullEntitiesList().toHtmlCaptions()
internal fun CaptionedInput.toHtmlCaptions(): List<String> = textSources.toHtmlCaptions()
internal fun TextSourcesList.toHtmlTexts(): List<String> = createHtmlText(
this,
textLength.last
)
internal fun TextContent.toHtmlTexts(): List<String> = fullEntitiesList().toHtmlTexts()
internal fun TextContent.toHtmlTexts(): List<String> = textSources.toHtmlTexts()

View File

@@ -148,8 +148,3 @@ internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") +
internal fun MultilevelTextSource.phoneMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.phoneHTML(): String = subsources.joinSubSourcesHtml()
internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + subsources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + subsources.joinSubSourcesHtml()

View File

@@ -99,12 +99,10 @@ private inline fun String.hashTag(adapt: String.() -> String): String = if (star
}
internal fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link)
internal fun String.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
internal fun String.mentionMarkdown(): String = mention(String::toMarkdown)
internal fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
internal fun String.hashTagHTML(): String = hashTag(String::toHtml)
internal fun String.phoneMarkdown(): String = toMarkdown()
@@ -136,14 +134,6 @@ internal infix fun Pair<String, String>.link(parseMode: ParseMode): String = whe
is MarkdownV2 -> first.linkMarkdownV2(second)
}
internal infix fun String.command(parseMode: ParseMode): String = when (parseMode) {
is HTML -> commandHTML()
is Markdown -> commandMarkdown()
is MarkdownV2 -> commandMarkdownV2()
}
internal infix fun String.underline(parseMode: ParseMode): String = when (parseMode) {
is HTML -> underlineHTML()
is Markdown -> underlineMarkdown()

View File

@@ -1,8 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.CommonAbstracts.plus
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.utils.internal.*
import kotlin.test.Test
import kotlin.test.assertEquals

View File

@@ -3,7 +3,8 @@ package dev.inmo.tgbotapi.types.MessageEntity
import dev.inmo.tgbotapi.CommonAbstracts.justTextSources
import dev.inmo.tgbotapi.utils.internal.toHtmlTexts
import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Texts
import kotlin.test.*
import kotlin.test.Test
import kotlin.test.assertEquals
class TextPartsCreatingTests {
@Test

View File

@@ -1,9 +1,7 @@
package dev.inmo.tgbotapi.requests.abstracts
import dev.inmo.tgbotapi.utils.MimeType
import dev.inmo.tgbotapi.utils.StorageFile
import java.io.File
import java.io.InputStream
fun File.toInputFile() = if (exists()) {
MultipartFile(

View File

@@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.utils
import io.ktor.utils.io.streams.asInput
import java.io.File
import java.io.InputStream
import java.nio.file.Files
fun StorageFile(

View File

@@ -1 +1 @@
{"bintrayConfig":{"repo":"TelegramBotAPI","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Extensions for API","description":"API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}
{"bintrayConfig":{"repo":"TelegramBotAPI","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Extensions for API","description":"API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","includeGpgSigning":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}

View File

@@ -1,8 +1,12 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
task sourceJar (type : Jar) {
classifier = 'sources'
}
afterEvaluate {
project.publishing.publications.all {
@@ -10,6 +14,7 @@ afterEvaluate {
groupId "${project.group}"
if (it.name.contains('kotlinMultiplatform')) {
artifactId = "${project.name}"
artifact sourceJar
} else {
artifactId = "${project.name}-$name"
}
@@ -62,4 +67,9 @@ publishing {
}
}
}
}
signing {
useGpgCmd()
publishing.publications.forEach { sign it }
}

View File

@@ -45,17 +45,3 @@ fun buildBot(
TelegramAPIUrlsKeeper(token, apiUrl),
BotBuilder().apply(block).createHttpClient()
)
/**
* @return Created by [telegramBotWithCustomClientConfig] function [TelegramBot]. This executor will be preconfigured using [token] and
* [block]
*/
@Deprecated("Renamed", ReplaceWith("buildBot", "dev.inmo.tgbotapi.extensions.api.buildBot"))
fun telegramBot(
token: String,
block: BotBuilder.() -> Unit
): TelegramBot = buildBot(
token,
telegramBotAPIDefaultUrl,
block
)

View File

@@ -1,6 +1,6 @@
package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutorBuilder
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
@@ -8,23 +8,13 @@ import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.*
/**
* Allows to create bot using bot [urlsKeeper]
*/
@Deprecated("Replaced in core", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.bot.Ktor.telegramBot"))
fun telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper
): TelegramBot = dev.inmo.tgbotapi.bot.Ktor.telegramBot(
urlsKeeper
)
/**
* Allows to create bot using bot [urlsKeeper] and already prepared [client]
*/
fun telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper,
client: HttpClient
): TelegramBot = dev.inmo.tgbotapi.bot.Ktor.telegramBot(urlsKeeper) {
): TelegramBot = telegramBot(urlsKeeper) {
this.client = client
}
@@ -69,16 +59,6 @@ inline fun telegramBot(
HttpClient(clientConfig)
)
/**
* Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client]
*/
@Deprecated("Replaced in core", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.bot.Ktor.telegramBot"))
@Suppress("NOTHING_TO_INLINE")
inline fun telegramBot(
token: String,
apiUrl: String = telegramBotAPIDefaultUrl
): TelegramBot = dev.inmo.tgbotapi.bot.Ktor.telegramBot(token, apiUrl)
/**
* Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client]
*/
@@ -130,37 +110,3 @@ inline fun telegramBot(
TelegramAPIUrlsKeeper(token, apiUrl),
clientConfig
)
/**
* Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by passing [clientEngine] param and optionally
* configure [HttpClient] using [clientConfig]
*/
@Deprecated("Will be removed in next releases", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot"))
fun telegramBotWithCustomClientConfig(
urlsKeeper: TelegramAPIUrlsKeeper,
clientEngine: HttpClientEngine,
clientConfig: HttpClientConfig<*>.() -> Unit
): TelegramBot = telegramBot(
urlsKeeper,
HttpClient(clientEngine, clientConfig)
)
/**
* Allows to create bot using bot [urlsKeeper] and optionally configure [HttpClient] using [clientConfig]
*/
@Deprecated("Will be removed in next releases", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot"))
fun telegramBotWithCustomClientConfig(
urlsKeeper: TelegramAPIUrlsKeeper,
clientConfig: HttpClientConfig<*>.() -> Unit
): TelegramBot = telegramBot(
urlsKeeper,
HttpClient(clientConfig)
)
@Suppress("NOTHING_TO_INLINE")
@Deprecated("Renamed", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot"))
inline fun telegramBotWithCustomClientConfig(
token: String,
apiUrl: String = telegramBotAPIDefaultUrl,
noinline clientConfig: HttpClientConfig<*>.() -> Unit
) = telegramBot(token, apiUrl = apiUrl, clientConfig = clientConfig)

View File

@@ -5,7 +5,6 @@ import dev.inmo.tgbotapi.requests.chat.modify.UnpinChatMessage
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.message.abstracts.Message
suspend fun TelegramBot.unpinChatMessage(

View File

@@ -2,12 +2,7 @@ package dev.inmo.tgbotapi.extensions.api.send
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.send.SendVenue
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.FoursquareId
import dev.inmo.tgbotapi.types.FoursquareType
import dev.inmo.tgbotapi.types.GooglePlaceId
import dev.inmo.tgbotapi.types.GooglePlaceType
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.location.StaticLocation

View File

@@ -1 +1 @@
{"bintrayConfig":{"repo":"TelegramBotAPI","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Steps Extensions","description":"This extensions project contains tools for simple interaction with chats","url":"https://insanusmokrassar.github.io/TelegramBotAPI/tgbotapi.extensions.steps","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}
{"bintrayConfig":{"repo":"TelegramBotAPI","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Steps Extensions","description":"This extensions project contains tools for simple interaction with chats","url":"https://insanusmokrassar.github.io/TelegramBotAPI/tgbotapi.extensions.steps","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","includeGpgSigning":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}

View File

@@ -1,4 +1,5 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
@@ -66,4 +67,9 @@ publishing {
}
}
}
}
signing {
useGpgCmd()
publishing.publications.forEach { sign it }
}

View File

@@ -1,10 +1,22 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import dev.inmo.tgbotapi.utils.PreviewFeature
import kotlinx.coroutines.CoroutineScope
/**
* Use this method in case you wish to make some additional actions with [flowUpdatesFilter].
*
* **WARNING** This method WILL NOT launch any listening of updates. Use something like
* [startGettingOfUpdatesByLongPolling] or tools for work with webhooks
*
* @see [BehaviourContext]
* @see startGettingOfUpdatesByLongPolling
*/
@PreviewFeature
suspend fun TelegramBot.buildBehaviour(
scope: CoroutineScope,
flowUpdatesFilter: FlowsUpdatesFilter,
@@ -17,17 +29,26 @@ suspend fun TelegramBot.buildBehaviour(
).block()
}
/**
* Use this method to build bot behaviour and run it via long polling. In case you wish to get [FlowsUpdatesFilter] for
* additional manipulations, you must provide external [FlowsUpdatesFilter] in other [buildBehaviour] function.
*
* @see buildBehaviour
* @see BehaviourContext
* @see startGettingOfUpdatesByLongPolling
*/
@PreviewFeature
suspend fun TelegramBot.buildBehaviour(
scope: CoroutineScope,
block: BehaviourContextReceiver<Unit>
) = FlowsUpdatesFilter().also {
) = FlowsUpdatesFilter().let {
buildBehaviour(
scope,
it,
block
)
startGettingOfUpdatesByLongPolling(
updatesFilter = it,
longPolling(
it,
scope = scope
)
}

Some files were not shown because too many files have changed in this diff Show More