1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-11-16 12:00:18 +00:00

Compare commits

..

76 Commits

Author SHA1 Message Date
841ae73f7c replyWithDice 2021-02-17 17:10:21 +06:00
41b4d29917 updates in slot machine utils 2021-02-17 16:58:57 +06:00
f8b3c44146 update micro_utils 2021-02-16 13:48:32 +06:00
f0eb670c3f start 0.32.6 2021-02-16 13:47:31 +06:00
fe5d94f31e Update README.md 2021-02-13 10:09:33 +06:00
7901d0a223 Update README.md 2021-02-13 01:42:35 +06:00
799f9123ba Update README.md 2021-02-13 01:38:31 +06:00
f77f010e66 Update README.md 2021-02-11 13:38:55 +06:00
67ddf8d809 Update README.md 2021-02-11 13:37:24 +06:00
81afa46253 Update README.md 2021-02-11 13:36:53 +06:00
a5bba76f07 Update README.md 2021-02-11 13:35:06 +06:00
d882cf9c97 update readme 2021-02-11 12:06:34 +06:00
2e27b8b64d Merge pull request #295 from InsanusMokrassar/0.32.5
0.32.5
2021-02-09 19:13:42 +06:00
4df800eaa9 fix of #291 2021-02-09 19:07:31 +06:00
8d27349868 update content resends and different other things 2021-02-09 18:26:10 +06:00
2a89c41a58 fix of #292 2021-02-09 17:15:28 +06:00
098b5cc393 rewrite createAccumulatedUpdatesRetrieverFlow onto channelFlow 2021-02-09 16:33:48 +06:00
10f4817283 solution of #293 2021-02-08 19:35:32 +06:00
4449893608 fix of #294 2021-02-08 18:15:54 +06:00
3a53f41f66 start 0.32.5 2021-02-08 11:36:20 +06:00
7cd366d893 Update README.md 2021-02-07 18:02:20 +06:00
1309a4111c Merge pull request #290 from InsanusMokrassar/0.32.4
content messages renames
2021-02-07 16:59:51 +06:00
0ca815760b content messages renames 2021-02-07 16:54:48 +06:00
eca0680f2f update readme 2021-02-07 12:44:38 +06:00
d472d371ed Merge pull request #282 from InsanusMokrassar/0.32.4
0.32.4
2021-02-07 12:43:08 +06:00
4748b6813a ExceptionsOnlyLimiter now will not use Result to provide success/failure state of result 2021-02-07 12:40:05 +06:00
a2ea15d4b0 update wrapper version 2021-02-07 11:02:13 +06:00
27dc302f5d update for compiling 2021-02-06 11:53:30 +06:00
baf8ed3a77 now JVM part will be compiled with IR 2021-02-06 00:52:39 +06:00
18913af3c3 update publishing scripts 2021-02-06 00:50:51 +06:00
51871ea94c update micro_utils version 2021-02-05 16:08:45 +06:00
6a625d7b9f update publishing scripts 2021-02-05 16:08:28 +06:00
0b93b472a3 update klock 2021-02-05 14:22:42 +06:00
ff16f9a315 Update README.md 2021-02-05 01:18:38 +06:00
86bfe043a5 update dependencies 2021-02-03 23:05:17 +06:00
fa18e7299d 0.32.4 2021-02-03 22:59:37 +06:00
c986025075 Merge pull request #277 from InsanusMokrassar/0.32.3
0.32.3
2021-02-02 11:44:53 +06:00
e8a7ea9ce4 inline qieries expectators and waiters 2021-02-02 11:17:51 +06:00
30f35e5488 start 0.32.3 2021-02-02 11:07:30 +06:00
b626974ea7 Create dependabot.yml 2021-02-01 23:22:26 +06:00
128b782a27 Merge pull request #276 from InsanusMokrassar/0.32.2
0.32.2
2021-02-01 21:43:21 +06:00
dc83b8d77a fix of #275 and several other internal problems 2021-02-01 21:09:11 +06:00
2aac6c0bde start 0.32.2 2021-02-01 21:04:54 +06:00
b637d0d2a6 Merge pull request #274 from InsanusMokrassar/0.32.1
0.32.1
2021-01-30 21:06:15 +06:00
d12cba2343 replacing of withContent and requireWithContent and extending of extensions receivers types 2021-01-30 20:59:26 +06:00
450c7e6474 fix of #273 2021-01-30 20:05:07 +06:00
a35fb40a66 fix of #272 2021-01-30 19:35:53 +06:00
8731aa2c26 start 0.32.1 2021-01-30 19:33:38 +06:00
32e305537d Merge pull request #260 from InsanusMokrassar/0.32.0
0.32.0
2021-01-29 17:00:06 +06:00
ec0a10e36e fillup changelog 2021-01-29 13:28:18 +06:00
131ec4d6d5 renames of EncryptedPassportElements 2021-01-29 12:44:13 +06:00
ecc608f51a add additional variant of doInDecryptionContextWithPKCS8Key 2021-01-29 10:44:11 +06:00
040654f131 refill readme 2021-01-29 01:18:44 +06:00
9e73d0c461 add opportunity to manually set up delay for media groups webhooks 2021-01-29 00:56:47 +06:00
d67c80bc99 ClassCasts update for SecureValue 2021-01-28 22:21:21 +06:00
b0eef4f82d update ktor 2021-01-28 22:06:52 +06:00
fbe91a6321 complete preview tools for passport 2021-01-28 22:03:14 +06:00
15066c9d63 add SecureData and DecryptedCredentials 2021-01-28 17:08:25 +06:00
e0bf67d8f9 global update of passport 2021-01-28 16:03:30 +06:00
1dc3ce2fb5 add passport in API 2021-01-25 10:43:51 +06:00
0c71133969 add expectations and triggers for passport 2021-01-25 10:29:11 +06:00
1359dd549f Create regular-build.yml 2021-01-25 04:42:23 +06:00
c425e2ecc3 update classcasts 2021-01-23 21:10:57 +06:00
4d63e3a17d complete tools for handling of encrypted data 2021-01-23 20:50:46 +06:00
d34deade0d temporal state (currently tools for files decryption in JS do work 2021-01-23 18:49:41 +06:00
2f52ad45a4 add tools for passport files hashes calculation 2021-01-23 12:21:57 +06:00
1d99e632a4 fix of SetPassportDataErrors request parent interface 2021-01-22 23:40:33 +06:00
cdcfaf5a29 fixes in passport errors serialization and replacing of PassportElementError 2021-01-22 23:14:24 +06:00
f3590762f3 add PassportElementError realization 2021-01-22 23:01:37 +06:00
e0ff14b7fe update gradle wrapper 2021-01-22 21:57:23 +06:00
9983e111ec update EncryptedElementSerializer 2021-01-22 21:53:37 +06:00
08b8710772 add asAction and several variants of oneOf 2021-01-19 20:19:28 +06:00
fc71e028c4 improving work of behaviour_builder 2021-01-19 18:50:45 +06:00
30a4a7bd8b update micro_utils dependency 2021-01-19 13:52:06 +06:00
b973278b0a add note about breaking changes 2021-01-19 11:00:12 +06:00
ae2f4579e2 start 0.32.0 as a migration from 0.31.1 due to breaking changes in MediaGroupMessage type 2021-01-19 10:52:30 +06:00
159 changed files with 2791 additions and 1077 deletions

11
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "gradle" # See documentation for possible values
directory: "/tgbotapi.core" # Location of package manifests
schedule:
interval: "daily"

16
.github/workflows/regular-build.yml vendored Normal file
View File

@@ -0,0 +1,16 @@
name: Build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Gradle
run: ./gradlew build

View File

@@ -1,10 +1,119 @@
# TelegramBotAPI changelog
## 0.31.1
## 0.32.6
* `Common`:
* `Version`:
* `MicroUtils`: `0.4.16` -> `0.4.18`
* `MicroUtils`: `0.4.24` -> `0.4.25`
* `Extensions API`:
* New extension `TelegramBot#replyWithDice`
* `Extensions Utils`:
* `SlotMachineReelImages` has been renamed to `SlotMachineReelImage`
* `SlotMachineReelImage` got two built-in parameters: `text` and `number`
* New extension `String#asSlotMachineReelImage`
## 0.32.5
* `Core`:
* Add `mention` variants for user ids and receiver variants ([#294](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/294))
* Now `AbstractRequestCallFactory` will set up one-second delay for zero timeouts in `GetUpdate` requests
* Several extensions for `TelegramBotAPI` like `retrieveAccumulatedUpdates` have been added as a solution for
[#293](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/293)
* Links for `tg://user?id=<user_id>` have been updated ([#292](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/292))
* All usages of captions or texts in resends and same things have been replaced with `textSources`
* Global `defaultParseMode` has been added ([#291](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/291))
## 0.32.4
* `Common`:
* `Version`:
* `Kotlin`: `1.4.21` -> `1.4.30`
* `Klock`: `2.0.4` -> `2.0.6`
* `MicroUtils`: `0.4.23` -> `0.4.24`
* `Core`:
* Renames:
* `ChannelMessage` -> `ChannelContentMessage`
* `PublicMessage` -> `PublicContentMessage`
* `GroupMessage` -> `GroupContentMessage`
* `FromChannelGroupMessage` -> `FromChannelGroupContentMessage`
* `AnonymousGroupMessage` -> `AnonymousGroupContentMessage`
* `CommonGroupMessage` -> `CommonGroupContentMessage`
* `PrivateMessage` -> `PrivateContentMessage`
* `Extensions Utils`:
* Renames of extensions in `ClassCasts` according to changes in `Core`
## 0.32.3
* `Behaviour Builder`:
* Add expectators and waiters for inline queries
## 0.32.2
* `Core`:
* Fix of [#275](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/275)
## 0.32.1
* `Core`:
* Fix of [#272](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/272)
* `Utils`:
* Fix of [#273](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/273)
## 0.32.0
**THIS UPDATE CONTAINS BREAKING CHANGES**
* `Common`:
* `Version`:
* `MicroUtils`: `0.4.16` -> `0.4.23`
* `Klock`: `0.2.3` -> `0.2.4`
* `Ktor`: `1.5.0` -> `1.5.1`
* `Core`:
* **BREAKING CHANGE** Now `MediaGroupMessage` have a generic type related to `MediaGroupContent`
* Methods and types related to `MediaGroupMessage` have been modified according to their meanings
* **Important Change** `FlowsUpdatesFilter` now is an interface. Old class has been renamed to
`DefaultFlowsUpdatesFilter` and factory method `FlowsUpdatesFilter` has been added
* **PASSPORT** Full support of `Telegram Passport API`
* `PassportData`
* All variants of `EncryptedPassportElement`
* All variants of `SecureValue`
* All variants of `PassportElementError`
* New request `SetPassportDataErrors`
* `Credentials`:
* `EncryptedCredentials`
* `DeryptedCredentials`
* `EndDataCredentials`
* `Behaviour Builder`:
* Trigger and expectation extensions for `MessageContent` (`onContentMessage` and `waitContentMessage`)
* `onMediaGroup` has been replaced
* `waitMediaGroup` has been added
* `onVisualMediaGroup` now is just an alternative to `onVisualGallery`
* `command` and `onCommand` expectations has been added for commands `String` variant
* New extensions `BehaviourContext#oneOf`, `BehaviourContext#parallel` and `Deferred<T>#withAction`
* Several renames:
* `waitAudioMediaGroup` -> `waitAudioMediaGroupContent`
* `waitDocumentMediaGroup` -> `waitDocumentMediaGroupContent`
* `waitMediaGroup` -> `waitAnyMediaGroupContent`
* `waitVisualMediaGroup` -> `waitVisualMediaGroupContent`
* New extensions `BehaviourContext#waitPassportMessagesWith` and `BehaviourContext#waitAnyPassportMessages`
* New extensions `BehaviourContext#onPassportMessage` and `BehaviourContext#onPassportMessageWith`
* `Utils`:
* New `ClassCasts` for
* `Message`
* **PASSPORT** `EncryptedPassportElement`
* **PASSPORT** `PassportElementError`
* **PASSPORT** `SecureValue`
* Several tools for decryption have been added:
* `AESDecryptor` is available for `JVM` platform
* Extensions `EncryptedCredentials#decryptWithPKCS8PrivateKey` are available for `JVM`
platform
* Extensions `EndDataCredentials#decryptData` and `FileCredentials#decryptFile` have been added
* Several extensions `createDecryptor`
* Several extensions `doInDecryptionContextWithPKCS8Key`
* New extension `Flow#passportMessages`
* In most of webhook setting up functions/methods now available parameter `mediaGroupsDebounceTimeMillis`
* `API`:
* **PASSPORT** New extensions `TelegramBot#setPassportDataErrors`
## 0.31.0

223
README.md
View File

@@ -1,153 +1,118 @@
[Participate in our common survey ☺](https://forms.gle/q6Xf8K3fD1pPsYUw9)
# TelegramBotAPI
<details>
<summary><b>I do not wanna read a lot, just give me my bot</b></summary>
Hello! This is a set of libraries for working with Telegram Bot API.
You can simply use <a href="https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template">this template</a> (and button
<a href="https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate">Use template</a>) to get your copy of bot and start to code.
<p></p>
<b>P.S. Do not forget to look into our <a href="https://bookstack.inmo.dev/books/telegrambotapi/">minidocs</a> and
<a href="https://tgbotapi.inmo.dev/docs/index.html">kdocs</a></b>
</details>
| Common info | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI.svg?branch=master)](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)|
| Common info | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)|
| -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Useful links | [![Chat in Telegram](badges/chat.svg)](https://t.me/InMoTelegramBotAPI) [![Create bot](badges/template.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![KDocs](badges/kdocs.svg)](https://tgbotapi.inmo.dev/docs/index.html) [Examples](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/), [Mini tutorial](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
| TelegramBotAPI Core status | [![Download](https://api.bintray.com/packages/insanusmokrassar/TelegramBotAPI/tgbotapi.core/images/download.svg)](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.core/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core) |
| TelegramBotAPI API Extensions status | [![Download](https://api.bintray.com/packages/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.api/images/download.svg)](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.api/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api) |
| TelegramBotAPI Util Extensions status | [![Download](https://api.bintray.com/packages/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.utils/images/download.svg)](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.utils/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils) |
| TelegramBotAPI Behaviour Builder Extensions status | [![Download](https://api.bintray.com/packages/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.behaviour_builder/images/download.svg)](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.behaviour_builder/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder) |
| TelegramBotAPI All status | [![Download](https://api.bintray.com/packages/insanusmokrassar/TelegramBotAPI/tgbotapi/images/download.svg)](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) |
| TelegramBotAPI Core status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core) |
| TelegramBotAPI API Extensions status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api) |
| TelegramBotAPI Util Extensions status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils) |
| TelegramBotAPI Behaviour Builder Extensions status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder) |
| TelegramBotAPI All status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) |
**At the time of publication of version `0.28.0` there are errors in serialization plugins like
[kotlinx.serialization#1004](https://github.com/Kotlin/kotlinx.serialization/issues/1004). It is possible, that both JVM
and JS version may work improperly in some cases with `kotlinx.serialization` version `1.0.0-RC`**
## Examples
## What is it?
There are several things you need to do to launch examples below:
It is a complex of libraries for working with `TelegramBotAPI` in type-safe and strict way as much as it possible. In
the list of this complex currently next projects:
* Add `mavenCentral()` to your project repositories
* [Maven variant](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Including-in-your-project#pomxml)
* Add dependency `implementation "dev.inmo:tgbotapi:$tgbotapi_version"`
* Replace `tgbotapi_version` with exact version (see last one in the table above) or put variable with this name in project
* Alternative variant for maven [here](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Including-in-your-project#telegrambotapi)
* [TelegramBotAPI Core](tgbotapi.core/README.md) - core of library. In fact it is independent library and can be used alone
without any additional library
* [TelegramBotAPI API Extensions](tgbotapi.extensions.api/README.md) - contains extensions (mostly for
`RequestsExecutor`), which allows to use the core library in more pleasant way
* [TelegramBotAPI Util Extensions](tgbotapi.extensions.utils/README.md) - contains extensions for more comfortable
work with commands, updates and other different things
* [TelegramBotAPI Behaviour Builder Extensions](tgbotapi.extensions.behaviour_builder/README.md) - builder for
step-by-step handling of bot behaviour in more comfortable manner
* [TelegramBotAPI](tgbotapi/README.md) - concentration of all previously mentioned libraries
More including instructions [available here](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Including-in-your-project).
Other configuration examples:
Most part of some specific solves or unuseful
moments are describing by official [Telegram Bot API](https://core.telegram.org/bots/api).
* [For multiplatform](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/tree/master/ResenderBot)
* [For JVM](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/blob/master/GetMeBot/build.gradle)
## JavaScript notes
### Most common example
### Versions before `0.28.0`
```kotlin
suspend fun main() {
val bot = telegramBot(TOKEN)
In case if you are want to use this library inside of browser, you will need additional settings (thanks for help to [Alexander Nozik](https://research.jetbrains.org/researchers/altavir)):
<details>
<summary>Gradle build script help (for versions before 0.28.0)</summary>
```groovy
dependencies {
/* ... */
implementation "com.github.insanusmokrassar:TelegramBotAPI:$tgbot_api_version"
implementation "com.github.insanusmokrassar:TelegramBotAPI-extensions-api:$tgbot_api_version" // optional
implementation "com.github.insanusmokrassar:TelegramBotAPI-extensions-utils:$tgbot_api_version" // optional
/* Block of dependencies for correct building in browser */
implementation(npm("fs"))
implementation(npm("bufferutil"))
implementation(npm("utf-8-validate"))
implementation(npm("abort-controller"))
implementation(npm("text-encoding"))
}
/* ... */
kotlin {
target {
browser {
/* Block for fix of exception in absence of some functionality, https://github.com/ktorio/ktor/issues/1339 */
dceTask {
dceOptions {
keep("ktor-ktor-io.\$\$importsForInline\$\$.ktor-ktor-io.io.ktor.utils.io")
}
}
}
bot.buildBehaviour {
println(getMe())
onCommand("start") {
reply(it, "Hi:)")
}
}.join()
}
```
</details>
In this example you will see information about this bot at the moment of starting and answer with `Hi:)` every time it
gets message `/start`
## Ok, where should I start?
### Handling only last messages
![Libraries hierarchy](resources/TelegramBotAPI-libraries-hierarchy.svg)
```kotlin
suspend fun main() {
val bot = telegramBot(TOKEN)
In most cases, the most simple way will be to implement [TelegramBotAPI](tgbotapi/README.md) - it contains
all necessary tools for comfort usage of this library. If you want to exclude some libraries, you can implement just
[TelegramBotAPI BehaviourBuilder Extensions](tgbotapi.extensions.behaviour_builder/README.md),
[TelegramBotAPI API Extensions](tgbotapi.extensions.api/README.md),
[TelegramBotAPI Util Extensions](tgbotapi.extensions.utils/README.md) or even
[TelegramBotAPI Core](tgbotapi.core/README.md).
val flowsUpdatesFilter = FlowsUpdatesFilter()
bot.buildBehaviour(flowUpdatesFilter = flowsUpdatesFilter) {
println(getMe())
onCommand("start") {
reply(it, "Hi:)")
}
If you want to dive deeper in the core of library or develop something for it - welcome to learn more from
[TelegramBotAPI Core](tgbotapi.core/README.md) and our [Telegram Chat](https://teleg.one/InMoTelegramBotAPIChat).
Anyway, all libraries are very typical inside of them. Examples:
* In `TelegramBotAPI` common request look like `requestsExecutor.execute(SomeRequest())`
* `tgbotapi.extensions.api` typical syntax look like `requestsExecutor.someRequest()` (in most cases it would be
better to use `bot` name instead of `requestsExecutor`)
* `tgbotapi.extensions.utils` will look like `filter.filterBaseMessageUpdates(chatId).filterExactCommands(Regex("^.*$"))...`
## Build instruction
If you want to build this project or to contribute, there are several recommendations:
### Build
In case if you want to just build project, run next command:
```bash
./gradlew clean build
```
On windows:
```
gradlew.bat clean build
```
### Publishing for work with your version locally
In case, if you want to work in your other projects using your modification (or some state) of this library,
you can use next code:
```bash
./gradlew clean build publishToMavenLocal
```
On windows:
```
gradlew.bat clean build publishToMavenLocal
```
But you must remember, that in this case your local maven repo must be the first one from
your project retrieving libraries:
```groovy
repositories {
mavenLocal() // that must be the first one
jcenter()
mavenCentral()
retrieveAccumulatedUpdates(this).join()
}
}
```
Besides, for your own version you can change variable `library_version` in the file [gradle.properties](./gradle.properties).
The main difference with the previous example is that bot will get only last updates (accumulated before bot launch
and maybe some updates it got after launch)
### Build a little bit more complex behaviour
```kotlin
suspend fun main() {
val bot = telegramBot(TOKEN)
bot.buildBehaviour {
println(getMe())
val nameReplyMarkup = ReplyKeyboardMarkup(
matrix {
row {
+SimpleKeyboardButton("nope")
}
}
)
onCommand("start") {
val photo = waitPhoto(
SendTextMessage(it.chat.id, "Send me your photo please")
).first()
val name = waitText(
SendTextMessage(
it.chat.id,
"Send me your name or choose \"nope\"",
replyMarkup = nameReplyMarkup
)
).first().text.takeIf { it != "nope" }
sendPhoto(
it.chat,
photo.mediaCollection,
entities = buildEntities {
if (name != null) regular(name) // may be collapsed up to name ?.let(::regular)
}
)
}
}.join()
}
```
### More examples
You may find examples in [this project](https://github.com/InsanusMokrassar/TelegramBotAPI-examples). Besides, you are
always welcome in our [wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/About-this-project) and
[chat](https://t.me/InMoTelegramBotAPIChat).

View File

@@ -5,18 +5,18 @@ kotlin.js.generate.externals=true
kotlin.incremental=true
kotlin.incremental.js=true
kotlin_version=1.4.21
kotlin_version=1.4.30
kotlin_coroutines_version=1.4.2
kotlin_serialisation_runtime_version=1.0.1
klock_version=2.0.3
kotlin_serialisation_runtime_version=1.1.0-RC
klock_version=2.0.6
uuid_version=0.2.3
ktor_version=1.5.0
ktor_version=1.5.1
micro_utils_version=0.4.18
micro_utils_version=0.4.25
javax_activation_version=1.1.1
library_group=dev.inmo
library_version=0.31.1
library_version=0.32.6
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.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip

View File

@@ -11,9 +11,6 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/
## Compatibility
This version compatible with [4th of November 2020 update of TelegramBotAPI (version 5.0)](https://core.telegram.org/bots/api#november-4-2020).
There is only one exception of implemented functionality - Telegram Passport API, which was presented in
[August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api-changelog#august-27-2018) update. It will be implemented
as soon as possible.
## How to implement library?
@@ -149,3 +146,18 @@ Here was used `okhttp` realisation of client, but there are several others engin
available on ktor.io site for [client](https://ktor.io/clients/http-client/engines.html) and [server](https://ktor.io/quickstart/artifacts.html)
engines.
### Passport
In case you wish to work with `Telegram Passport`, currently there are several useful things, but most part of working
with decryption and handling is available only on JVM. Next snippet contains example of data decryption on JVM platform:
```kotlin
passportMessage.passportData.doInDecryptionContextWithPKCS8Key(privateKey) {
val passportDataSecureValue = passport ?.data ?: return@doInDecryptionContextWithPKCS8Key
val passportData = (passportMessage.passportData.data.firstOrNull { it is CommonPassport } ?: return@doInDecryptionContextWithPKCS8Key) as CommonPassport
val decrypted = passportDataSecureValue.decrypt(
passportData.data
) ?.decodeToString() ?: return@doInDecryptionContextWithPKCS8Key
println(decrypted)
}
```

View File

@@ -29,7 +29,9 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main.kotlinOptions.useIR = true
}
js(BOTH) {
browser()
nodejs()
@@ -46,8 +48,10 @@ kotlin {
api "com.soywiz.korlibs.klock:klock:$klock_version"
api "com.benasher44:uuid:$uuid_version"
api "dev.inmo:micro_utils.crypto:$micro_utils_version"
api "dev.inmo:micro_utils.coroutines:$micro_utils_version"
api "dev.inmo:micro_utils.serialization.base64:$micro_utils_version"
api "dev.inmo:micro_utils.serialization.encapsulator:$micro_utils_version"
api "io.ktor:ktor-client-core:$ktor_version"
}
@@ -56,6 +60,7 @@ kotlin {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
implementation project(":tgbotapi.extensions.utils")
}
}
@@ -74,7 +79,6 @@ kotlin {
implementation kotlin('test-junit')
}
}
jsTest {
dependencies {
implementation kotlin('test-junit')

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","includeGpgSigning":true,"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,"publishToMavenCentral":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}

View File

@@ -4,22 +4,6 @@ apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
task sourceJar (type : Jar) {
classifier = 'sources'
}
afterEvaluate {
project.publishing.publications.all {
// rename artifacts
groupId "${project.group}"
if (it.name.contains('kotlinMultiplatform')) {
artifactId = "${project.name}"
artifact sourceJar
} else {
artifactId = "${project.name}-$name"
}
}
}
publishing {
publications.all {
@@ -64,6 +48,16 @@ publishing {
password = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
}
}
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
@@ -71,5 +65,5 @@ publishing {
signing {
useGpgCmd()
publishing.publications.forEach { sign it }
sign publishing.publications
}

View File

@@ -16,6 +16,8 @@ import io.ktor.http.ContentType
import kotlinx.serialization.json.Json
import kotlin.collections.set
var defaultUpdateTimeoutForZeroDelay = 1000L
abstract class AbstractRequestCallFactory : KtorCallFactory {
private val methodsCache: MutableMap<String, String> = mutableMapOf()
override suspend fun <T : Any> makeCall(
@@ -41,6 +43,11 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
requestTimeoutMillis = customTimeoutMillis
socketTimeoutMillis = customTimeoutMillis
}
} else {
timeout {
requestTimeoutMillis = defaultUpdateTimeoutForZeroDelay
socketTimeoutMillis = defaultUpdateTimeoutForZeroDelay
}
}
}
}

View File

@@ -17,7 +17,9 @@ class CommonLimiter(
@Transient
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
) : RequestLimiter {
@Transient
private val quotaSemaphore = Semaphore(lockCount)
@Transient
private val counterRegeneratorJob = scope.launch {
val regenDelay: MilliSeconds = (regenTime.toDouble() / lockCount).roundToLong()
while (isActive) {

View File

@@ -37,11 +37,12 @@ class ExceptionsOnlyLimiter(
override suspend fun <T> limit(block: suspend () -> T): T {
while (true) {
lockState.first { !it }
var throwable: Throwable? = null
val result = safely({
when (it) {
throwable = when (it) {
is TooMuchRequestsException -> {
lock(it.retryAfter.leftToRetry)
Result.failure(it)
it
}
is ClientRequestException -> {
if (it.response.status == HttpStatusCode.TooManyRequests) {
@@ -49,15 +50,16 @@ class ExceptionsOnlyLimiter(
} else {
throw it
}
Result.failure(it)
it
}
else -> throw it
}
null
}) {
Result.success(block())
block()
}
if (result.isSuccess) {
return result.getOrNull()!!
if (throwable == null) {
return result!!
}
}
}

View File

@@ -0,0 +1,22 @@
package dev.inmo.tgbotapi.requests
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.passport.PassportElementError
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
@Serializable
data class SetPassportDataErrors(
@SerialName(userIdField)
val user: UserId,
@SerialName(errorsField)
val errors: List<PassportElementError>
) : SimpleRequest<Boolean> {
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer()
override fun method(): String = "setPassportDataErrors"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -16,7 +16,7 @@ data class AnswerCallbackQuery(
val showAlert: Boolean? = null,
@SerialName(urlField)
val url: String? = null,
@SerialName(cachedTimeField)
@SerialName(cacheTimeField)
val cachedTimeSeconds: Int? = null
) : SimpleRequest<Boolean> {
override fun method(): String = "answerCallbackQuery"

View File

@@ -16,7 +16,7 @@ data class AnswerInlineQuery(
@Serializable(InlineQueryAnswersResultsSerializer::class)
@SerialName(resultsField)
val results: List<InlineQueryResult> = emptyList(),
@SerialName(cachedTimeField)
@SerialName(cacheTimeField)
val cachedTime: Int? = null,
@SerialName(isPersonalField)
val isPersonal: Boolean? = null,

View File

@@ -18,6 +18,8 @@ data class SetChatPhoto (
override fun method(): String = "setChatPhoto"
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer()
@Transient
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
@Transient
override val paramsJson: JsonObject = toJson(serializer())
}

View File

@@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.utils.throwRangeError
import kotlinx.serialization.*
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
const val editMessageLiveLocationMethod = "editMessageLiveLocation"
@Serializable
data class EditChatMessageLiveLocation(
@@ -30,7 +31,7 @@ data class EditChatMessageLiveLocation(
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage<LocationContent>, EditReplyMessage, EditLocationMessage {
override fun method(): String = "editMessageLiveLocation"
override fun method(): String = editMessageLiveLocationMethod
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>

View File

@@ -23,7 +23,7 @@ data class EditInlineMessageLiveLocation(
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditInlineMessage, EditReplyMessage, EditLocationMessage {
override fun method(): String = "editMessageLiveLocation"
override fun method(): String = editMessageLiveLocationMethod
override val requestSerializer: SerializationStrategy<*>
get() = serializer()

View File

@@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.types.message.content.LocationContent
import kotlinx.serialization.*
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
const val stopMessageLiveLocationMethod = "stopMessageLiveLocation"
@Serializable
data class StopChatMessageLiveLocation(
@@ -20,7 +21,7 @@ data class StopChatMessageLiveLocation(
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage<LocationContent>, EditReplyMessage {
override fun method(): String = "stopMessageLiveLocation"
override fun method(): String = stopMessageLiveLocationMethod
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
get() = commonResultDeserializer
override val requestSerializer: SerializationStrategy<*>

View File

@@ -13,7 +13,7 @@ data class StopInlineMessageLiveLocation(
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditInlineMessage, EditReplyMessage {
override fun method(): String = "stopMessageLiveLocation"
override fun method(): String = stopMessageLiveLocationMethod
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.requests.edit.text
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.edit.abstracts.*
import dev.inmo.tgbotapi.requests.edit.media.editMessageMediaMethod
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
@@ -55,10 +54,10 @@ data class EditInlineMessageText internal constructor(
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
rawEntities ?.asTextParts(text) ?.justTextSources()
}
override fun method(): String = editMessageMediaMethod
override fun method(): String = editMessageTextMethod
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -8,6 +8,10 @@ import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InputMedia.*
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.media.AudioContent
import dev.inmo.tgbotapi.types.message.content.media.DocumentContent
import dev.inmo.tgbotapi.utils.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.ListSerializer
@@ -17,13 +21,13 @@ const val rawSendingMediaGroupsWarning = "Media groups contains restrictions rel
" types. Currently it is possible to combine photo + video OR audio OR documents"
@RiskFeature(rawSendingMediaGroupsWarning)
fun SendMediaGroup(
fun <T : MediaGroupContent> SendMediaGroup(
chatId: ChatIdentifier,
media: List<MediaGroupMemberInputMedia>,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
): Request<List<MediaGroupMessage>> {
): Request<List<MediaGroupMessage<T>>> {
if (media.size !in mediaCountInMediaGroup) {
throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size)
}
@@ -47,14 +51,14 @@ fun SendMediaGroup(
allowSendingWithoutReply
)
return if (files.isEmpty()) {
return (if (files.isEmpty()) {
data
} else {
MultipartRequestImpl(
data,
SendMediaGroupFiles(files)
)
}
}) as Request<List<MediaGroupMessage<T>>>
}
/**
@@ -69,7 +73,7 @@ inline fun SendPlaylist(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply)
) = SendMediaGroup<AudioContent>(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply)
/**
* Use this method to be sure that you are correctly sending documents media group
@@ -83,7 +87,7 @@ inline fun SendDocumentsGroup(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply)
) = SendMediaGroup<DocumentContent>(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply)
/**
* Use this method to be sure that you are correctly sending visual media group
@@ -98,9 +102,9 @@ inline fun SendVisualMediaGroup(
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply)
) = SendMediaGroup<VisualMediaGroupContent>(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply)
private val messagesListSerializer: KSerializer<List<MediaGroupMessage>>
private val messagesListSerializer: KSerializer<List<MediaGroupMessage<MediaGroupContent>>>
= ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass())
@Serializable
@@ -114,7 +118,7 @@ data class SendMediaGroupData internal constructor(
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(allowSendingWithoutReplyField)
override val allowSendingWithoutReply: Boolean? = null
) : DataRequest<List<MediaGroupMessage>>, SendMessageRequest<List<MediaGroupMessage>> {
) : DataRequest<List<MediaGroupMessage<MediaGroupContent>>>, SendMessageRequest<List<MediaGroupMessage<MediaGroupContent>>> {
@SerialName(mediaField)
private val convertedMedia: String
get() = buildJsonArray {
@@ -127,7 +131,7 @@ data class SendMediaGroupData internal constructor(
override fun method(): String = "sendMediaGroup"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override val resultDeserializer: DeserializationStrategy<List<MediaGroupMessage>>
override val resultDeserializer: DeserializationStrategy<List<MediaGroupMessage<MediaGroupContent>>>
get() = messagesListSerializer
}

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.requests.send.polls
import com.soywiz.klock.DateTime
import com.soywiz.klock.TimeSpan
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
@@ -16,6 +17,11 @@ import kotlinx.serialization.*
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
private inline val ApproximateScheduledCloseInfo.openPeriod
get() = openDuration.millisecondsLong.div(1000)
private inline val ExactScheduledCloseInfo.closeDate
get() = closeDateTime.unixMillisLong.div(1000)
private fun checkPollInfo(
question: String,
options: List<String>
@@ -138,12 +144,23 @@ sealed class SendPoll : SendMessageRequest<ContentMessage<PollContent>>,
abstract val options: List<String>
abstract val isAnonymous: Boolean
abstract val isClosed: Boolean
abstract val closeInfo: ScheduledCloseInfo?
abstract val type: String
internal abstract val openPeriod: LongSeconds?
internal abstract val closeDate: LongSeconds?
protected val creationDate = DateTime.now()
open val closeInfo: ScheduledCloseInfo?
get() {
val openPeriod = openPeriod
val closeDate = closeDate
return when {
openPeriod != null -> openPeriod.asApproximateScheduledCloseInfo(creationDate)
closeDate != null -> closeDate.asExactScheduledCloseInfo
else -> null
}
}
override fun method(): String = "sendPoll"
override val resultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
get() = commonResultDeserializer
@@ -163,8 +180,10 @@ data class SendRegularPoll(
override val isClosed: Boolean = false,
@SerialName(allowsMultipleAnswersField)
val allowMultipleAnswers: Boolean = false,
@Transient
override val closeInfo: ScheduledCloseInfo? = null,
@SerialName(openPeriodField)
override val openPeriod: LongSeconds?= null,
@SerialName(closeDateField)
override val closeDate: LongSeconds?,
@SerialName(disableNotificationField)
override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField)
@@ -178,20 +197,39 @@ data class SendRegularPoll(
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
@SerialName(openPeriodField)
override val openPeriod: LongSeconds?
= (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.millisecondsLong ?.div(1000)
@SerialName(closeDateField)
override val closeDate: LongSeconds?
= (closeInfo as? ExactScheduledCloseInfo) ?.closeDateTime ?.unixMillisLong ?.div(1000)
init {
checkPollInfo(question, options)
closeInfo ?.checkSendData()
}
}
fun SendRegularPoll(
chatId: ChatIdentifier,
question: String,
options: List<String>,
isAnonymous: Boolean = true,
isClosed: Boolean = false,
allowMultipleAnswers: Boolean = false,
closeInfo: ScheduledCloseInfo? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = SendRegularPoll(
chatId,
question,
options,
isAnonymous,
isClosed,
allowMultipleAnswers,
(closeInfo as? ApproximateScheduledCloseInfo) ?.openPeriod,
(closeInfo as? ExactScheduledCloseInfo) ?.closeDate,
disableNotification,
replyToMessageId,
allowSendingWithoutReply,
replyMarkup
)
fun SendQuizPoll(
chatId: ChatIdentifier,
question: String,
@@ -253,6 +291,39 @@ fun SendQuizPoll(
replyMarkup
)
internal fun SendQuizPoll(
chatId: ChatIdentifier,
question: String,
options: List<String>,
correctOptionId: Int,
isAnonymous: Boolean = true,
isClosed: Boolean = false,
explanation: String? = null,
parseMode: ParseMode? = null,
rawEntities: List<RawMessageEntity>? = null,
closeInfo: ScheduledCloseInfo? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = SendQuizPoll(
chatId,
question,
options,
correctOptionId,
isAnonymous,
isClosed,
explanation,
parseMode,
rawEntities,
(closeInfo as? ApproximateScheduledCloseInfo) ?.openPeriod,
(closeInfo as? ExactScheduledCloseInfo) ?.closeDate,
disableNotification,
replyToMessageId,
allowSendingWithoutReply,
replyMarkup
)
@Serializable
data class SendQuizPoll internal constructor(
@SerialName(chatIdField)
@@ -273,8 +344,10 @@ data class SendQuizPoll internal constructor(
override val parseMode: ParseMode? = null,
@SerialName(explanationEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null,
@Transient
override val closeInfo: ScheduledCloseInfo? = null,
@SerialName(openPeriodField)
override val openPeriod: LongSeconds? = null,
@SerialName(closeDateField)
override val closeDate: LongSeconds? = null,
@SerialName(disableNotificationField)
override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField)
@@ -291,14 +364,6 @@ data class SendQuizPoll internal constructor(
rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources()
}
@SerialName(openPeriodField)
override val openPeriod: LongSeconds?
= (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.millisecondsLong ?.div(1000)
@SerialName(closeDateField)
override val closeDate: LongSeconds?
= (closeInfo as? ExactScheduledCloseInfo) ?.closeDateTime ?.unixMillisLong ?.div(1000)
init {
checkPollInfo(question, options)
closeInfo ?.checkSendData()

View File

@@ -1,5 +1,7 @@
package dev.inmo.tgbotapi.types
import dev.inmo.micro_utils.common.Warning
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import kotlinx.serialization.*
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@@ -17,9 +19,20 @@ data class ChatId(
val chatId: Identifier
) : ChatIdentifier()
val ChatId.link: String
get() = "tg://user?id=$chatId"
/**
* https://core.telegram.org/bots/api#formatting-options
*/
@Warning("This API have restrictions in Telegram System")
val Identifier.link: String
get() = "tg://user?id=$this"
/**
* https://core.telegram.org/bots/api#formatting-options
*/
@Warning("This API have restrictions in Telegram System")
val UserId.link: String
get() = chatId.link
val User.link: String
get() = id.link
typealias UserId = ChatId

View File

@@ -123,7 +123,7 @@ const val callbackQueryIdField = "callback_query_id"
const val inlineQueryIdField = "inline_query_id"
const val inlineKeyboardField = "inline_keyboard"
const val showAlertField = "show_alert"
const val cachedTimeField = "cached_time"
const val cacheTimeField = "cache_time"
const val foursquareIdField = "foursquare_id"
const val foursquareTypeField = "foursquare_type"
const val googlePlaceIdField = "google_place_id"
@@ -362,8 +362,34 @@ const val dataField = "data"
const val credentialsField = "credentials"
const val hashField = "hash"
const val translationField = "translation"
const val translationFileField = "translation_file"
const val fileField = "file"
const val filesField = "files"
const val translationFilesField = "translation_files"
const val frontSideField = "front_side"
const val reverseSideField = "reverse_side"
const val selfieField = "selfie"
const val secretField = "secret"
const val errorsField = "errors"
const val sourceField = "source"
const val fieldNameField = "field_name"
const val dataHashField = "data_hash"
const val fileHashField = "file_hash"
const val fileHashesField = "file_hashes"
const val messageField = "message"
const val unspecifiedField = "unspecified"
const val secureDataField = "secure_data"
const val nonceField = "nonce"
const val personalDetailsField = "personal_details"
const val passportField = "passport"
const val internalPassportField = "internal_passport"
const val driverLicenseField = "driver_license"
const val identityCardField = "identity_card"
const val utilityBillField = "utility_bill"
const val bankStatementField = "bank_statement"
const val rentalAgreementField = "rental_agreement"
const val passportRegistrationField = "passport_registration"
const val temporaryRegistrationField = "temporary_registration"

View File

@@ -74,3 +74,15 @@ fun AudioFile.toInputMediaAudio(
title,
thumb ?.fileId
)
fun AudioFile.toInputMediaAudio(
textSources: TextSourcesList = emptyList(),
title: String? = this.title
): InputMediaAudio = InputMediaAudio(
fileId,
textSources,
duration,
performer,
title,
thumb ?.fileId
)

View File

@@ -70,3 +70,11 @@ fun DocumentFile.toInputMediaDocument(
parseMode,
thumb ?.fileId
)
fun DocumentFile.toInputMediaDocument(
textSources: TextSourcesList = emptyList()
) = InputMediaDocument(
fileId,
textSources,
thumb ?.fileId
)

View File

@@ -53,3 +53,10 @@ fun PhotoSize.toInputMediaPhoto(
caption,
parseMode
)
fun PhotoSize.toInputMediaPhoto(
textSources: TextSourcesList = emptyList()
): InputMediaPhoto = InputMediaPhoto(
fileId,
textSources
)

View File

@@ -1,7 +1,7 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
@@ -21,6 +21,26 @@ data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstr
@Suppress("NOTHING_TO_INLINE")
inline fun mention(parts: List<TextSource>, user: User) = TextMentionTextSource(parts.makeString(), user, parts)
@Suppress("NOTHING_TO_INLINE")
inline fun User.mention(parts: List<TextSource>) = mention(parts, this)
@Suppress("NOTHING_TO_INLINE")
inline fun mention(parts: List<TextSource>, userId: UserId) = mention(parts, CommonUser(userId, ""))
@Suppress("NOTHING_TO_INLINE")
inline fun UserId.mention(parts: List<TextSource>) = mention(parts, this)
@Suppress("NOTHING_TO_INLINE")
inline fun mention(parts: List<TextSource>, id: Identifier) = mention(parts, UserId(id))
@Suppress("NOTHING_TO_INLINE")
inline fun Identifier.mention(parts: List<TextSource>) = mention(parts, this)
@Suppress("NOTHING_TO_INLINE")
inline fun mention(user: User, vararg parts: TextSource) = mention(parts.toList(), user)
@Suppress("NOTHING_TO_INLINE")
inline fun mention(text: String, user: User) = mention(user, regular(text))
@Suppress("NOTHING_TO_INLINE")
inline fun User.mention(text: String) = mention(this, regular(text))
@Suppress("NOTHING_TO_INLINE")
inline fun mention(text: String, userId: UserId) = mention(text, CommonUser(userId, ""))
@Suppress("NOTHING_TO_INLINE")
inline fun UserId.mention(text: String) = mention(text, this)
@Suppress("NOTHING_TO_INLINE")
inline fun mention(text: String, id: Identifier) = mention(text, UserId(id))
@Suppress("NOTHING_TO_INLINE")
inline fun Identifier.mention(text: String) = mention(text, this)

View File

@@ -35,12 +35,21 @@ typealias Markdown = MarkdownParseMode
typealias MarkdownV2 = MarkdownV2ParseMode
typealias HTML = HTMLParseMode
/**
* This variable respects to default parse mode used in places like next:
*
* * [dev.inmo.tgbotapi.types.message.content.TextContent.createResends]
* *
*/
var defaultParseMode: ParseMode = HTML
@Serializer(ParseMode::class)
internal object ParseModeSerializerObject : KSerializer<ParseMode> {
override fun deserialize(decoder: Decoder): ParseMode {
return when (decoder.decodeString()) {
MarkdownParseMode.parseModeName -> MarkdownParseMode
HTMLParseMode.parseModeName -> HTMLParseMode
Markdown.parseModeName -> Markdown
MarkdownV2.parseModeName -> MarkdownV2
HTML.parseModeName -> HTML
else -> throw IllegalArgumentException("Unknown parse mode")
}
}

View File

@@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.types.files
import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo
@@ -44,3 +45,15 @@ inline fun VideoFile.toInputMediaVideo(
duration,
thumb ?.fileId
)
@Suppress("NOTHING_TO_INLINE")
inline fun VideoFile.toInputMediaVideo(
textSources: TextSourcesList
) = InputMediaVideo(
fileId,
textSources,
width,
height,
duration,
thumb ?.fileId
)

View File

@@ -9,14 +9,14 @@ import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
data class ChannelMediaGroupMessage(
data class ChannelMediaGroupMessage<T : MediaGroupContent>(
override val messageId: MessageIdentifier,
override val chat: Chat,
override val date: DateTime,
override val mediaGroupId: MediaGroupIdentifier,
override val content: MediaGroupContent,
override val content: T,
override val editDate: DateTime?,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?
) : MediaGroupMessage
) : MediaGroupMessage<T>

View File

@@ -4,11 +4,11 @@ import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
import dev.inmo.tgbotapi.types.message.abstracts.ChannelMessage
import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
data class ChannelMessageImpl<T: MessageContent>(
data class ChannelContentMessageImpl<T: MessageContent>(
override val messageId: MessageIdentifier,
override val chat: ChannelChat,
override val content: T,
@@ -19,4 +19,6 @@ data class ChannelMessageImpl<T: MessageContent>(
override val replyMarkup: InlineKeyboardMarkup?,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
) : ChannelMessage<T>
) : ChannelContentMessage<T>
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("ChannelContentMessageImpl", "dev.inmo.tgbotapi.types.message.ChannelContentMessageImpl"))
typealias ChannelMessageImpl<T> = ChannelContentMessageImpl<T>

View File

@@ -7,15 +7,15 @@ import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
data class CommonMediaGroupMessage(
data class CommonMediaGroupMessage<T : MediaGroupContent>(
override val messageId: MessageIdentifier,
override val user: User,
override val chat: Chat,
override val date: DateTime,
override val mediaGroupId: MediaGroupIdentifier,
override val content: MediaGroupContent,
override val content: T,
override val editDate: DateTime?,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?
) : MediaGroupMessage, FromUserMessage
) : MediaGroupMessage<T>, FromUserMessage

View File

@@ -8,7 +8,7 @@ import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
data class FromChannelGroupMessageImpl<T : MessageContent>(
data class FromChannelGroupContentMessageImpl<T : MessageContent>(
override val chat: GroupChat,
override val channel: ChannelChat,
override val messageId: MessageIdentifier,
@@ -20,9 +20,11 @@ data class FromChannelGroupMessageImpl<T : MessageContent>(
override val content: T,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
) : FromChannelGroupMessage<T>
) : FromChannelGroupContentMessage<T>
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("FromChannelGroupContentMessageImpl", "dev.inmo.tgbotapi.types.message.FromChannelGroupContentMessageImpl"))
typealias FromChannelGroupMessageImpl<T> = FromChannelGroupContentMessageImpl<T>
data class AnonymousGroupMessageImpl<T : MessageContent>(
data class AnonymousGroupContentMessageImpl<T : MessageContent>(
override val chat: GroupChat,
override val messageId: MessageIdentifier,
override val date: DateTime,
@@ -33,9 +35,11 @@ data class AnonymousGroupMessageImpl<T : MessageContent>(
override val content: T,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
) : AnonymousGroupMessage<T>
) : AnonymousGroupContentMessage<T>
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("AnonymousGroupContentMessageImpl", "dev.inmo.tgbotapi.types.message.AnonymousGroupContentMessageImpl"))
typealias AnonymousGroupMessageImpl<T> = AnonymousGroupContentMessageImpl<T>
data class CommonGroupMessageImpl<T : MessageContent>(
data class CommonGroupContentMessageImpl<T : MessageContent>(
override val chat: GroupChat,
override val messageId: MessageIdentifier,
override val user: User,
@@ -46,4 +50,6 @@ data class CommonGroupMessageImpl<T : MessageContent>(
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?
) : CommonGroupMessage<T>
) : CommonGroupContentMessage<T>
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("CommonGroupContentMessageImpl", "dev.inmo.tgbotapi.types.message.CommonGroupContentMessageImpl"))
typealias CommonGroupMessageImpl<T> = CommonGroupContentMessageImpl<T>

View File

@@ -4,12 +4,11 @@ import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.PrivateMessage
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
data class PrivateMessageImpl<T: MessageContent>(
data class PrivateContentMessageImpl<T: MessageContent>(
override val messageId: MessageIdentifier,
override val user: User,
override val chat: Chat,
@@ -21,4 +20,6 @@ data class PrivateMessageImpl<T: MessageContent>(
override val replyMarkup: InlineKeyboardMarkup?,
override val senderBot: CommonBot?,
val paymentInfo: SuccessfulPaymentInfo?
) : PrivateMessage<T>
) : PrivateContentMessage<T>
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("PrivateContentMessageImpl", "dev.inmo.tgbotapi.types.message.PrivateContentMessageImpl"))
typealias PrivateMessageImpl<T> = PrivateContentMessageImpl<T>

View File

@@ -256,7 +256,7 @@ internal data class RawMessage(
}
} ?: when (chat) {
is PublicChat -> when (chat) {
is ChannelChat -> ChannelMessageImpl(
is ChannelChat -> ChannelContentMessageImpl(
messageId,
chat,
content,
@@ -269,7 +269,7 @@ internal data class RawMessage(
author_signature
)
is GroupChat -> when (sender_chat) {
is ChannelChat -> FromChannelGroupMessageImpl(
is ChannelChat -> FromChannelGroupContentMessageImpl(
chat,
sender_chat,
messageId,
@@ -282,7 +282,7 @@ internal data class RawMessage(
via_bot,
author_signature
)
is GroupChat -> AnonymousGroupMessageImpl(
is GroupChat -> AnonymousGroupContentMessageImpl(
chat,
messageId,
date.asDate,
@@ -294,7 +294,7 @@ internal data class RawMessage(
via_bot,
author_signature
)
null -> CommonGroupMessageImpl(
null -> CommonGroupContentMessageImpl(
chat,
messageId,
from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"),
@@ -310,7 +310,7 @@ internal data class RawMessage(
}
else -> error("Unknown type of public chat: $chat")
}
is PrivateChat -> PrivateMessageImpl(
is PrivateChat -> PrivateContentMessageImpl(
messageId,
from ?: error("Was detected common message, but owner (sender) of the message was not found"),
chat,

View File

@@ -4,8 +4,10 @@ import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
interface ChannelMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, SignedMessage, WithSenderChatMessage {
interface ChannelContentMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, SignedMessage, WithSenderChatMessage {
override val chat: ChannelChat
override val senderChat: ChannelChat
get() = chat
}
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("ChannelContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage"))
typealias ChannelMessage<T> = ChannelContentMessage<T>

View File

@@ -4,17 +4,28 @@ import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
interface GroupMessage<T : MessageContent> : PublicMessage<T> {
interface GroupContentMessage<T : MessageContent> : PublicContentMessage<T> {
override val chat: GroupChat
}
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("GroupContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.GroupContentMessage"))
typealias GroupMessage<T> = GroupContentMessage<T>
interface FromChannelGroupMessage<T : MessageContent> : GroupMessage<T>, SignedMessage, WithSenderChatMessage {
interface FromChannelGroupContentMessage<T : MessageContent> : GroupContentMessage<T>, SignedMessage, WithSenderChatMessage {
val channel: ChannelChat
override val senderChat: ChannelChat
get() = channel
}
interface AnonymousGroupMessage<T : MessageContent> : GroupMessage<T>, SignedMessage, WithSenderChatMessage {
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("FromChannelGroupContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.FromChannelGroupContentMessage"))
typealias FromChannelGroupMessage<T> = FromChannelGroupContentMessage<T>
interface AnonymousGroupContentMessage<T : MessageContent> : GroupContentMessage<T>, SignedMessage, WithSenderChatMessage {
override val senderChat: GroupChat
get() = chat
}
interface CommonGroupMessage<T : MessageContent> : GroupMessage<T>, FromUserMessage
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("AnonymousGroupContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage"))
typealias AnonymousGroupMessage<T> = AnonymousGroupContentMessage<T>
interface CommonGroupContentMessage<T : MessageContent> : GroupContentMessage<T>, FromUserMessage
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("CommonGroupContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.CommonGroupContentMessage"))
typealias CommonGroupMessage<T> = CommonGroupContentMessage<T>

View File

@@ -3,6 +3,6 @@ package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
interface MediaGroupMessage : CommonMessage<MediaGroupContent> {
interface MediaGroupMessage<T : MediaGroupContent> : CommonMessage<T> {
val mediaGroupId: MediaGroupIdentifier
}

View File

@@ -3,4 +3,6 @@ package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
interface PrivateMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, FromUserMessage
interface PrivateContentMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, FromUserMessage
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("PrivateContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage"))
typealias PrivateMessage<T> = PrivateContentMessage<T>

View File

@@ -4,6 +4,8 @@ import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
interface PublicMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T> {
interface PublicContentMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T> {
override val chat: PublicChat
}
@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("PublicContentMessage", "dev.inmo.tgbotapi.types.message.PublicContentMessage"))
typealias PublicMessage<T> = PublicContentMessage<T>

View File

@@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
import dev.inmo.tgbotapi.CommonAbstracts.TextedInput
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.SendTextMessage
import dev.inmo.tgbotapi.types.ChatIdentifier
@@ -10,7 +9,6 @@ import dev.inmo.tgbotapi.types.ParseMode.*
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.*
data class TextContent(
override val text: String,
@@ -24,8 +22,7 @@ data class TextContent(
replyMarkup: KeyboardMarkup?
): Request<ContentMessage<TextContent>> = SendTextMessage(
chatId,
toHtmlTexts().first(),
HTMLParseMode,
textSources,
false,
disableNotification,
replyToMessageId,
@@ -33,42 +30,36 @@ data class TextContent(
replyMarkup
)
@Deprecated(
"Useless due to fact that createResend currently use textSource and that will guarantee correct sending of message",
ReplaceWith("createResend")
)
override fun createResends(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
allowSendingWithoutReply: Boolean?,
replyMarkup: KeyboardMarkup?
): List<Request<ContentMessage<TextContent>>> = createResends(
chatId,
disableNotification,
replyToMessageId,
allowSendingWithoutReply,
replyMarkup,
HTMLParseMode
): List<Request<ContentMessage<TextContent>>> = listOf(
createResend(
chatId,
disableNotification,
replyToMessageId,
allowSendingWithoutReply,
replyMarkup
)
)
@Deprecated(
"Useless due to fact that createResend currently use textSource and that will guarantee correct sending of message",
ReplaceWith("createResend")
)
fun createResends(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
allowSendingWithoutReply: Boolean?,
replyMarkup: KeyboardMarkup?,
parseMode: ParseMode = HTMLParseMode
): List<Request<ContentMessage<TextContent>>> = when (parseMode) {
is MarkdownParseMode -> toMarkdownTexts()
is MarkdownV2ParseMode -> toMarkdownV2Texts()
is HTMLParseMode -> toHtmlTexts()
}.map {
SendTextMessage(
chatId,
it,
parseMode,
false,
disableNotification,
replyToMessageId,
allowSendingWithoutReply,
replyMarkup
)
}
parseMode: ParseMode = defaultParseMode
): List<Request<ContentMessage<TextContent>>> = createResends(chatId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
}

View File

@@ -1,12 +1,18 @@
package dev.inmo.tgbotapi.types.message.content.abstracts
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput
import dev.inmo.tgbotapi.types.InputMedia.MediaGroupMemberInputMedia
import dev.inmo.tgbotapi.types.InputMedia.*
interface MediaGroupContent : MediaContent, CaptionedInput {
fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia
}
interface VisualMediaGroupContent : MediaGroupContent
interface AudioMediaGroupContent : MediaGroupContent
interface DocumentMediaGroupContent : MediaGroupContent
interface VisualMediaGroupContent : MediaGroupContent {
override fun toMediaGroupMemberInputMedia(): VisualMediaGroupMemberInputMedia
}
interface AudioMediaGroupContent : MediaGroupContent {
override fun toMediaGroupMemberInputMedia(): AudioMediaGroupMemberInputMedia
}
interface DocumentMediaGroupContent : MediaGroupContent {
override fun toMediaGroupMemberInputMedia(): DocumentMediaGroupMemberInputMedia
}

View File

@@ -1,21 +1,16 @@
package dev.inmo.tgbotapi.types.message.content.media
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.media.SendAnimation
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.InputMedia.InputMediaAnimation
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.AnimationFile
import dev.inmo.tgbotapi.types.files.DocumentFile
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions
data class AnimationContent(
override val media: AnimationFile,
@@ -33,8 +28,7 @@ data class AnimationContent(
chatId,
media.fileId,
media.thumb ?.fileId,
toHtmlCaptions().firstOrNull(),
HTMLParseMode,
textSources,
media.duration,
media.width,
media.height,
@@ -46,8 +40,7 @@ data class AnimationContent(
override fun asInputMedia(): InputMediaAnimation = InputMediaAnimation(
media.fileId,
toMarkdownV2Captions().firstOrNull(),
MarkdownV2,
textSources,
media.width,
media.height,
media.duration,

View File

@@ -1,18 +1,17 @@
package dev.inmo.tgbotapi.types.message.content.media
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
import dev.inmo.tgbotapi.CommonAbstracts.textSources
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.media.SendAudio
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.InputMedia.InputMediaAudio
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaAudio
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.AudioFile
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
data class AudioContent(
override val media: AudioFile,
@@ -29,8 +28,7 @@ data class AudioContent(
chatId,
media.fileId,
media.thumb ?.fileId,
toHtmlCaptions().firstOrNull(),
HTMLParseMode,
textSources,
media.duration,
media.performer,
media.title,
@@ -42,8 +40,5 @@ data class AudioContent(
override fun toMediaGroupMemberInputMedia(): InputMediaAudio = asInputMedia()
override fun asInputMedia(): InputMediaAudio = media.toInputMediaAudio(
toHtmlCaptions().firstOrNull(),
HTMLParseMode
)
override fun asInputMedia(): InputMediaAudio = media.toInputMediaAudio(textSources)
}

View File

@@ -1,21 +1,18 @@
package dev.inmo.tgbotapi.types.message.content.media
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.media.SendDocument
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.InputMedia.InputMediaDocument
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaDocument
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.DocumentFile
import dev.inmo.tgbotapi.types.files.asDocumentFile
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
data class DocumentContent(
override val media: DocumentFile,
@@ -32,8 +29,7 @@ data class DocumentContent(
chatId,
media.fileId,
media.thumb ?.fileId,
toHtmlCaptions().firstOrNull(),
HTMLParseMode,
textSources,
disableNotification,
replyToMessageId,
allowSendingWithoutReply,
@@ -42,10 +38,7 @@ data class DocumentContent(
override fun toMediaGroupMemberInputMedia(): InputMediaDocument = asInputMedia()
override fun asInputMedia(): InputMediaDocument = media.toInputMediaDocument(
toHtmlCaptions().firstOrNull(),
HTMLParseMode
)
override fun asInputMedia(): InputMediaDocument = media.toInputMediaDocument(textSources)
}
@Suppress("NOTHING_TO_INLINE")

View File

@@ -1,19 +1,18 @@
package dev.inmo.tgbotapi.types.message.content.media
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
import dev.inmo.tgbotapi.CommonAbstracts.textSources
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.media.SendPhoto
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.InputMedia.InputMediaPhoto
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaPhoto
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
data class PhotoContent(
override val mediaCollection: Photo,
@@ -31,8 +30,7 @@ data class PhotoContent(
): Request<ContentMessage<PhotoContent>> = SendPhoto(
chatId,
media.fileId,
toHtmlCaptions().firstOrNull(),
HTMLParseMode,
textSources,
disableNotification,
replyToMessageId,
allowSendingWithoutReply,
@@ -41,8 +39,5 @@ data class PhotoContent(
override fun toMediaGroupMemberInputMedia(): InputMediaPhoto = asInputMedia()
override fun asInputMedia(): InputMediaPhoto = media.toInputMediaPhoto(
toHtmlCaptions().firstOrNull(),
HTMLParseMode
)
override fun asInputMedia(): InputMediaPhoto = media.toInputMediaPhoto(textSources)
}

View File

@@ -1,18 +1,17 @@
package dev.inmo.tgbotapi.types.message.content.media
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
import dev.inmo.tgbotapi.CommonAbstracts.textSources
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.media.SendVideo
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.VideoFile
import dev.inmo.tgbotapi.types.files.toInputMediaVideo
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
data class VideoContent(
override val media: VideoFile,
@@ -29,8 +28,7 @@ data class VideoContent(
chatId,
media.fileId,
media.thumb ?.fileId,
toHtmlCaptions().firstOrNull(),
HTMLParseMode,
textSources,
media.duration,
media.width,
media.height,
@@ -43,8 +41,5 @@ data class VideoContent(
override fun toMediaGroupMemberInputMedia(): InputMediaVideo = asInputMedia()
override fun asInputMedia(): InputMediaVideo = media.toInputMediaVideo(
toHtmlCaptions().firstOrNull(),
HTMLParseMode
)
override fun asInputMedia(): InputMediaVideo = media.toInputMediaVideo(textSources)
}

View File

@@ -1,20 +1,15 @@
package dev.inmo.tgbotapi.types.message.content.media
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.media.SendVoice
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.InputMedia.InputMediaAudio
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.VoiceFile
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions
data class VoiceContent(
override val media: VoiceFile,
@@ -30,8 +25,7 @@ data class VoiceContent(
): Request<ContentMessage<VoiceContent>> = SendVoice(
chatId,
media.fileId,
toHtmlCaptions().firstOrNull(),
HTMLParseMode,
textSources,
media.duration,
disableNotification,
replyToMessageId,
@@ -41,8 +35,7 @@ data class VoiceContent(
override fun asInputMedia(): InputMediaAudio = InputMediaAudio(
media.fileId,
toMarkdownV2Captions().firstOrNull(),
MarkdownV2,
textSources,
media.duration
)
}

View File

@@ -1,23 +0,0 @@
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

@@ -2,7 +2,8 @@ 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 dev.inmo.tgbotapi.types.passport.credentials.EncryptedCredentials
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View File

@@ -0,0 +1,266 @@
@file:Suppress("unused", "EXPERIMENTAL_API_USAGE")
package dev.inmo.tgbotapi.types.passport
import dev.inmo.micro_utils.crypto.MD5
import dev.inmo.micro_utils.crypto.md5
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.*
import dev.inmo.tgbotapi.types.passport.encrypted.type
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.*
val ByteArray.passportFileHash: MD5
get() = md5()
@Serializable(PassportElementErrorSerializer::class)
sealed class PassportElementError {
abstract val source: String
abstract val type: String
abstract val message: String
}
data class UnknownPassportElementError(
val raw: JsonObject
) : PassportElementError() {
override val source: String = raw[sourceField] ?.jsonPrimitive ?.contentOrNull ?: ""
override val type: String = raw[typeField] ?.jsonPrimitive ?.contentOrNull ?: ""
override val message: String = raw[messageField] ?.jsonPrimitive ?.contentOrNull ?: ""
}
object PassportElementErrorSerializer : KSerializer<PassportElementError> {
private val jsonObjectSerializer = JsonObject.serializer()
override val descriptor: SerialDescriptor
get() = jsonObjectSerializer.descriptor
override fun deserialize(decoder: Decoder): PassportElementError {
val json = jsonObjectSerializer.deserialize(decoder)
return when (json[sourceField] ?.jsonPrimitive ?.content) {
"dataField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorDataField.serializer(), json)
"frontSideField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorFrontSide.serializer(), json)
"reverseSideField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorReverseSide.serializer(), json)
"selfieField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorSelfie.serializer(), json)
"fileField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementFileError.serializer(), json)
"filesField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementFilesError.serializer(), json)
"translationFileField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorTranslationFile.serializer(), json)
"translationFilesField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorTranslationFiles.serializer(), json)
"unspecifiedField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorUnspecified.serializer(), json)
else -> UnknownPassportElementError(json)
}
}
override fun serialize(encoder: Encoder, value: PassportElementError) {
val neverMindAboutThisVariable = when (value) {
is PassportElementErrorFrontSide -> PassportElementErrorFrontSide.serializer().serialize(encoder, value)
is PassportElementErrorReverseSide -> PassportElementErrorReverseSide.serializer().serialize(encoder, value)
is PassportElementErrorSelfie -> PassportElementErrorSelfie.serializer().serialize(encoder, value)
is PassportElementErrorFile -> PassportElementErrorFile.serializer().serialize(encoder, value)
is PassportElementErrorTranslationFile -> PassportElementErrorTranslationFile.serializer().serialize(encoder, value)
is PassportElementErrorUnspecified -> PassportElementErrorUnspecified.serializer().serialize(encoder, value)
is PassportElementErrorDataField -> PassportElementErrorDataField.serializer().serialize(encoder, value)
is PassportElementErrorFiles -> PassportElementErrorFiles.serializer().serialize(encoder, value)
is PassportElementErrorTranslationFiles -> PassportElementErrorTranslationFiles.serializer().serialize(encoder, value)
is UnknownPassportElementError -> jsonObjectSerializer.serialize(encoder, value.raw)
}
}
}
@Serializable
sealed class PassportSingleElementError : PassportElementError() {
abstract val elementHash: PassportElementHash
}
@Serializable
sealed class PassportMultipleElementsError : PassportElementError() {
abstract val elementsHashes: List<PassportElementHash>
}
@Serializable
sealed class PassportElementFileError : PassportSingleElementError()
@Serializable
sealed class PassportElementFilesError : PassportMultipleElementsError()
@Serializable
data class PassportElementErrorDataField(
@SerialName(typeField)
override val type: String,
@SerialName(fieldNameField)
val fieldName: String,
@SerialName(dataHashField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val elementHash: PassportElementHash,
@SerialName(messageField)
override val message: String
) : PassportSingleElementError() {
@SerialName(sourceField)
@Required
override val source: String = dataField
}
fun EncryptedPassportElementWithData.createDataError(field: String, message: String) = PassportElementErrorDataField(
type,
field,
hash,
message
)
@Serializable
data class PassportElementErrorFrontSide(
@SerialName(typeField)
override val type: String,
@SerialName(fileHashField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val elementHash: PassportElementHash,
@SerialName(messageField)
override val message: String
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
override val source: String = frontSideField
}
fun EncryptedPassportElementWithFrontSide.createFrontSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFrontSide(
type,
unencryptedFileHash,
message
)
@Serializable
data class PassportElementErrorReverseSide(
@SerialName(typeField)
override val type: String,
@SerialName(fileHashField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val elementHash: PassportElementHash,
@SerialName(messageField)
override val message: String
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
override val source: String = reverseSideField
}
fun EncryptedPassportElementWithReverseSide.createReverseSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorReverseSide(
type,
unencryptedFileHash,
message
)
@Serializable
data class PassportElementErrorSelfie(
@SerialName(typeField)
override val type: String,
@SerialName(fileHashField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val elementHash: PassportElementHash,
@SerialName(messageField)
override val message: String
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
override val source: String = selfieField
}
fun EncryptedPassportElementWithSelfie.createSelfieError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorSelfie(
type,
unencryptedFileHash,
message
)
@Serializable
data class PassportElementErrorFile(
@SerialName(typeField)
override val type: String,
@SerialName(fileHashField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val elementHash: PassportElementHash,
@SerialName(messageField)
override val message: String
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
override val source: String = fileField
}
fun EncryptedPassportElementWithFilesCollection.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFile(
type,
unencryptedFileHash,
message
)
@Serializable
data class PassportElementErrorFiles(
@SerialName(typeField)
override val type: String,
@SerialName(fileHashesField)
override val elementsHashes: List<@Serializable(Base64BytesToFromStringSerializer::class) PassportElementHash>,
@SerialName(messageField)
override val message: String
) : PassportElementFilesError() {
@SerialName(sourceField)
@Required
override val source: String = filesField
}
fun EncryptedPassportElementWithFilesCollection.createFilesError(message: String, unencryptedFileHashes: List<PassportElementHash>) = PassportElementErrorFiles(
type,
unencryptedFileHashes,
message
)
@Serializable
data class PassportElementErrorTranslationFile(
@SerialName(typeField)
override val type: String,
@SerialName(fileHashField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val elementHash: PassportElementHash,
@SerialName(messageField)
override val message: String
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
override val source: String = translationFileField
}
fun EncryptedPassportElementTranslatable.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorTranslationFile(
type,
unencryptedFileHash,
message
)
@Serializable
data class PassportElementErrorTranslationFiles(
@SerialName(typeField)
override val type: String,
@SerialName(fileHashesField)
override val elementsHashes: List<@Serializable(Base64BytesToFromStringSerializer::class) PassportElementHash>,
@SerialName(messageField)
override val message: String
) : PassportElementFilesError() {
@SerialName(sourceField)
@Required
override val source: String = translationFilesField
}
fun EncryptedPassportElementTranslatable.createFilesError(message: String, unencryptedFileHashes: List<PassportElementHash>) = PassportElementErrorTranslationFiles(
type,
unencryptedFileHashes,
message
)
@Serializable
data class PassportElementErrorUnspecified(
@SerialName(typeField)
override val type: String,
@SerialName(fileHashField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val elementHash: PassportElementHash,
@SerialName(messageField)
override val message: String
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
override val source: String = unspecifiedField
}
fun EncryptedPassportElement.createUnspecifiedError(message: String, elementHash: PassportElementHash) = PassportElementErrorUnspecified(
type,
elementHash,
message
)

View File

@@ -0,0 +1,15 @@
package dev.inmo.tgbotapi.types.passport.credentials
import dev.inmo.tgbotapi.types.nonceField
import dev.inmo.tgbotapi.types.passport.decrypted.SecureData
import dev.inmo.tgbotapi.types.secureDataField
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class DecryptedCredentials(
@SerialName(secureDataField)
val secureData: SecureData,
@SerialName(nonceField)
val nonce: String
)

View File

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

View File

@@ -0,0 +1,35 @@
package dev.inmo.tgbotapi.types.passport.credentials
import dev.inmo.micro_utils.crypto.SourceBytes
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
sealed class EndDataCredentials {
@Serializable(Base64BytesToFromStringSerializer::class)
abstract val hash: SourceBytes
@Serializable(Base64BytesToFromStringSerializer::class)
abstract val secret: SourceBytes
}
@Serializable
data class DataCredentials(
@SerialName(dataHashField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: SourceBytes,
@SerialName(secretField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val secret: SourceBytes
) : EndDataCredentials()
@Serializable
data class FileCredentials(
@SerialName(fileHashField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: SourceBytes,
@SerialName(secretField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val secret: SourceBytes
) : EndDataCredentials()

View File

@@ -0,0 +1,16 @@
package dev.inmo.tgbotapi.types.passport.decrypted
import dev.inmo.tgbotapi.types.dataField
import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData
import kotlinx.serialization.*
@Serializable
data class AddressSecureValue(
@SerialName(dataField)
override val data: DataCredentials
) : SecureValueWithData {
@Transient
override val credentials: List<EndDataCredentials> = listOf(data)
}

View File

@@ -0,0 +1,41 @@
package dev.inmo.tgbotapi.types.passport.decrypted
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.passport.credentials.*
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
sealed class IdentityWithReverseSideSecureValue : SecureValueIdentity, SecureValueWithData, SecureValueWithTranslations, SecureValueWithReverseSide {
override val credentials: List<EndDataCredentials>
get() = listOfNotNull(data, frontSide, reverseSide, selfie) + translation
}
@Serializable
data class DriverLicenseSecureValue(
@SerialName(dataField)
override val data: DataCredentials? = null,
@SerialName(frontSideField)
override val frontSide: FileCredentials? = null,
@SerialName(reverseSideField)
override val reverseSide: FileCredentials? = null,
@SerialName(selfieField)
override val selfie: FileCredentials? = null,
@SerialName(translationField)
override val translation: List<FileCredentials> = emptyList()
) : IdentityWithReverseSideSecureValue()
@Serializable
data class IdentityCardSecureValue(
@SerialName(dataField)
override val data: DataCredentials? = null,
@SerialName(frontSideField)
override val frontSide: FileCredentials? = null,
@SerialName(reverseSideField)
override val reverseSide: FileCredentials? = null,
@SerialName(selfieField)
override val selfie: FileCredentials? = null,
@SerialName(translationField)
override val translation: List<FileCredentials> = emptyList()
) : IdentityWithReverseSideSecureValue()

View File

@@ -0,0 +1,56 @@
package dev.inmo.tgbotapi.types.passport.decrypted
import dev.inmo.tgbotapi.types.filesField
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithFiles
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithTranslations
import dev.inmo.tgbotapi.types.translationField
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
sealed class OtherDocumentsSecureValue : SecureValueWithTranslations, SecureValueWithFiles {
override val credentials: List<EndDataCredentials>
get() = translation + files
}
@Serializable
data class UtilityBillSecureValue(
@SerialName(translationField)
override val translation: List<FileCredentials> = emptyList(),
@SerialName(filesField)
override val files: List<FileCredentials> = emptyList()
) : OtherDocumentsSecureValue()
@Serializable
data class BankStatementSecureValue(
@SerialName(translationField)
override val translation: List<FileCredentials> = emptyList(),
@SerialName(filesField)
override val files: List<FileCredentials> = emptyList()
) : OtherDocumentsSecureValue()
@Serializable
data class RentalAgreementSecureValue(
@SerialName(translationField)
override val translation: List<FileCredentials> = emptyList(),
@SerialName(filesField)
override val files: List<FileCredentials> = emptyList()
) : OtherDocumentsSecureValue()
@Serializable
data class PassportRegistrationSecureValue(
@SerialName(translationField)
override val translation: List<FileCredentials> = emptyList(),
@SerialName(filesField)
override val files: List<FileCredentials> = emptyList()
) : OtherDocumentsSecureValue()
@Serializable
data class TemporalRegistrationSecureValue(
@SerialName(translationField)
override val translation: List<FileCredentials> = emptyList(),
@SerialName(filesField)
override val files: List<FileCredentials> = emptyList()
) : OtherDocumentsSecureValue()

View File

@@ -0,0 +1,38 @@
package dev.inmo.tgbotapi.types.passport.decrypted
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.passport.credentials.*
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
sealed class PassportSecureValue : SecureValueIdentity, SecureValueWithData, SecureValueWithTranslations {
override val credentials: List<EndDataCredentials>
get() = listOfNotNull(data, frontSide, selfie) + translation
}
@Serializable
data class CommonPassportSecureValue(
@SerialName(dataField)
override val data: DataCredentials? = null,
@SerialName(frontSideField)
override val frontSide: FileCredentials? = null,
@SerialName(selfieField)
override val selfie: FileCredentials? = null,
@SerialName(translationField)
override val translation: List<FileCredentials> = emptyList()
) : PassportSecureValue()
@Serializable
data class InternalPassportSecureValue(
@SerialName(dataField)
override val data: DataCredentials? = null,
@SerialName(frontSideField)
override val frontSide: FileCredentials? = null,
@SerialName(selfieField)
override val selfie: FileCredentials? = null,
@SerialName(translationField)
override val translation: List<FileCredentials> = emptyList()
) : PassportSecureValue()

View File

@@ -0,0 +1,16 @@
package dev.inmo.tgbotapi.types.passport.decrypted
import dev.inmo.tgbotapi.types.dataField
import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData
import kotlinx.serialization.*
@Serializable
data class PersonalDetailsSecureValue(
@SerialName(dataField)
override val data: DataCredentials
) : SecureValueWithData {
@Transient
override val credentials: List<EndDataCredentials> = listOf(data)
}

View File

@@ -0,0 +1,42 @@
package dev.inmo.tgbotapi.types.passport.decrypted
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class SecureData(
@SerialName(personalDetailsField)
val personalDetails: PersonalDetailsSecureValue? = null,
@SerialName(passportField)
val passport: CommonPassportSecureValue? = null,
@SerialName(internalPassportField)
val internalPassport: InternalPassportSecureValue? = null,
@SerialName(driverLicenseField)
val driverLicense: DriverLicenseSecureValue? = null,
@SerialName(identityCardField)
val identityCard: IdentityCardSecureValue? = null,
@SerialName(utilityBillField)
val utilityBill: UtilityBillSecureValue? = null,
@SerialName(bankStatementField)
val bankStatement: BankStatementSecureValue? = null,
@SerialName(rentalAgreementField)
val rentalAgreement: RentalAgreementSecureValue? = null,
@SerialName(passportRegistrationField)
val passportRegistration: PassportRegistrationSecureValue? = null,
@SerialName(temporaryRegistrationField)
val temporaryRegistration: TemporalRegistrationSecureValue? = null,
) {
val allCredentials by lazy {
(personalDetails ?.credentials ?: emptyList()) +
(passport ?.credentials ?: emptyList()) +
(internalPassport ?.credentials ?: emptyList()) +
(driverLicense ?.credentials ?: emptyList()) +
(identityCard ?.credentials ?: emptyList()) +
(utilityBill ?.credentials ?: emptyList()) +
(bankStatement ?.credentials ?: emptyList()) +
(rentalAgreement ?.credentials ?: emptyList()) +
(passportRegistration ?.credentials ?: emptyList()) +
(temporaryRegistration ?.credentials ?: emptyList())
}
}

View File

@@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.passport.decrypted.abstracts
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
interface SecureValue {
val credentials: List<EndDataCredentials>
}

View File

@@ -0,0 +1,8 @@
package dev.inmo.tgbotapi.types.passport.decrypted.abstracts
import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials
interface SecureValueIdentity : SecureValue {
val frontSide: FileCredentials?
val selfie: FileCredentials?
}

View File

@@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.passport.decrypted.abstracts
import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials
interface SecureValueWithData : SecureValue {
val data: DataCredentials?
}

View File

@@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.passport.decrypted.abstracts
import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials
interface SecureValueWithFiles : SecureValue {
val files: List<FileCredentials>
}

View File

@@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.passport.decrypted.abstracts
import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials
interface SecureValueWithReverseSide : SecureValue {
val reverseSide: FileCredentials?
}

View File

@@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.passport.decrypted.abstracts
import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials
interface SecureValueWithTranslations : SecureValue {
val translation: List<FileCredentials>
}

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.types.passport.encrypted
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
import dev.inmo.tgbotapi.types.emailField
import dev.inmo.tgbotapi.types.hashField
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithEmail
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class Email(
@SerialName(emailField)
override val email: String,
@SerialName(hashField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithEmail

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.types.passport.encrypted
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
import dev.inmo.tgbotapi.types.dataField
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithData
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class EncryptedAddress(
@SerialName(dataField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val data: EncryptedData,
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithData

View File

@@ -0,0 +1,64 @@
package dev.inmo.tgbotapi.types.passport.encrypted
import dev.inmo.micro_utils.crypto.decodeBase64
import dev.inmo.micro_utils.serialization.encapsulator.Encapsulator
import dev.inmo.tgbotapi.types.hashField
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.UnknownEncryptedPassportElement
import dev.inmo.tgbotapi.types.typeField
import dev.inmo.tgbotapi.utils.RiskFeature
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.*
val encryptedElementsClassesByTypes = mapOf(
"personal_details" to Encapsulator(EncryptedPersonalDetails::class, EncryptedPersonalDetails.serializer()),
"passport" to Encapsulator(CommonPassport::class, CommonPassport.serializer()),
"driver_license" to Encapsulator(DriverLicense::class, DriverLicense.serializer()),
"identity_card" to Encapsulator(IdentityCard::class, IdentityCard.serializer()),
"internal_passport" to Encapsulator(InternalPassport::class, InternalPassport.serializer()),
"address" to Encapsulator(EncryptedAddress::class, EncryptedAddress.serializer()),
"utility_bill" to Encapsulator(UtilityBill::class, UtilityBill.serializer()),
"bank_statement" to Encapsulator(BankStatement::class, BankStatement.serializer()),
"rental_agreement" to Encapsulator(RentalAgreement::class, RentalAgreement.serializer()),
"passport_registration" to Encapsulator(PassportRegistration::class, PassportRegistration.serializer()),
"temporary_registration" to Encapsulator(TemporaryRegistration::class, TemporaryRegistration.serializer()),
"phone_number" to Encapsulator(PhoneNumber::class, PhoneNumber.serializer()),
"email" to Encapsulator(Email::class, Email.serializer())
)
@RiskFeature("Remember that this method may return \"unknown\" in case if encrypted element was not defined in library")
val EncryptedPassportElement.type: String
get() = encryptedElementsClassesByTypes.keys.firstOrNull { encryptedElementsClassesByTypes.getValue(it).klass.isInstance(this) } ?: "unknown"
@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 json[typeField] ?.jsonPrimitive ?.content ?.let { type ->
encryptedElementsClassesByTypes[type] ?.serializer ?.let { deserializer ->
nonstrictJsonFormat.decodeFromJsonElement(deserializer, json)
}
} ?: UnknownEncryptedPassportElement(json, json[hashField] ?.jsonPrimitive ?.content ?.decodeBase64() ?: byteArrayOf())
}
override fun serialize(encoder: Encoder, value: EncryptedPassportElement) {
val json = value.let {
encryptedElementsClassesByTypes.forEach { (key, encapsulator) ->
val json = encapsulator.encapsulate(value) { data ->
nonstrictJsonFormat.encodeToJsonElement(this as KSerializer<EncryptedPassportElement>, data).jsonObject
} ?: return@forEach
return@let JsonObject(json + (typeField to JsonPrimitive(key)))
}
(value as? UnknownEncryptedPassportElement) ?.rawJson ?: return
}
jsonSerializer.serialize(encoder, json)
}
}

View File

@@ -1,14 +1,13 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
package dev.inmo.tgbotapi.types.passport.encrypted
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
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 dev.inmo.tgbotapi.types.passport.encrypted.abstracts.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
sealed class TranslatableFilesCollection : Translatable, FilesCollection
sealed class EncryptedPassportElementWithTranslatableFilesCollection : EncryptedPassportElementTranslatable, EncryptedPassportElementWithFilesCollection
@Serializable
data class UtilityBill(
@@ -17,9 +16,9 @@ data class UtilityBill(
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableFilesCollection()
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithTranslatableFilesCollection()
@Serializable
data class BankStatement(
@SerialName(filesField)
@@ -27,9 +26,9 @@ data class BankStatement(
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableFilesCollection()
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithTranslatableFilesCollection()
@Serializable
data class RentalAgreement(
@SerialName(filesField)
@@ -37,9 +36,9 @@ data class RentalAgreement(
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableFilesCollection()
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithTranslatableFilesCollection()
@Serializable
data class PassportRegistration(
@SerialName(filesField)
@@ -47,9 +46,9 @@ data class PassportRegistration(
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableFilesCollection()
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithTranslatableFilesCollection()
@Serializable
data class TemporaryRegistration(
@SerialName(filesField)
@@ -57,7 +56,7 @@ data class TemporaryRegistration(
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableFilesCollection()
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithTranslatableFilesCollection()

View File

@@ -1,19 +1,19 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
package dev.inmo.tgbotapi.types.passport.encrypted
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.passport.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.*
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
sealed class TranslatableIDDocument : WithData, WithFrontSide, WithReverseSide, WithSelfie, Translatable
sealed class EncryptedPassportElementWithTranslatableIDDocument : EncryptedPassportElementWithData, EncryptedPassportElementWithFrontSide, EncryptedPassportElementWithReverseSide, EncryptedPassportElementWithSelfie, EncryptedPassportElementTranslatable
@Serializable
data class DriverLicense(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
@Serializable(Base64BytesToFromStringSerializer::class)
override val data: EncryptedData,
@SerialName(frontSideField)
override val frontSide: PassportFile? = null,
@@ -24,14 +24,14 @@ data class DriverLicense(
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableIDDocument()
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithTranslatableIDDocument()
@Serializable
data class IdentityCard(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
@Serializable(Base64BytesToFromStringSerializer::class)
override val data: EncryptedData,
@SerialName(frontSideField)
override val frontSide: PassportFile? = null,
@@ -42,6 +42,6 @@ data class IdentityCard(
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
) : TranslatableIDDocument()
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithTranslatableIDDocument()

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.types.passport.encrypted
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
import dev.inmo.tgbotapi.types.dataField
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithData
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class EncryptedPersonalDetails(
@SerialName(dataField)
@Serializable(Base64BytesToFromStringSerializer::class)
override val data: EncryptedData,
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithData

View File

@@ -1,19 +1,19 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
package dev.inmo.tgbotapi.types.passport.encrypted
import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.passport.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.*
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable(EncryptedElementSerializer::class)
sealed class Passport : WithData, WithFrontSide, WithSelfie, Translatable
sealed class Passport : EncryptedPassportElementWithData, EncryptedPassportElementWithFrontSide, EncryptedPassportElementWithSelfie, EncryptedPassportElementTranslatable
@Serializable
data class CommonPassport(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
@Serializable(Base64BytesToFromStringSerializer::class)
override val data: EncryptedData,
@SerialName(frontSideField)
override val frontSide: PassportFile? = null,
@@ -22,13 +22,13 @@ data class CommonPassport(
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : Passport()
@Serializable
data class InternalPassport(
@SerialName(dataField)
@Serializable(Base64StringSerializer::class)
@Serializable(Base64BytesToFromStringSerializer::class)
override val data: EncryptedData,
@SerialName(frontSideField)
override val frontSide: PassportFile? = null,
@@ -37,6 +37,6 @@ data class InternalPassport(
@SerialName(translationField)
override val translations: List<PassportFile> = emptyList(),
@SerialName(hashField)
@Serializable(Base64StringSerializer::class)
override val hash: String
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : Passport()

View File

@@ -1,4 +1,4 @@
package dev.inmo.tgbotapi.types.passport.encrypted_data
package dev.inmo.tgbotapi.types.passport.encrypted
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.types.passport.encrypted
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
import dev.inmo.tgbotapi.types.hashField
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithPhoneNumber
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(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElementWithPhoneNumber

View File

@@ -0,0 +1,21 @@
package dev.inmo.tgbotapi.types.passport.encrypted.abstracts
import dev.inmo.micro_utils.crypto.SourceBytes
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject
typealias PassportElementHash = SourceBytes
@Serializable(EncryptedElementSerializer::class)
interface EncryptedPassportElement {
val hash: PassportElementHash
}
@Serializable(EncryptedElementSerializer::class)
data class UnknownEncryptedPassportElement(
val rawJson: JsonObject,
@Serializable(Base64BytesToFromStringSerializer::class)
override val hash: PassportElementHash
) : EncryptedPassportElement

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,18 +0,0 @@
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

@@ -1,17 +0,0 @@
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

@@ -1,87 +0,0 @@
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

@@ -1,17 +0,0 @@
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

@@ -1,18 +0,0 @@
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

@@ -1,18 +0,0 @@
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

@@ -1,10 +0,0 @@
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

@@ -1,10 +0,0 @@
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

@@ -1,10 +0,0 @@
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

@@ -1,9 +0,0 @@
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

@@ -1,10 +0,0 @@
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

@@ -1,9 +0,0 @@
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

@@ -1,10 +0,0 @@
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?
}

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