mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-16 20:10:18 +00:00
Compare commits
281 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dc83b8d77a | |||
| 2aac6c0bde | |||
| b637d0d2a6 | |||
| d12cba2343 | |||
| 450c7e6474 | |||
| a35fb40a66 | |||
| 8731aa2c26 | |||
| 32e305537d | |||
| ec0a10e36e | |||
| 131ec4d6d5 | |||
| ecc608f51a | |||
| 040654f131 | |||
| 9e73d0c461 | |||
| d67c80bc99 | |||
| b0eef4f82d | |||
| fbe91a6321 | |||
| 15066c9d63 | |||
| e0bf67d8f9 | |||
| 1dc3ce2fb5 | |||
| 0c71133969 | |||
| 1359dd549f | |||
| c425e2ecc3 | |||
| 4d63e3a17d | |||
| d34deade0d | |||
| 2f52ad45a4 | |||
| 1d99e632a4 | |||
| cdcfaf5a29 | |||
| f3590762f3 | |||
| e0ff14b7fe | |||
| 9983e111ec | |||
| 08b8710772 | |||
| fc71e028c4 | |||
| 30a4a7bd8b | |||
| b973278b0a | |||
| ae2f4579e2 | |||
| a4bf6911c7 | |||
| 73b3daa68b | |||
| 09748615ae | |||
| 2dc8521aed | |||
| 81de59f37c | |||
| fb61a94c5e | |||
| 26fd5e51bf | |||
| c1ab9da4c4 | |||
| 6b414d64b0 | |||
| 5a3edc2b44 | |||
| 6dcdc2ab7f | |||
| a2ae4f71de | |||
| 5d87b86afe | |||
| ef22735894 | |||
| c0ea479fe3 | |||
| 0846e816e9 | |||
| d837c9d605 | |||
| d1993842c3 | |||
| 4e8a9dcff0 | |||
| 10eb15e172 | |||
| 0320da7614 | |||
| 7aa3ff180e | |||
| a882a212c2 | |||
| 1b15748f65 | |||
| 044fe5eadf | |||
| 9453ec37e7 | |||
| 3d0cbc2d2b | |||
| 198b551ebf | |||
| 1452e32293 | |||
| 946b7abcae | |||
| 879943622a | |||
| c0b4b523cf | |||
| 49e6e9cfe3 | |||
| ffadb6355b | |||
| 9cc402b42d | |||
| b9341f89ac | |||
| ac07f44c81 | |||
| 2e53247726 | |||
| e2dddf96a1 | |||
| ce0fceb240 | |||
| 633239961a | |||
| 8b79b15777 | |||
| a28cf5ddff | |||
| 8c2cffc8e3 | |||
| b933361258 | |||
| 383e722d07 | |||
| 3125c2fc1b | |||
| 965b8c3c50 | |||
| 94745ef373 | |||
| aee5ab564b | |||
| c70f0b65dd | |||
| 30e6f68228 | |||
| 00873a255c | |||
| 6bd423dc11 | |||
| c5ada8cea0 | |||
| 0cb3df4d1a | |||
| b22118b400 | |||
| 2006e45b57 | |||
| c091098feb | |||
| 6cf8d47cbf | |||
| 3dc4e9dda4 | |||
| 6407ad1a93 | |||
| f974e5787f | |||
| 28a9bbd310 | |||
| 599d5a51e3 | |||
| 25f8d15a4b | |||
| 66c2cb2d30 | |||
| 74fb448378 | |||
| 3417ec060f | |||
| 4f54a00003 | |||
| 4fb187da30 | |||
| 7637b6f69a | |||
| 9df9af193c | |||
| ba4b4c4b64 | |||
| fa0861b8bc | |||
| 20494e1d4a | |||
| a404008dee | |||
| 881205dd80 | |||
| 2096c44811 | |||
| 1a3da33589 | |||
| be28c9bd5d | |||
| a193ef5fd5 | |||
| 7c43d3aaa5 | |||
| e034afc75c | |||
| 08e3326d1a | |||
| 6dd1825b98 | |||
| bd4eb29fc1 | |||
| 2cc66ef13c | |||
| 9a8175d1c8 | |||
| 25285b2e8a | |||
| bb09f05d7b | |||
| da5e46e59f | |||
| a3f315a73a | |||
| 43583a885a | |||
| ec02257ecd | |||
| 29ee4a9396 | |||
| 2717cb4fc6 | |||
| 1ce2526401 | |||
| 74c480b07e | |||
| 657e9aa770 | |||
| 0d19952ba7 | |||
| f8cccc3e17 | |||
| bc1b7c3f25 | |||
| ec74111a9d | |||
| 2dadeb7eb7 | |||
| 24bd65501b | |||
| 574ca803fa | |||
| 947e3bf34e | |||
| 488158d8fb | |||
| 41bf3c7f0b | |||
| c2032d21cd | |||
| 6650dd9cfe | |||
| af1d6d6f1a | |||
| a5861d659d | |||
| b36f80a6d3 | |||
| 7c4f034a6c | |||
| 3b08bc6dd2 | |||
| ed87c0ad95 | |||
| c8c0fc2ce8 | |||
| 1f40ce1a81 | |||
| b0219389fc | |||
| f6ec82b449 | |||
| 71dac70635 | |||
| 98f68a9e1e | |||
| e7199e7451 | |||
| 33b50c6c68 | |||
| e4ce6f8fc7 | |||
| 8764f18ca8 | |||
| b2fa7fee9d | |||
| 0121e3a104 | |||
| f6e5664632 | |||
| c5b7c4e1f5 | |||
| 53800d49bf | |||
| d83e3eb10a | |||
| 66b4d06064 | |||
| 4fab01b2a2 | |||
| b81086c4bb | |||
| d776071cac | |||
| 5f33d05deb | |||
| 912cc7217c | |||
| 96e00f6e31 | |||
| f8ea5f9515 | |||
| 9f11c4f1c4 | |||
| 9c91980d5d | |||
| 7376eb5b10 | |||
| 6654f27f9d | |||
| d29acce417 | |||
| f0f18209f3 | |||
| 324018a0f6 | |||
| b621325e92 | |||
| 43e92555c2 | |||
|
|
5f1ca51e60 | ||
| 83edda2dfe | |||
| 1974c20229 | |||
| 499d9b1791 | |||
| 6caa7dd428 | |||
| e8ded44562 | |||
| 1e6b0381ee | |||
| 1cf7ae7438 | |||
| 311512b5db | |||
| d73fa4076f | |||
| 3620350cc0 | |||
| 54cfea9adf | |||
| 6665b6ef03 | |||
| ee6f0f3d5d | |||
| 6ec0fcadd2 | |||
| c89aa7b9ba | |||
| cf47cee36a | |||
|
|
824fa9ba09 | ||
| 654d84b1b4 | |||
|
|
c7259e7699 | ||
| 00a75801a8 | |||
| e45f9cf46a | |||
| 3b1803e851 | |||
| bf1e353615 | |||
| 99bb8d6e0d | |||
| 98d7b9c651 | |||
| 765caefc32 | |||
| 6bdefb6f8f | |||
| d5e283e7ba | |||
| a5982ac881 | |||
| c0e81b1d6d | |||
| eb879963f8 | |||
| f835167f66 | |||
| ff34b23777 | |||
| ec806dfd83 | |||
|
|
0a73dfb799 | ||
| 53b8cc4625 | |||
| 201def826e | |||
| 609a959b99 | |||
| 6a05a7ecab | |||
| 159ea6f1cc | |||
| 0886781d61 | |||
| 60d5581ec6 | |||
| 2a33216006 | |||
| 179bb66183 | |||
| 7a2ecd2dbf | |||
| fd1a15cb5d | |||
| 86a472e814 | |||
| 6d6c544aaf | |||
| dd4d5cd15d | |||
| 23dfa4f69d | |||
| a10d766295 | |||
| ea6ab8f024 | |||
| f377d61bf0 | |||
| 18c9d4e468 | |||
| 20b931138c | |||
| d7bca15693 | |||
| 957649603b | |||
| bbc56fe94c | |||
| d048958423 | |||
| f0e9267664 | |||
| 5dd7207e09 | |||
| d96d47e32c | |||
| 1ee73dd406 | |||
| e9a05c4930 | |||
| 9e771fa04a | |||
| 06ba21fc1f | |||
| 7d72d72f2c | |||
| 80d4bdfe17 | |||
| b457d11067 | |||
| 46fe16fd73 | |||
| 8e1cafb1b6 | |||
| 68d971f874 | |||
| 37a23c7e79 | |||
| b053c29ea3 | |||
| 23a1fed7dd | |||
| 87d2537bda | |||
| 6d782f28c3 | |||
| d8dbbdf549 | |||
| f317e144e6 | |||
| 05c27804ce | |||
| eb97a8e151 | |||
|
|
06639e5f3c | ||
| 82b7bf676f | |||
| 4f9cb531c0 | |||
| 09bbb1945c | |||
| 7bedc4caf0 | |||
| 6a73aa1525 | |||
| e1ee541005 | |||
|
|
2d2fe01227 | ||
|
|
af53682b1f | ||
|
|
c8a5552c9e | ||
|
|
ffa78ebfe1 | ||
| e85e7d02f7 | |||
| 5747383ed1 |
16
.github/workflows/regular-build.yml
vendored
Normal file
16
.github/workflows/regular-build.yml
vendored
Normal 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
|
||||
409
CHANGELOG.md
409
CHANGELOG.md
@@ -1,5 +1,414 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 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
|
||||
|
||||
**THIS UPDATE CONTAINS BREAKING CHANGES**
|
||||
|
||||
* `Common`:
|
||||
* **ALL DEPRECATIONS CREATED SINCE 0.30.0 WERE REMOVED**
|
||||
* `Behaviour Builder`:
|
||||
* Extension `TelegramBot#buildBehaviour` have changed its return value: now it is `Job` instead of
|
||||
`FlowsUpdatesFilter`
|
||||
* `Utils`
|
||||
* New extensions `TelegramBot#longPolling` were added as new recommended way to start getting updates via long
|
||||
polling
|
||||
* Old extensions `RequestsExecutor#startGettingFlowsUpdatesByLongPolling` has been deprecated
|
||||
|
||||
## 0.30.13
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `MicroUtils`: `0.4.15` -> `0.4.16`
|
||||
* `Core`:
|
||||
* New variable `FlowsUpdatesFilter#allUpdatesWithoutMediaGroupsGroupingFlow` which will contains updates without
|
||||
`SentMediaGroupUpdate`
|
||||
* `Utils`:
|
||||
* Extensions for `ResendableContent` has been added
|
||||
* Extensions for `TextSource` has been added
|
||||
* `Behaviour Builder`:
|
||||
* Project has been created :)
|
||||
|
||||
## 0.30.12
|
||||
|
||||
* `Utils`:
|
||||
* Class casts has been added. Now you can write something like `message.asGroupMessage() ?.let { ... }` instead of
|
||||
`(message as? GroupMessage<*>) ?.let { ... }`
|
||||
|
||||
## 0.30.11
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `MicroUtils`: `0.4.11` -> `0.4.15`
|
||||
* `Klock`: `2.0.1` -> `2.0.3`
|
||||
* `Ktor`: `1.4.3` -> `1.5.0`
|
||||
* `Core`:
|
||||
* All bot actions got functions for short calling, like `recordVideo` for `RecordVideoNote`
|
||||
* All bot actions got class-cast shortcuts
|
||||
|
||||
## 0.30.10
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `Kotlin`: `1.4.20` -> `1.4.21`
|
||||
* `Klock`: `2.0.0` -> `2.0.1`
|
||||
* `Ktor`: `1.4.2` -> `1.4.3`
|
||||
* `MicroUtils`: `0.4.6` -> `0.4.11`
|
||||
* `API Extensions`:
|
||||
* New function `buildBot`
|
||||
|
||||
## 0.30.9
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `UUID`: `0.2.2` -> `0.2.3`
|
||||
* `Coroutines`: `1.4.1` -> `1.4.2`
|
||||
* `MicroUtils`: `0.4.3` -> `0.4.6`
|
||||
* `Core`:
|
||||
* Add `BowlingDiceAnimationType`
|
||||
|
||||
## 0.30.8
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `Kotlin`: `1.4.10` -> `1.4.20`
|
||||
* `Klock`: `1.12.1` -> `2.0.0`
|
||||
* `MicroUtils`: `0.4.1` -> `0.4.3`
|
||||
|
||||
## 0.30.7
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `MicroUtils`: `0.4.0` -> `0.4.1`
|
||||
* `Core`:
|
||||
* `TelegramAPIUrlsKeeper` will fix ending of host url since this version
|
||||
* New mechanisms in`PowLimiter` and `CommonLimiter` has been added
|
||||
* New builder `KtorRequestsExecutorBuilder`
|
||||
* New function `telegramBot`
|
||||
* `Utils`:
|
||||
* Simple function `telegramBot(TelegramAPIUrlsKeeper)` has been deprecated with replacement by almost the same
|
||||
function in `Core`
|
||||
|
||||
## 0.30.6
|
||||
|
||||
* `Core`
|
||||
* `TextSource` properties has been renamed:
|
||||
* `asMarkdownSource` -> `markdown`
|
||||
* `asMarkdownV2Source` -> `markdownV2`
|
||||
* `asHtmlSource` -> `html`
|
||||
* `PrivateChat` override `id` property with type `UserId`
|
||||
* Several new extensions and functions in links creation:
|
||||
* New function `makeUsernameLink` with parameter `String`
|
||||
* New extension `Username#link` and function `makeLink(Username)`
|
||||
* Function `makeLinkToMessage` now able to get any type of chat
|
||||
* New extension `Message#link`
|
||||
* Old functions `makeLinkToAddStickerSet...` has been deprecated:
|
||||
* `makeLinkToAddStickerSet`
|
||||
* `makeLinkToAddStickerSetInMarkdownV2`
|
||||
* `makeLinkToAddStickerSetInMarkdown`
|
||||
* `makeLinkToAddStickerSetInHtml`
|
||||
|
||||
## 0.30.5
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `MicroUtils`: `0.3.3` -> `0.4.0`
|
||||
* `Core`:
|
||||
* Mechanism of `ChatMember` serialization has been changed
|
||||
* Since this version any `ChatMember` can be serialized (even outside in case it marked by `@Serializable`)
|
||||
* Since this version any `ChatMember` (included in this project) can be deserialized in common way
|
||||
* `User` property `id` has changed its type: now it is `UserId` (under the hood it is the same as `ChatId`)
|
||||
|
||||
## 0.30.4
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `MicroUtils`: `0.3.1` -> `0.3.3`
|
||||
* `Core`:
|
||||
* `MultilevelTextSource#textSources` has been safely renamed to `subsources`
|
||||
* `TextContent#fullEntitiesList` has been deprecated
|
||||
* Now `TextContent` implements `TextedInput`
|
||||
* `TextContent#entities` has been deprecated
|
||||
* `GroupEventMessage` now overrides `chatEvent` with type `GroupEvent`
|
||||
* `SupergroupEventMessage` now overrides `chatEvent` with type `SupergroupEvent`
|
||||
* Any `ChatEventMessage` now have generic type of its `chatEvent` (just like messages)
|
||||
* `Utils`:
|
||||
* Old extensions related to chat events are deprecated:
|
||||
* `Flow<ChatEventMessage<*>>#divideBySource`
|
||||
* `Flow<ChatEventMessage<*>>#onlyChannelEvents`
|
||||
* `Flow<ChatEventMessage<*>>#onlyGroupEvents`
|
||||
* `Flow<ChatEventMessage<*>>#onlySupergroupEvents`
|
||||
* A lot of extensions for `Flow<ChatEventMessage>` has been added:
|
||||
* `FlowsUpdatesFilter#events`
|
||||
* `FlowsUpdatesFilter#channelEvents`
|
||||
* `FlowsUpdatesFilter#groupEvents`
|
||||
* `FlowsUpdatesFilter#supergroupEvents`
|
||||
* And a lot of other filters with specific types
|
||||
|
||||
## 0.30.3
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `MicroUtils`: `0.3.0` -> `0.3.1`
|
||||
* `Core`:
|
||||
* New type of requests exceptions `TooMuchRequestsException`. In fact it will be rare case when you will get this
|
||||
exception
|
||||
* `EmptyLimiter` has been renamed to `ExceptionsOnlyLimiter` and currently will stop requests after
|
||||
`TooMuchRequestsException` happen until retry time is actual
|
||||
* Now `ExceptionsOnlyLimiter` (previously `EmptyLimiter`) is a class
|
||||
* `AbstractRequestCallFactory` currently will not look at the response and wait if it have `RetryAfter` error. New
|
||||
behaviour aimed on delegating of this work to `RequestsLimiter`
|
||||
|
||||
## 0.30.2
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `Ktor`: `1.4.1` -> `1.4.2`
|
||||
* `Core`:
|
||||
* New sealed class `SetWebhookRequest` which can be used in `SetWebhook` requests
|
||||
* `Utils`:
|
||||
* Extensions `setWebhookInfoAndStartListenWebhooks` has been united in one extension with `SetWebhookRequest`
|
||||
incoming parameter
|
||||
|
||||
## 0.30.1
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `MicroUtils`: `0.2.7` -> `0.3.0`
|
||||
* `Utils`:
|
||||
* Builder-style DSL for text sources - `buildEntities` (thanks to [djaler](https://github.com/djaler))
|
||||
|
||||
## 0.30.0 Bot API 5.0
|
||||
|
||||
**THIS UPDATE CONTAINS A LOT OF BREAKING CHANGES. PLEASE, BE CAREFUL ON UPGRADING OF YOUR PROJECT**
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `Coroutine`: `1.4.0` -> `1.4.1`
|
||||
* **NEW** `MicroUtils`: `0.2.7`
|
||||
* `Core`:
|
||||
* Support of `logOut` method (`LogOut` object as a `Request`)
|
||||
* Support of `close` method (`Close` object as a `Request`)
|
||||
* `SetWebhook` updates:
|
||||
* New field `ipAddress`. It works the same as `ip_address` in [setWebhook](https://core.telegram.org/bots/api#setwebhook)
|
||||
section
|
||||
* New field `dropPendingUpdates`. It works the same as `drop_pending_updates` in [setWebhook](https://core.telegram.org/bots/api#setwebhook)
|
||||
section
|
||||
* New field `ExtendedPrivateChat#bio`
|
||||
* New data class `ChatLocation`
|
||||
* New field `UnbanChatMember#onlyIfBanned`
|
||||
* New fields `ExtendedChannelChat#linkedGroupChatId` and `ExtendedSupergroupChat#linkedChannelChatId`
|
||||
* New fields `ExtendedSupergroupChat#location`
|
||||
* New fields `AudioFile#fileName` and `VideoFile#fileName`
|
||||
* New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection`
|
||||
* New request `UnpinAllChatMessages`
|
||||
* New parameter for `unpinChatMessage` method: `messageId`
|
||||
* New dice type `FootballDiceAnimationType`
|
||||
* Limits for dices has been changed
|
||||
* `commonDiceResultLimit` has been deprecated
|
||||
* New field `DiceAnimationType#valueLimits`
|
||||
* Locations updates:
|
||||
* New interface `Headed` with property `heading`
|
||||
* New interface `HorizontallyAccured` with property `horizontalAccuracy`
|
||||
* New interface `ProximityAlertable` with property `proximityAlertRadius`
|
||||
* `Location` class has been separated:
|
||||
* `StaticLocation` for static locations
|
||||
* `LiveLocation` for live locations
|
||||
* Property `Livable#livePeriod` now use typealias type `Seconds` (the same by meaning - `Int`)
|
||||
* `EditLocationMessage` now extends `Locationed`, `HorizontallyAccured`, `ProximityAlertable` and `Headed` interfaces
|
||||
* New properties in `EditChatMessageLiveLocation`: `horizontalAccuracy`, `heading`, `proximityAlertRadius`
|
||||
* New properties in `EditInlineMessageLiveLocation`: `horizontalAccuracy`, `heading`, `proximityAlertRadius`
|
||||
* Main constructor of `SendLocation` now is internal. Instead of that currently available next factories:
|
||||
* `SendLocation` - sending of static location without live parameters
|
||||
* `SendStaticLocation` - sending of static location without live parameters
|
||||
* `SendLiveLocation` - sending of live location with live parameters
|
||||
* `PositionedSendMessageRequest` now extends `Locationed`
|
||||
* `LocationContent#createResend` now can create `LiveLocation`
|
||||
* Support of `ProximityAlertTriggered`. It is `CommonEvent`
|
||||
* Property `pollQuestionTextLength` now have maximum up to `300`
|
||||
* Anonymous Admins:
|
||||
* New field `AdministratorChatMember#isAnonymous`
|
||||
* Several new interfaces of messages:
|
||||
* `SignedMessage` - any message which possibly have `authorSignature`
|
||||
* `WithSenderChatMessage` - any message which have `senderChat`. Property `senderChat` is not-nullable due to
|
||||
separation of implementators
|
||||
* `PublicMessage` - all channel messages have property `val chat: PublicChat` instead of common `val chat: Chat`
|
||||
* `ChannelMessage` - all channel messages have property `val chat: ChannelChat` instead of common `val chat: Chat`
|
||||
* Old `ChannelMessage` was safely renamed to `ChannelMessageImpl` (old name was set as typealias and deprecated)
|
||||
* `GroupMessage` - all group messages have property `val chat: GroupChat` instead of common `val chat: Chat`
|
||||
* `FromChannelGroupMessage` - instances should have property `val channel: ChannelChat`
|
||||
* `AnonymousGroupMessage` - instances may have setup property `authorSignature`
|
||||
* `CommonGroupMessage` - just common message
|
||||
* `PrivateMessage` - works like previous `CommonMessageImpl`
|
||||
* Previous `CommonMessageImpl` safely renamed to `PrivateMessageImpl`
|
||||
* New property `PromoteChatMember#isAnonymous`
|
||||
* Update all classes which must have `entities`/`caption_entities` fields
|
||||
* New request `CopyMessage`
|
||||
* New extension `List<TextSource>#makeString` for more comfortable work with new api with entities
|
||||
* Support for Google Places identifiers for venues
|
||||
* New extensions for text sources separating:
|
||||
* `List<TextSource>#separateForMessage`
|
||||
* `List<TextSource>#separateForCaption`
|
||||
* `List<TextSource>#separateForText`
|
||||
* Rewritten work with text sources and text parts:
|
||||
* Now any `Message` type with entities will have full list of entities. That means that parts without any
|
||||
formatter entities will use `RegularTextSource`
|
||||
* `MultilevelTextSource#textParts` has been deprecated. Now each `MultilevelTextSource` have its own
|
||||
`textSources` list
|
||||
* New dsl for creating of `TextSource` lists
|
||||
* Built-in `handleSafely` and `ExceptionHandler` is deprecated
|
||||
* New common factories for `StorageFile`
|
||||
* `API`:
|
||||
* Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat`
|
||||
* New extensions `TelegramBot#unpinAllChatMessages`
|
||||
* Extensions `TelegramBot#promoteChatMember` got `isAnonymous` parameter
|
||||
* All old api methods has been actualized to their analogs in `Core`
|
||||
* All `telegramBot` with `token: String` got `apiUrl` parameter
|
||||
* Factory `telegramBotWithCustomClientConfig` has been renamed to `telegramBot`
|
||||
|
||||
## 0.29.4
|
||||
|
||||
* `Core`:
|
||||
* `diceResultLimit` now is deprecated, use `commonDiceResultLimit` instead
|
||||
* New extension `slotMachineDiceResultLimit`
|
||||
* `Utils`:
|
||||
* New enum `SlotMachineReelImages`
|
||||
* New extension `Int#asSlotMachineReelImage`
|
||||
* New data class `SlotMachineResult`
|
||||
* New extension `Dice#calculateSlotMachineResult`
|
||||
|
||||
## 0.29.3
|
||||
|
||||
* `Common`:
|
||||
* Version updates:
|
||||
* `Serialization`: `1.0.0` -> `1.0.1`
|
||||
* `Core`:
|
||||
* New annotation `RiskFeature`. This annotation will be applied to the things which contains unsafe types usage
|
||||
* `SendMediaGroup` factory now marked with `RiskFeature`
|
||||
* Media groups updates:
|
||||
* New functions `SendPlaylist`
|
||||
* New functions `SendDocumentsGroup`
|
||||
* New functions `SendVisualMediaGroup`
|
||||
* New type `VisualMediaGroupMemberInputMedia : MediaGroupMemberInputMedia`
|
||||
* `InputMediaPhoto` now implements `VisualMediaGroupMemberInputMedia` instead of `MediaGroupMemberInputMedia`
|
||||
* `InputMediaVideo` now implements `VisualMediaGroupMemberInputMedia` instead of `MediaGroupMemberInputMedia`
|
||||
* New type `VisualMediaGroupContent : MediaGroupContent`
|
||||
* `PhotoContent` now implements `VisualMediaGroupContent` instead of `MediaGroupContent`
|
||||
* `VideoContent` now implements `VisualMediaGroupContent` instead of `MediaGroupContent`
|
||||
* New type `AudioMediaGroupContent : MediaGroupContent`
|
||||
* `AudioContent` now implements `AudioMediaGroupContent` instead of `MediaContent` and `CaptionedInput`
|
||||
* New type `DocumentMediaGroupContent : MediaGroupContent`
|
||||
* `DocumentContent` now implements `DocumentMediaGroupContent` instead of `MediaContent` and `CaptionedInput`
|
||||
* New type `AudioMediaGroupMemberInputMedia : MediaGroupMemberInputMedia`
|
||||
* `InputMediaAudio` now implements `AudioMediaGroupMemberInputMedia`
|
||||
* New type `DocumentMediaGroupMemberInputMedia : MediaGroupMemberInputMedia`
|
||||
* `InputMediaDocument` now implements `DocumentMediaGroupMemberInputMedia`
|
||||
* New extension `AudioFile#toInputMediaAudio`
|
||||
* `AudioContent` now implements `MediaGroupContent`
|
||||
* New extension `DocumentFile#toInputMediaDocument`
|
||||
* `DocumentContent` now implements `MediaGroupContent`
|
||||
* New dice type `SlotMachineDiceAnimationType`
|
||||
* New extension `TelegramMediaFile#asDocumentFile`
|
||||
* New extension `VideoFile#toInputMediaVideo`
|
||||
* New exception `WrongFileIdentifierException`
|
||||
* Extension `String#toInputMediaFileAttachmentName` now is deprecated
|
||||
* Property `ThumbedInputMedia#thumbMedia` now is deprecated
|
||||
* `API`:
|
||||
* New extensions for media groups:
|
||||
* `TelegramBot#sendPlaylist`
|
||||
* `TelegramBot#replyWithPlaylist`
|
||||
* `TelegramBot#sendDocumentsGroup`
|
||||
* `TelegramBot#replyWithDocumentsGroup`
|
||||
* `TelegramBot#sendVisualMediaGroup`
|
||||
* `TelegramBot#replyWithVisualMediaGroup`
|
||||
* `Utils`:
|
||||
* New extensions for `Flow`s:
|
||||
* `Flow<SentMediaGroupUpdate>#mediaGroupVisualMessages`
|
||||
* `Flow<SentMediaGroupUpdate>#mediaGroupAudioMessages`
|
||||
* `Flow<SentMediaGroupUpdate>#mediaGroupDocumentMessages`
|
||||
* New extensions for `FlowsUpdatesFilter`:
|
||||
* `FlowsUpdatesFilter#audioMessagesWithMediaGroups`
|
||||
* `FlowsUpdatesFilter#mediaGroupAudioMessages`
|
||||
* `FlowsUpdatesFilter#documentMessagesWithMediaGroups`
|
||||
* `FlowsUpdatesFilter#mediaGroupDocumentMessages`
|
||||
* `FlowsUpdatesFilter#mediaGroupVisualMessages`
|
||||
|
||||
## 0.29.2
|
||||
|
||||
* `Common`:
|
||||
* Version updates:
|
||||
* `Coroutines`: `1.3.9` -> `1.4.0`
|
||||
* Internal broadcast channels were replaced with `SharedFlow`
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Extension `ReceiveChannel#debounceByValue` has been deprecated
|
||||
|
||||
## 0.29.1
|
||||
|
||||
* `Common`:
|
||||
|
||||
22
README.md
22
README.md
@@ -1,17 +1,30 @@
|
||||
# TelegramBotAPI
|
||||
|
||||
<details>
|
||||
<summary><b>I do not wanna read a lot, just give me my bot</b></summary>
|
||||
|
||||
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 | [](https://github.com/KotlinBy/awesome-kotlin) [](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)|
|
||||
| -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| Useful links | [](https://t.me/InMoTelegramBotAPI) [](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) |
|
||||
| Useful links | [](https://t.me/InMoTelegramBotAPI) [](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [](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 | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.core/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core) |
|
||||
| TelegramBotAPI Extensions status | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.api/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api) |
|
||||
| TelegramBotAPI API Extensions status | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.api/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api) |
|
||||
| TelegramBotAPI Util Extensions status | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.utils/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils) |
|
||||
| TelegramBotAPI Behaviour Builder Extensions status | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.behaviour_builder/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder) |
|
||||
| TelegramBotAPI All status | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi/_latestVersion) [](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`**
|
||||
|
||||
## What is it?
|
||||
|
||||
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:
|
||||
@@ -22,6 +35,8 @@ the list of this complex currently next projects:
|
||||
`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
|
||||
|
||||
Most part of some specific solves or unuseful
|
||||
@@ -74,8 +89,9 @@ kotlin {
|
||||
|
||||

|
||||
|
||||
In most cases, the most simple way will be to implement [TelegramBotAPI](TelegramBotAPI/README.md) - it contains
|
||||
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).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<minder version="1.11.1">
|
||||
<minder version="1.11.3">
|
||||
<theme name="default" label="Default" index="-1"/>
|
||||
<styles>
|
||||
<style level="0" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
||||
@@ -14,45 +14,54 @@
|
||||
<style level="9" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
||||
<style level="10" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
||||
</styles>
|
||||
<drawarea x="-320.56697591145837" y="-10.028254191080691" scale="0.75"/>
|
||||
<drawarea x="-950.47548925255796" y="-49.650554065281653" scale="0.5"/>
|
||||
<images/>
|
||||
<nodes>
|
||||
<node id="0" posx="748.88964843749955" posy="119.42341613769531" width="472" height="168" side="top" fold="false" treesize="603" layout="Downwards" group="false">
|
||||
<node id="0" posx="1378.798161778599" posy="159.04571601189673" width="472" height="168" side="top" fold="false" treesize="743" layout="Downwards" group="false">
|
||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="439" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
||||
<nodename posx="764.88964843749955" posy="135.42341613769531" maxwidth="488.96484375">
|
||||
<nodename posx="1394.798161778599" posy="175.04571601189673" maxwidth="488.96484375">
|
||||
<text data="tgbotapi.core Root project with API. It is not recommended to use its requests directly and better to use at least tgbotapi.extensions.api"/>
|
||||
</nodename>
|
||||
<nodenote></nodenote>
|
||||
<nodes>
|
||||
<node id="1" posx="781.88964843749955" posy="387.42341613769531" width="406" height="145" side="bottom" fold="false" treesize="603" color="#68b723" colorroot="true" layout="Downwards" group="false">
|
||||
<node id="1" posx="1411.798161778599" posy="427.04571601189673" width="406" height="145" side="bottom" fold="false" treesize="743" color="#68b723" colorroot="true" layout="Downwards" group="false">
|
||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="none" nodewidth="394" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
||||
<nodename posx="797.88964843749955" posy="403.42341613769531" maxwidth="419.451171875">
|
||||
<nodename posx="1427.798161778599" posy="443.04571601189673" maxwidth="419.451171875">
|
||||
<text data="TelegramBotAPI extensions Family of projects which are fully based on TelegramBotAPI and extend its functionality"/>
|
||||
</nodename>
|
||||
<nodenote></nodenote>
|
||||
<nodes>
|
||||
<node id="2" posx="683.38964843749955" posy="632.42341613769531" width="296" height="191" side="bottom" fold="false" treesize="296" color="#68b723" colorroot="true" layout="Downwards" group="false">
|
||||
<node id="2" posx="1247.298161778599" posy="672.04571601189673" width="296" height="191" side="bottom" fold="false" treesize="296" color="#68b723" colorroot="true" layout="Downwards" group="false">
|
||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="203" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
||||
<nodename posx="699.38964843749955" posy="648.42341613769531" maxwidth="295.90315755208337">
|
||||
<nodename posx="1263.298161778599" posy="688.04571601189673" maxwidth="295.90315755208337">
|
||||
<text data="tgbotapi.extensions.api Extensions project for make requests more look like in the Telegram Bot API and give opportunity to use it's easier"/>
|
||||
</nodename>
|
||||
<nodenote></nodenote>
|
||||
</node>
|
||||
<node id="3" posx="979.38964843749955" posy="632.42341613769531" width="307" height="168" side="bottom" fold="false" treesize="307" color="#68b723" colorroot="true" layout="Downwards" group="false">
|
||||
<node id="3" posx="1609.298161778599" posy="672.04571601189673" width="307" height="168" side="bottom" fold="false" treesize="439" color="#68b723" colorroot="true" layout="Downwards" group="false">
|
||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="286" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
||||
<nodename posx="995.38964843749955" posy="648.42341613769531" maxwidth="299.252197265625">
|
||||
<nodename posx="1625.298161778599" posy="688.04571601189673" maxwidth="299.252197265625">
|
||||
<text data="tgbotapi.extensions.utils Extensions project with utils things which will make easier different operations"/>
|
||||
</nodename>
|
||||
<nodenote></nodenote>
|
||||
<nodes>
|
||||
<node id="4" posx="1543.298161778599" posy="940.04571601189673" width="439" height="122" side="bottom" fold="false" treesize="439" color="#68b723" colorroot="false" layout="Downwards" group="false">
|
||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="387" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
||||
<nodename posx="1559.298161778599" posy="956.04571601189673" maxwidth="408.97932942708348">
|
||||
<text data="tgbotapi.extensions.behaviour_builder Extension project for building bot behaviour via special dsl"/>
|
||||
</nodename>
|
||||
<nodenote></nodenote>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
<node id="4" posx="815.52319335937455" posy="948.04447937011719" width="329" height="213" side="top" fold="false" treesize="329" layout="Downwards" group="false">
|
||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="388" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
||||
<nodename posx="831.52319335937455" posy="964.04447937011719" maxwidth="394.3671875">
|
||||
<text data="tgbotapi Here included all available TelegramBotAPI libraries: * tgbotapi.core * tgbotapi.extensions.api * tgbotapi.extensions.utils">
|
||||
<node id="5" posx="1391.8445078072455" posy="1155.6062730594231" width="461" height="236" side="bottom" fold="false" treesize="461" layout="Downwards" group="false">
|
||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="430" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
||||
<nodename posx="1407.8445078072455" posy="1171.6062730594231" maxwidth="453.885498046875">
|
||||
<text data="tgbotapi Here included all available TelegramBotAPI libraries: * tgbotapi.core * tgbotapi.extensions.api * tgbotapi.extensions.utils * tgbotapi.extensions.behaviour_builder">
|
||||
<color>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
@@ -70,6 +79,94 @@
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
||||
@@ -102,6 +199,90 @@
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
||||
</color>
|
||||
</text>
|
||||
</nodename>
|
||||
@@ -110,12 +291,17 @@
|
||||
</nodes>
|
||||
<groups/>
|
||||
<connections>
|
||||
<connection from_id="2" to_id="4" drag_x="905.70642089843705" drag_y="891.23394775390625" color="#777777">
|
||||
<connection from_id="2" to_id="5" drag_x="1475.8213347929195" drag_y="1014.8259945356604" color="#777777">
|
||||
<style connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
||||
<title></title>
|
||||
<note></note>
|
||||
</connection>
|
||||
<connection from_id="3" to_id="4" drag_x="1056.456420898437" drag_y="885.48394775390625" color="#777777">
|
||||
<connection from_id="4" to_id="5" drag_x="1691.5447998046875" drag_y="1107.00439453125" color="#777777">
|
||||
<style connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
||||
<title></title>
|
||||
<note></note>
|
||||
</connection>
|
||||
<connection from_id="3" to_id="5" drag_x="1483.48876953125" drag_y="896.18115234375">
|
||||
<style connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
||||
<title></title>
|
||||
<note></note>
|
||||
|
||||
20
badges/template.svg
Normal file
20
badges/template.svg
Normal file
@@ -0,0 +1,20 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="104" height="20">
|
||||
<linearGradient id="b" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
</linearGradient>
|
||||
<clipPath id="a">
|
||||
<rect width="104" height="20" rx="3" fill="#fff"/>
|
||||
</clipPath>
|
||||
<g clip-path="url(#a)">
|
||||
<path fill="#555" d="M0 0h65v20H0z"/>
|
||||
<path fill="#007ec6" d="M35 0h69v20H35z"/>
|
||||
<path fill="url(#b)" d="M0 0h104v20H0z"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110">
|
||||
<text x="175" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)">Bot</text>
|
||||
<text x="175" y="140" transform="scale(.1)">Bot</text>
|
||||
<text x="690" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)">Template</text>
|
||||
<text x="690" y="140" transform="scale(.1)">Template</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1016 B |
@@ -9,7 +9,6 @@ buildscript {
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
||||
classpath "com.github.breadmoirai:github-release:$github_release_plugin_version"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,29 +46,17 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
private Closure includeSourcesInDokka(String... approximateNames) {
|
||||
return {
|
||||
parent.subprojects.forEach {
|
||||
if (it != project) {
|
||||
File srcDir = new File(it.projectDir.absolutePath, "src")
|
||||
if (srcDir.exists() && srcDir.isDirectory()) {
|
||||
srcDir.eachFile { file ->
|
||||
if (approximateNames.any { file.name.contains(it) } && file.isDirectory()) {
|
||||
String pathToSrc = file.absolutePath
|
||||
sourceRoot {
|
||||
path = pathToSrc
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private List<SourceDirectorySet> findSourcesWithName(String... approximateNames) {
|
||||
return parent.subprojects
|
||||
.findAll { it != project }
|
||||
.collectMany { it.kotlin.sourceSets }
|
||||
.findAll { sourceSet -> approximateNames.any {
|
||||
nameToFilter -> sourceSet.name.contains(nameToFilter)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.collect { it.kotlin }
|
||||
}
|
||||
|
||||
dokka {
|
||||
outputFormat = 'html'
|
||||
|
||||
tasks.dokkaHtml {
|
||||
switch (true) {
|
||||
case project.hasProperty("DOKKA_PATH"):
|
||||
outputDirectory = project.property("DOKKA_PATH").toString()
|
||||
@@ -78,19 +66,27 @@ dokka {
|
||||
break
|
||||
}
|
||||
|
||||
multiplatform {
|
||||
global {
|
||||
skipDeprecated = true
|
||||
dokkaSourceSets {
|
||||
configureEach {
|
||||
skipDeprecated.set(true)
|
||||
|
||||
sourceLink {
|
||||
path = "./"
|
||||
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/"
|
||||
lineSuffix = "#L"
|
||||
localDirectory.set(file("./"))
|
||||
remoteUrl.set(new URL("https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/"))
|
||||
remoteLineSuffix.set("#L")
|
||||
}
|
||||
}
|
||||
|
||||
common(includeSourcesInDokka("commonMain"))
|
||||
js(includeSourcesInDokka("jsMain"/*, "commonMain"*/))
|
||||
jvm(includeSourcesInDokka("jvmMain"/*, "commonMain"*/))
|
||||
named("commonMain") {
|
||||
sourceRoots.setFrom(findSourcesWithName("commonMain"))
|
||||
}
|
||||
|
||||
named("jsMain") {
|
||||
sourceRoots.setFrom(findSourcesWithName("jsMain", "commonMain"))
|
||||
}
|
||||
|
||||
named("jvmMain") {
|
||||
sourceRoots.setFrom(findSourcesWithName("jvmMain", "commonMain"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
dokka_version=0.10.1
|
||||
dokka_version=1.4.20
|
||||
|
||||
org.gradle.jvmargs=-Xmx1024m
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
org.gradle.jvmargs=-Xmx1024m
|
||||
org.gradle.jvmargs=-Xmx2048m
|
||||
kotlin.code.style=official
|
||||
org.gradle.parallel=true
|
||||
kotlin.js.generate.externals=true
|
||||
kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
kotlin_version=1.4.10
|
||||
kotlin_coroutines_version=1.3.9
|
||||
kotlin_serialisation_runtime_version=1.0.0
|
||||
klock_version=1.12.1
|
||||
uuid_version=0.2.2
|
||||
ktor_version=1.4.1
|
||||
kotlin_version=1.4.21
|
||||
kotlin_coroutines_version=1.4.2
|
||||
kotlin_serialisation_runtime_version=1.0.1
|
||||
klock_version=2.0.4
|
||||
uuid_version=0.2.3
|
||||
ktor_version=1.5.1
|
||||
|
||||
micro_utils_version=0.4.23
|
||||
|
||||
javax_activation_version=1.1.1
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=0.29.1
|
||||
library_version=0.32.2
|
||||
|
||||
gradle_bintray_plugin_version=1.8.5
|
||||
github_release_plugin_version=2.2.12
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -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.6.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 89 KiB |
@@ -1,5 +1,13 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
include ":tgbotapi.core"
|
||||
include ":tgbotapi.extensions.api"
|
||||
include ":tgbotapi.extensions.utils"
|
||||
include ":tgbotapi.extensions.behaviour_builder"
|
||||
include ":tgbotapi"
|
||||
include ":docs"
|
||||
|
||||
@@ -10,10 +10,7 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/
|
||||
|
||||
## Compatibility
|
||||
|
||||
This version compatible with [4th of June 2020 update of TelegramBotAPI (version 4.9)](https://core.telegram.org/bots/api#june-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.
|
||||
This version compatible with [4th of November 2020 update of TelegramBotAPI (version 5.0)](https://core.telegram.org/bots/api#november-4-2020).
|
||||
|
||||
## 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)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -8,7 +8,6 @@ buildscript {
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +46,11 @@ 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"
|
||||
}
|
||||
}
|
||||
@@ -72,7 +76,6 @@ kotlin {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
|
||||
jsTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"bintrayConfig":{"repo":"TelegramBotAPI","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI","autoPublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Core","description":"Library for Object-Oriented and type-safe work with Telegram Bot API","url":"https://insanusmokrassar.github.io/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"}
|
||||
{"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"}]}}
|
||||
@@ -1,58 +1,75 @@
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
apply from: "maven.publish.gradle"
|
||||
|
||||
bintray {
|
||||
user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
|
||||
key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
|
||||
filesSpec {
|
||||
from "${buildDir}/publications/"
|
||||
eachFile {
|
||||
String directorySubname = it.getFile().parentFile.name
|
||||
if (it.getName() == "module.json") {
|
||||
if (directorySubname == "kotlinMultiplatform") {
|
||||
it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.module")
|
||||
} else {
|
||||
it.setPath("${project.name}-${directorySubname}/${project.version}/${project.name}-${directorySubname}-${project.version}.module")
|
||||
}
|
||||
} else {
|
||||
if (directorySubname == "kotlinMultiplatform" && it.getName() == "pom-default.xml") {
|
||||
it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.pom")
|
||||
} else {
|
||||
it.exclude()
|
||||
}
|
||||
}
|
||||
}
|
||||
into "${project.group}".replace(".", "/")
|
||||
}
|
||||
|
||||
publish = true
|
||||
|
||||
pkg {
|
||||
repo = "TelegramBotAPI"
|
||||
name = "${project.name}"
|
||||
vcsUrl = "https://github.com/InsanusMokrassar/TelegramBotAPI"
|
||||
licenses = ["Apache-2.0"]
|
||||
version {
|
||||
name = "${project.version}"
|
||||
released = new Date()
|
||||
vcsTag = "${project.version}"
|
||||
gpg {
|
||||
sign = true
|
||||
passphrase = project.hasProperty('signing.gnupg.passphrase') ? project.property('signing.gnupg.passphrase') : System.getenv('signing.gnupg.passphrase')
|
||||
}
|
||||
}
|
||||
}
|
||||
task javadocsJar(type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
}
|
||||
task sourceJar (type : Jar) {
|
||||
classifier = 'sources'
|
||||
}
|
||||
|
||||
bintrayUpload.doFirst {
|
||||
publications = publishing.publications.collect {
|
||||
afterEvaluate {
|
||||
project.publishing.publications.all {
|
||||
// rename artifacts
|
||||
groupId "${project.group}"
|
||||
if (it.name.contains('kotlinMultiplatform')) {
|
||||
null
|
||||
artifactId = "${project.name}"
|
||||
artifact sourceJar
|
||||
} else {
|
||||
it.name
|
||||
artifactId = "${project.name}-$name"
|
||||
}
|
||||
} - null
|
||||
}
|
||||
}
|
||||
|
||||
bintrayUpload.dependsOn publishToMavenLocal
|
||||
publishing {
|
||||
publications.all {
|
||||
artifact javadocsJar
|
||||
|
||||
pom {
|
||||
description = "Library for Object-Oriented and type-safe work with Telegram Bot API"
|
||||
name = "Telegram Bot API Core"
|
||||
url = "https://insanusmokrassar.github.io/TelegramBotAPI"
|
||||
|
||||
scm {
|
||||
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
|
||||
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
|
||||
}
|
||||
|
||||
developers {
|
||||
|
||||
developer {
|
||||
id = "InsanusMokrassar"
|
||||
name = "Ovsiannikov Aleksei"
|
||||
email = "ovsyannikov.alexey95@gmail.com"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
licenses {
|
||||
|
||||
license {
|
||||
name = "Apache Software License 2.0"
|
||||
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "bintray"
|
||||
url = uri("https://api.bintray.com/maven/${project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')}/TelegramBotAPI/${project.name}/;publish=1;override=1")
|
||||
credentials {
|
||||
username = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
|
||||
password = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
useGpgCmd()
|
||||
publishing.publications.forEach { sign it }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.utils.fullListOfSubSource
|
||||
|
||||
interface Captioned {
|
||||
val caption: String?
|
||||
@@ -13,14 +12,14 @@ interface CaptionedOutput : Captioned {
|
||||
|
||||
interface CaptionedInput : Captioned {
|
||||
/**
|
||||
* Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
|
||||
* @see [CaptionedInput.fullEntitiesList]
|
||||
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
|
||||
*/
|
||||
val captionEntities: List<TextPart>
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert its [CaptionedInput.captionEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
|
||||
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
|
||||
* @see CaptionedInput.captionEntities
|
||||
* @see justTextSources
|
||||
*/
|
||||
fun CaptionedInput.fullEntitiesList(): FullTextSourcesList = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList()
|
||||
val CaptionedInput.textSources
|
||||
get() = captionEntities.justTextSources()
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
|
||||
interface CommonVenueData : Titled {
|
||||
override val title: String
|
||||
val address: String
|
||||
val foursquareId: String?
|
||||
val foursquareType: String? // TODO:: Rewrite with enum or interface
|
||||
val foursquareId: FoursquareId?
|
||||
val foursquareType: FoursquareType? // TODO:: Rewrite with enum or interface
|
||||
val googlePlaceId: GooglePlaceId?
|
||||
val googlePlaceType: GooglePlaceType?
|
||||
}
|
||||
|
||||
@@ -1,26 +1,31 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.utils.fullListOfSubSource
|
||||
|
||||
interface Explained {
|
||||
val explanation: String?
|
||||
}
|
||||
|
||||
interface ExplainedOutput : Explained {
|
||||
interface ParsableExplainedOutput : Explained {
|
||||
val parseMode: ParseMode?
|
||||
}
|
||||
|
||||
interface EntitiesExplainedOutput : Explained {
|
||||
val entities: List<TextSource>?
|
||||
}
|
||||
|
||||
interface ExplainedOutput : ParsableExplainedOutput, EntitiesExplainedOutput
|
||||
|
||||
interface ExplainedInput : Explained {
|
||||
/**
|
||||
* Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
|
||||
* @see [ExplainedInput.fullEntitiesList]
|
||||
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
|
||||
*/
|
||||
val explanationEntities: List<TextPart>
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert its [ExplainedInput.explanationEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
|
||||
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
|
||||
* @see ExplainedInput.explanationEntities
|
||||
* @see justTextSources
|
||||
*/
|
||||
fun ExplainedInput.fullEntitiesList(): FullTextSourcesList = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList()
|
||||
val ExplainedInput.textSources
|
||||
get() = explanationEntities.justTextSources()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.Degrees
|
||||
|
||||
interface Headed {
|
||||
val heading: Degrees?
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.Meters
|
||||
|
||||
interface HorizontallyAccured {
|
||||
val horizontalAccuracy: Meters?
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.Seconds
|
||||
|
||||
interface Livable {
|
||||
/**
|
||||
* Period in SECONDS
|
||||
* Period in [Seconds]
|
||||
*/
|
||||
val livePeriod: Int?
|
||||
val livePeriod: Seconds?
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.Meters
|
||||
|
||||
interface ProximityAlertable {
|
||||
val proximityAlertRadius: Meters?
|
||||
}
|
||||
@@ -1,18 +1,35 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
typealias FullTextSourcesList = List<TextSource>
|
||||
typealias FullTextPartsList = List<TextPart>
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.regular
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.toTextParts
|
||||
import dev.inmo.tgbotapi.types.captionLength
|
||||
import dev.inmo.tgbotapi.types.textLength
|
||||
|
||||
const val DirectInvocationOfTextSourceConstructor = "It is strongly not recommended to use constructors directly instead of factory methods"
|
||||
|
||||
typealias TextSourcesList = List<TextSource>
|
||||
|
||||
interface TextSource {
|
||||
val asMarkdownSource: String
|
||||
val asMarkdownV2Source: String
|
||||
val asHtmlSource: String
|
||||
val markdown: String
|
||||
val markdownV2: String
|
||||
val html: String
|
||||
val source: String
|
||||
|
||||
val asText: String
|
||||
get() = source
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline operator fun TextSource.plus(other: TextSource) = listOf(this, other)
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline operator fun TextSource.plus(other: List<TextSource>) = listOf(this) + other
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline operator fun TextSource.plus(text: String) = listOf(this, regular(text))
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline operator fun List<TextSource>.plus(text: String) = this + regular(text)
|
||||
|
||||
interface MultilevelTextSource : TextSource {
|
||||
val textParts: List<TextPart>
|
||||
val subsources: List<TextSource>
|
||||
}
|
||||
|
||||
data class TextPart(
|
||||
@@ -21,3 +38,49 @@ data class TextPart(
|
||||
)
|
||||
|
||||
fun List<TextPart>.justTextSources() = map { it.source }
|
||||
fun List<TextSource>.makeString() = joinToString("") { it.source }
|
||||
internal fun MultilevelTextSource.textParts(offset: Int): List<TextPart> = subsources.toTextParts(offset)
|
||||
fun List<TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List<List<TextSource>> {
|
||||
if (isEmpty()) {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
val resultList = mutableListOf<MutableList<TextSource>>(mutableListOf())
|
||||
var currentPartLength = 0
|
||||
val maxSize = limit.last + 1
|
||||
|
||||
for (current in this) {
|
||||
if (current.source.length > maxSize) {
|
||||
error("Currently unsupported parts with size more than target one-message parts (${current.source.length} > ${maxSize})")
|
||||
}
|
||||
|
||||
if (currentPartLength + current.source.length > maxSize) {
|
||||
if (numberOfParts == null || numberOfParts < resultList.size) {
|
||||
resultList.add(mutableListOf())
|
||||
currentPartLength = 0
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
resultList.last().add(current)
|
||||
currentPartLength += current.source.length
|
||||
}
|
||||
|
||||
return resultList
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will prepare [TextSource]s list for messages. Remember, that first part will be separated with
|
||||
* [captionLength] and all others with
|
||||
*/
|
||||
fun List<TextSource>.separateForCaption(): List<List<TextSource>> {
|
||||
val captionPart = separateForMessage(captionLength, 1).first()
|
||||
return listOf(captionPart) + minus(captionPart).separateForMessage(textLength)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will prepare [TextSource]s list for messages with [textLength]
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun List<TextSource>.separateForText(): List<List<TextSource>> = separateForMessage(textLength)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
|
||||
interface Texted {
|
||||
val text: String?
|
||||
}
|
||||
|
||||
interface ParsableOutput : Texted {
|
||||
val parseMode: ParseMode?
|
||||
}
|
||||
|
||||
interface EntitiesOutput : Texted {
|
||||
val entities: List<TextSource>?
|
||||
}
|
||||
|
||||
interface TextedOutput : ParsableOutput, EntitiesOutput
|
||||
|
||||
interface TextedInput : Texted {
|
||||
/**
|
||||
* Here must be full list of entities. This list must contains [TextPart]s with
|
||||
* [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] in case if source text contains parts of
|
||||
* regular text
|
||||
*/
|
||||
val textEntities: List<TextPart>
|
||||
}
|
||||
|
||||
/**
|
||||
* Full list of [TextSource] built from source[TextedInput.textEntities]
|
||||
*
|
||||
* @see TextedInput.textEntities
|
||||
* @see justTextSources
|
||||
*/
|
||||
val TextedInput.textSources
|
||||
get() = textEntities.justTextSources()
|
||||
@@ -4,4 +4,5 @@ import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||
|
||||
interface ReplyMessageId {
|
||||
val replyToMessageId: MessageIdentifier?
|
||||
val allowSendingWithoutReply: Boolean?
|
||||
}
|
||||
@@ -1,25 +1,53 @@
|
||||
package dev.inmo.tgbotapi.bot.Ktor
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
|
||||
import dev.inmo.tgbotapi.bot.Ktor.base.*
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.bot.exceptions.newRequestException
|
||||
import dev.inmo.tgbotapi.bot.settings.limiters.EmptyLimiter
|
||||
import dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter
|
||||
import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.Response
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.features.*
|
||||
import io.ktor.client.statement.HttpStatement
|
||||
import io.ktor.client.statement.readText
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class KtorRequestsExecutorBuilder(
|
||||
var telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
||||
) {
|
||||
var client: HttpClient = HttpClient()
|
||||
var callsFactories: List<KtorCallFactory> = emptyList()
|
||||
var excludeDefaultFactories: Boolean = false
|
||||
var requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter()
|
||||
var jsonFormatter: Json = nonstrictJsonFormat
|
||||
|
||||
fun build() = KtorRequestsExecutor(telegramAPIUrlsKeeper, client, callsFactories, excludeDefaultFactories, requestsLimiter, jsonFormatter)
|
||||
}
|
||||
|
||||
inline fun telegramBot(
|
||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||
crossinline builder: KtorRequestsExecutorBuilder.() -> Unit = {}
|
||||
): TelegramBot = KtorRequestsExecutorBuilder(telegramAPIUrlsKeeper).apply(builder).build()
|
||||
|
||||
/**
|
||||
* Shortcut for [telegramBot]
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun telegramBot(
|
||||
token: String,
|
||||
apiUrl: String = telegramBotAPIDefaultUrl,
|
||||
crossinline builder: KtorRequestsExecutorBuilder.() -> Unit = {}
|
||||
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), builder)
|
||||
|
||||
class KtorRequestsExecutor(
|
||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||
client: HttpClient = HttpClient(),
|
||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||
excludeDefaultFactories: Boolean = false,
|
||||
private val requestsLimiter: RequestLimiter = EmptyLimiter,
|
||||
private val requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter(),
|
||||
private val jsonFormatter: Json = nonstrictJsonFormat
|
||||
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
||||
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
||||
@@ -37,10 +65,10 @@ class KtorRequestsExecutor(
|
||||
}
|
||||
|
||||
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||
return handleSafely(
|
||||
return safely(
|
||||
{ e ->
|
||||
throw if (e is ClientRequestException) {
|
||||
val content = e.response ?.readText() ?: throw e
|
||||
val content = e.response.readText()
|
||||
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
|
||||
newRequestException(
|
||||
responseObject,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package dev.inmo.tgbotapi.bot.Ktor.base
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory
|
||||
import dev.inmo.tgbotapi.bot.exceptions.newRequestException
|
||||
import dev.inmo.tgbotapi.requests.GetUpdates
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.Response
|
||||
import dev.inmo.tgbotapi.types.RetryAfterError
|
||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.receive
|
||||
@@ -13,7 +13,6 @@ import io.ktor.client.features.timeout
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.http.ContentType
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlin.collections.set
|
||||
|
||||
@@ -51,23 +50,17 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
|
||||
val content = response.receive<String>()
|
||||
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
|
||||
|
||||
return (responseObject.result?.let {
|
||||
jsonFormatter.decodeFromJsonElement(request.resultDeserializer, it)
|
||||
} ?: responseObject.parameters?.let {
|
||||
val error = it.error
|
||||
if (error is RetryAfterError) {
|
||||
delay(error.leftToRetry)
|
||||
makeCall(client, urlsKeeper, request, jsonFormatter)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?: response.let {
|
||||
throw newRequestException(
|
||||
responseObject,
|
||||
content,
|
||||
"Can't get result object from $content"
|
||||
)
|
||||
})
|
||||
return safely {
|
||||
(responseObject.result?.let {
|
||||
jsonFormatter.decodeFromJsonElement(request.resultDeserializer, it)
|
||||
} ?: response.let {
|
||||
throw newRequestException(
|
||||
responseObject,
|
||||
content,
|
||||
"Can't get result object from $content"
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package dev.inmo.tgbotapi.bot.Ktor.base
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory
|
||||
import dev.inmo.tgbotapi.bot.RequestsExecutor
|
||||
import dev.inmo.tgbotapi.requests.DownloadFile
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||
import dev.inmo.tgbotapi.utils.handleSafely
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.client.request.get
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
object DownloadFileRequestCallFactory : KtorCallFactory {
|
||||
@@ -21,7 +18,7 @@ object DownloadFileRequestCallFactory : KtorCallFactory {
|
||||
): T? = (request as? DownloadFile) ?.let {
|
||||
val fullUrl = "${urlsKeeper.fileBaseUrl}/${it.filePath}"
|
||||
|
||||
return handleSafely {
|
||||
return safely {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
client.get<ByteArray>(fullUrl) as T // always ByteArray
|
||||
}
|
||||
|
||||
@@ -25,10 +25,9 @@ object MultipartRequestCallFactory : AbstractRequestCallFactory() {
|
||||
Headers.build {
|
||||
append(HttpHeaders.ContentType, value.mimeType)
|
||||
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
|
||||
}
|
||||
) {
|
||||
value.file.asInput()
|
||||
}
|
||||
},
|
||||
block = value.file::input
|
||||
)
|
||||
is FileId -> append(key, value.fileId)
|
||||
else -> append(key, value.toString())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package dev.inmo.tgbotapi.bot.exceptions
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.types.Response
|
||||
import dev.inmo.tgbotapi.types.RetryAfterError
|
||||
import io.ktor.utils.io.errors.IOException
|
||||
|
||||
fun newRequestException(
|
||||
@@ -15,6 +17,14 @@ fun newRequestException(
|
||||
description.contains("Bad Request: message is not modified") -> MessageIsNotModifiedException(response, plainAnswer, message, cause)
|
||||
description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
|
||||
description.contains("PHOTO_INVALID_DIMENSIONS") -> InvalidPhotoDimensionsException(response, plainAnswer, message, cause)
|
||||
description.contains("wrong file identifier") -> WrongFileIdentifierException(response, plainAnswer, message, cause)
|
||||
description.contains("Too Many Requests") -> TooMuchRequestsException(
|
||||
(response.parameters ?.error as? RetryAfterError) ?: RetryAfterError(60, DateTime.now().unixMillisLong),
|
||||
response,
|
||||
plainAnswer,
|
||||
message,
|
||||
cause
|
||||
)
|
||||
else -> null
|
||||
}
|
||||
} ?: CommonRequestException(response, plainAnswer, message, cause)
|
||||
@@ -45,3 +55,9 @@ class MessageToEditNotFoundException(response: Response, plainAnswer: String, me
|
||||
|
||||
class InvalidPhotoDimensionsException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
class WrongFileIdentifierException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
class TooMuchRequestsException(val retryAfter: RetryAfterError, response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
@@ -1,67 +1,39 @@
|
||||
package dev.inmo.tgbotapi.bot.settings.limiters
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.types.MilliSeconds
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
private fun now(): Long = DateTime.nowUnixLong()
|
||||
|
||||
@Serializable
|
||||
class CommonLimiter(
|
||||
private val lockCount: Int = 10,
|
||||
private val regenTime: Long = 20 * 1000L // 20 seconds for full regen of opportunity to send message
|
||||
private val regenTime: MilliSeconds = 15 * 1000, // 15 seconds for full regen of opportunity to send message
|
||||
@Transient
|
||||
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
) : RequestLimiter {
|
||||
private var doLimit: Boolean = false
|
||||
|
||||
private val counterChannel = Channel<Unit>(Channel.UNLIMITED)
|
||||
private val scope = CoroutineScope(Dispatchers.Default)
|
||||
private val counterJob = scope.launch {
|
||||
var wasLastSecond = 0
|
||||
var lastCountTime = now()
|
||||
var limitManagementJob: Job? = null
|
||||
var removeLimitTime: Long = lastCountTime
|
||||
for (counter in counterChannel) {
|
||||
val now = now()
|
||||
if (now - lastCountTime > 1000) {
|
||||
lastCountTime = now
|
||||
wasLastSecond = 1
|
||||
} else {
|
||||
wasLastSecond++
|
||||
}
|
||||
if (wasLastSecond >= lockCount) {
|
||||
removeLimitTime = now + regenTime
|
||||
if (limitManagementJob == null) {
|
||||
limitManagementJob = launch {
|
||||
doLimit = true
|
||||
var internalNow = now()
|
||||
while (internalNow < removeLimitTime) {
|
||||
delay(removeLimitTime - internalNow)
|
||||
internalNow = now()
|
||||
}
|
||||
doLimit = false
|
||||
}
|
||||
private val quotaSemaphore = Semaphore(lockCount)
|
||||
private val counterRegeneratorJob = scope.launch {
|
||||
val regenDelay: MilliSeconds = (regenTime.toDouble() / lockCount).roundToLong()
|
||||
while (isActive) {
|
||||
delay(regenDelay)
|
||||
if (quotaSemaphore.availablePermits < lockCount) {
|
||||
try {
|
||||
quotaSemaphore.release()
|
||||
} catch (_: IllegalStateException) {
|
||||
// Skip IllegalStateException due to the fact that this exception may happens in release method
|
||||
}
|
||||
}
|
||||
if (now > removeLimitTime) {
|
||||
limitManagementJob = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val quoterChannel = Channel<Unit>(Channel.CONFLATED)
|
||||
private val tickerJob = scope.launch {
|
||||
while (isActive) {
|
||||
quoterChannel.send(Unit)
|
||||
delay(1000L)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T> limit(block: suspend () -> T): T {
|
||||
counterChannel.send(Unit)
|
||||
return if (!doLimit) {
|
||||
block()
|
||||
} else {
|
||||
quoterChannel.receive()
|
||||
block()
|
||||
}
|
||||
quotaSemaphore.acquire()
|
||||
return block()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package dev.inmo.tgbotapi.bot.settings.limiters
|
||||
|
||||
object EmptyLimiter : RequestLimiter {
|
||||
override suspend fun <T> limit(block: suspend () -> T): T = block()
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package dev.inmo.tgbotapi.bot.settings.limiters
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.tgbotapi.bot.exceptions.TooMuchRequestsException
|
||||
import dev.inmo.tgbotapi.types.MilliSeconds
|
||||
import dev.inmo.tgbotapi.types.RetryAfterError
|
||||
import io.ktor.client.features.ClientRequestException
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
||||
/**
|
||||
* This limiter will limit requests only after getting a [RetryAfterError] or [ClientRequestException] with
|
||||
* [HttpStatusCode.TooManyRequests] status code. Important thing is that in case if some of block has been blocked, all
|
||||
* the others will wait until it will be possible to be called
|
||||
*
|
||||
* @param defaultTooManyRequestsDelay This parameter will be used in case of getting [ClientRequestException] with
|
||||
* [HttpStatusCode.TooManyRequests] as a parameter for delay like it would be [TooMuchRequestsException]. The reason of
|
||||
* it is that in [ClientRequestException] there is no information about required delay between requests
|
||||
*/
|
||||
class ExceptionsOnlyLimiter(
|
||||
private val defaultTooManyRequestsDelay: MilliSeconds = 1000L
|
||||
) : RequestLimiter {
|
||||
private val lockState = MutableStateFlow(false)
|
||||
private suspend fun lock(timeMillis: MilliSeconds) {
|
||||
try {
|
||||
safely {
|
||||
lockState.emit(true)
|
||||
delay(timeMillis)
|
||||
}
|
||||
} finally {
|
||||
lockState.emit(false)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T> limit(block: suspend () -> T): T {
|
||||
while (true) {
|
||||
lockState.first { !it }
|
||||
val result = safely({
|
||||
when (it) {
|
||||
is TooMuchRequestsException -> {
|
||||
lock(it.retryAfter.leftToRetry)
|
||||
Result.failure(it)
|
||||
}
|
||||
is ClientRequestException -> {
|
||||
if (it.response.status == HttpStatusCode.TooManyRequests) {
|
||||
lock(defaultTooManyRequestsDelay)
|
||||
} else {
|
||||
throw it
|
||||
}
|
||||
Result.failure(it)
|
||||
}
|
||||
else -> throw it
|
||||
}
|
||||
}) {
|
||||
Result.success(block())
|
||||
}
|
||||
if (result.isSuccess) {
|
||||
return result.getOrNull()!!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package dev.inmo.tgbotapi.bot.settings.limiters
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.actor
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.tgbotapi.types.MilliSeconds
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
import kotlin.coroutines.*
|
||||
@@ -9,62 +11,60 @@ import kotlin.math.pow
|
||||
|
||||
private sealed class RequestEvent
|
||||
private class AddRequest(
|
||||
val continuation: Continuation<Long>
|
||||
val continuation: Continuation<MilliSeconds>
|
||||
) : RequestEvent()
|
||||
private object CompleteRequest : RequestEvent()
|
||||
|
||||
@Serializable
|
||||
data class PowLimiter(
|
||||
private val minAwaitTime: Long = 0L,
|
||||
private val maxAwaitTime: Long = 10000L,
|
||||
private val minAwaitTime: MilliSeconds = 0L,
|
||||
private val maxAwaitTime: MilliSeconds = 10000L,
|
||||
private val powValue: Double = 4.0,
|
||||
private val powK: Double = 0.0016
|
||||
private val powK: Double = 1.6,
|
||||
@Transient
|
||||
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
) : RequestLimiter {
|
||||
@Transient
|
||||
private val scope = CoroutineScope(Dispatchers.Default)
|
||||
@Transient
|
||||
private val eventsChannel = Channel<RequestEvent>(Channel.UNLIMITED)
|
||||
@Transient
|
||||
private val awaitTimeRange = minAwaitTime .. maxAwaitTime
|
||||
@Transient
|
||||
private val eventsChannel = let {
|
||||
var requestsInWork = 0.0
|
||||
scope.actor<RequestEvent> {
|
||||
when (it) {
|
||||
is AddRequest -> {
|
||||
val awaitTime = (requestsInWork.pow(powValue) * powK).toLong()
|
||||
requestsInWork++
|
||||
|
||||
init {
|
||||
scope.launch {
|
||||
var requestsInWork: Double = 0.0
|
||||
for (event in eventsChannel) {
|
||||
when (event) {
|
||||
is AddRequest -> {
|
||||
val awaitTime = (((requestsInWork.pow(powValue) * powK) * 1000L).toLong())
|
||||
requestsInWork++
|
||||
|
||||
event.continuation.resume(
|
||||
if (awaitTime in awaitTimeRange) {
|
||||
awaitTime
|
||||
} else {
|
||||
if (awaitTime < minAwaitTime) {
|
||||
minAwaitTime
|
||||
} else {
|
||||
maxAwaitTime
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
is CompleteRequest -> requestsInWork--
|
||||
it.continuation.resume(
|
||||
when {
|
||||
awaitTime in awaitTimeRange -> awaitTime
|
||||
awaitTime < awaitTimeRange.first -> awaitTimeRange.first
|
||||
else -> awaitTimeRange.last
|
||||
}
|
||||
)
|
||||
}
|
||||
is CompleteRequest -> requestsInWork--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T> limit(
|
||||
block: suspend () -> T
|
||||
private suspend inline fun <T> withDelay(
|
||||
crossinline block: suspend () -> T
|
||||
): T {
|
||||
val delayMillis = suspendCoroutine<Long> {
|
||||
scope.launch { eventsChannel.send(AddRequest(it)) }
|
||||
}
|
||||
delay(delayMillis)
|
||||
return try {
|
||||
block()
|
||||
safely { block() }
|
||||
} finally {
|
||||
eventsChannel.send(CompleteRequest)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T> limit(
|
||||
block: suspend () -> T
|
||||
): T {
|
||||
return withDelay(block)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.inmo.tgbotapi.requests.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaFileAttachmentName
|
||||
import dev.inmo.tgbotapi.utils.StorageFile
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.*
|
||||
@@ -12,6 +11,14 @@ sealed class InputFile {
|
||||
abstract val fileId: String
|
||||
}
|
||||
|
||||
internal inline val InputFile.attachFileId
|
||||
get() = "attach://$fileId"
|
||||
internal inline val InputFile.fileIdToSend
|
||||
get() = when (this) {
|
||||
is FileId -> fileId
|
||||
is MultipartFile -> attachFileId
|
||||
}
|
||||
|
||||
// TODO:: add checks for file url/file id regex
|
||||
/**
|
||||
* Contains file id or file url
|
||||
@@ -30,12 +37,6 @@ internal object InputFileSerializer : KSerializer<InputFile> {
|
||||
override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString())
|
||||
}
|
||||
|
||||
internal val InputFile.asMediaData: String
|
||||
get() = when (this) {
|
||||
is FileId -> fileId
|
||||
is MultipartFile -> fileId.toInputMediaFileAttachmentName()
|
||||
}
|
||||
|
||||
// TODO:: add checks for files size
|
||||
/**
|
||||
* Contains info about file for sending
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -4,13 +4,13 @@ import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMemberSerializerWithoutDeserialization
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMemberSerializer
|
||||
import dev.inmo.tgbotapi.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
|
||||
private val chatMembersListSerializer = ListSerializer(
|
||||
AdministratorChatMemberSerializerWithoutDeserialization
|
||||
AdministratorChatMemberSerializer
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.requests.chat.members
|
||||
import dev.inmo.tgbotapi.requests.chat.abstracts.ChatMemberRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMemberDeserializationStrategy
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMemberSerializer
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
@@ -15,7 +15,7 @@ data class GetChatMember(
|
||||
) : ChatMemberRequest<ChatMember> {
|
||||
override fun method(): String = "getChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<ChatMember>
|
||||
get() = ChatMemberDeserializationStrategy
|
||||
get() = ChatMemberSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ data class PromoteChatMember(
|
||||
override val userId: UserId,
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null,
|
||||
@SerialName(isAnonymousField)
|
||||
private val isAnonymous: Boolean? = null,
|
||||
@SerialName(canChangeInfoField)
|
||||
private val canChangeInfo: Boolean? = null,
|
||||
@SerialName(canPostMessagesField)
|
||||
|
||||
@@ -10,7 +10,9 @@ data class UnbanChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId
|
||||
override val userId: UserId,
|
||||
@SerialName(onlyIfBannedField)
|
||||
val onlyIfBanned: Boolean? = null
|
||||
) : ChatMemberRequest<Boolean> {
|
||||
override fun method(): String = "unbanChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
|
||||
@@ -6,6 +6,11 @@ import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
/**
|
||||
* Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot
|
||||
* must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a
|
||||
* supergroup or 'can_edit_messages' admin right in a channel.
|
||||
*/
|
||||
@Serializable
|
||||
data class PinChatMessage (
|
||||
@SerialName(chatIdField)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package dev.inmo.tgbotapi.requests.chat.modify
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
/**
|
||||
* Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an
|
||||
* administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or
|
||||
* 'can_edit_messages' admin right in a channel.
|
||||
*
|
||||
* @see PinChatMessage
|
||||
* @see UnpinChatMessage
|
||||
*/
|
||||
@Serializable
|
||||
data class UnpinAllChatMessages(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "unpinAllChatMessages"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -2,15 +2,16 @@ package dev.inmo.tgbotapi.requests.chat.modify
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.chatIdField
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
@Serializable
|
||||
data class UnpinChatMessage(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
val messageId: MessageIdentifier? = null
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "unpinChatMessage"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
|
||||
@@ -6,9 +6,11 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import dev.inmo.tgbotapi.types.message.content.LocationContent
|
||||
import dev.inmo.tgbotapi.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
|
||||
const val editMessageLiveLocationMethod = "editMessageLiveLocation"
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageLiveLocation(
|
||||
@@ -20,12 +22,24 @@ data class EditChatMessageLiveLocation(
|
||||
override val latitude: Double,
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(horizontalAccuracyField)
|
||||
override val horizontalAccuracy: Meters? = null,
|
||||
@SerialName(headingField)
|
||||
override val heading: Degrees? = null,
|
||||
@SerialName(proximityAlertRadiusField)
|
||||
override val proximityAlertRadius: Meters? = null,
|
||||
@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<*>
|
||||
get() = serializer()
|
||||
|
||||
init {
|
||||
if (horizontalAccuracy != null && horizontalAccuracy !in horizontalAccuracyLimit) {
|
||||
throwRangeError("horizontalAccuracy", horizontalAccuracyLimit, horizontalAccuracy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.requests.edit.LiveLocation
|
||||
import dev.inmo.tgbotapi.requests.edit.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import dev.inmo.tgbotapi.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
@@ -13,10 +14,22 @@ data class EditInlineMessageLiveLocation(
|
||||
override val latitude: Double,
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(horizontalAccuracyField)
|
||||
override val horizontalAccuracy: Meters? = null,
|
||||
@SerialName(headingField)
|
||||
override val heading: Degrees? = null,
|
||||
@SerialName(proximityAlertRadiusField)
|
||||
override val proximityAlertRadius: Meters? = null,
|
||||
@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()
|
||||
|
||||
init {
|
||||
if (horizontalAccuracy != null && horizontalAccuracy !in horizontalAccuracyLimit) {
|
||||
throwRangeError("horizontalAccuracy", horizontalAccuracyLimit, horizontalAccuracy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<*>
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.inmo.tgbotapi.requests.edit.abstracts
|
||||
|
||||
interface EditLocationMessage {
|
||||
val latitude: Double
|
||||
val longitude: Double
|
||||
}
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
|
||||
interface EditLocationMessage : Locationed, HorizontallyAccured, ProximityAlertable, Headed
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.edit.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
|
||||
|
||||
interface EditTextChatMessage {
|
||||
val text: String
|
||||
val parseMode: ParseMode?
|
||||
interface EditTextChatMessage : TextedOutput {
|
||||
override val text: String
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package dev.inmo.tgbotapi.requests.edit.caption
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.edit.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.edit.media.MediaContentMessageResultDeserializer
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
@@ -12,8 +14,37 @@ import kotlinx.serialization.*
|
||||
|
||||
const val editMessageCaptionMethod = "editMessageCaption"
|
||||
|
||||
fun EditChatMessageCaption(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = EditChatMessageCaption(
|
||||
chatId,
|
||||
messageId,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
fun EditChatMessageCaption(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
entities: List<TextSource>,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = EditChatMessageCaption(
|
||||
chatId,
|
||||
messageId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageCaption(
|
||||
data class EditChatMessageCaption internal constructor(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
@@ -22,9 +53,14 @@ data class EditChatMessageCaption(
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage<MediaContent>, EditTextChatMessage, EditReplyMessage {
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageCaptionMethod
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<MediaContent>>
|
||||
|
||||
@@ -1,23 +1,56 @@
|
||||
package dev.inmo.tgbotapi.requests.edit.caption
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.edit.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun EditInlineMessageCaption(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = EditInlineMessageCaption(
|
||||
inlineMessageId,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
fun EditInlineMessageCaption(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
entities: List<TextSource>,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = EditInlineMessageCaption(
|
||||
inlineMessageId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageCaption(
|
||||
data class EditInlineMessageCaption internal constructor(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(captionField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage {
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageCaptionMethod
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package dev.inmo.tgbotapi.requests.edit.text
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.edit.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.TextContentMessageResultDeserializer
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
@@ -12,8 +14,41 @@ import kotlinx.serialization.*
|
||||
|
||||
const val editMessageTextMethod = "editMessageText"
|
||||
|
||||
fun EditChatMessageText(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
disableWebPagePreview: Boolean? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = EditChatMessageText(
|
||||
chatId,
|
||||
messageId,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
disableWebPagePreview,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
fun EditChatMessageText(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
entities: List<TextSource>,
|
||||
disableWebPagePreview: Boolean? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = EditChatMessageText(
|
||||
chatId,
|
||||
messageId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
disableWebPagePreview,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageText(
|
||||
data class EditChatMessageText internal constructor(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
@@ -22,11 +57,16 @@ data class EditChatMessageText(
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(entitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(disableWebPagePreviewField)
|
||||
override val disableWebPagePreview: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage<TextContent>, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageTextMethod
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<TextContent>>
|
||||
|
||||
@@ -1,27 +1,63 @@
|
||||
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
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun EditInlineMessageText(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
disableWebPagePreview: Boolean? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = EditInlineMessageText(
|
||||
inlineMessageId,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
disableWebPagePreview,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
fun EditInlineMessageText(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
entities: List<TextSource>,
|
||||
disableWebPagePreview: Boolean? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = EditInlineMessageText(
|
||||
inlineMessageId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
disableWebPagePreview,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageText(
|
||||
data class EditInlineMessageText internal constructor(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(entitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(disableWebPagePreviewField)
|
||||
override val disableWebPagePreview: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageTextMethod
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package dev.inmo.tgbotapi.requests.local
|
||||
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
/**
|
||||
* Use this method to close the bot instance before moving it from one local server to another. You need to delete the
|
||||
* webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will
|
||||
* return error 429 in the first 10 minutes after the bot is launched.
|
||||
*
|
||||
* @see io.ktor.client.features.ClientRequestException
|
||||
*/
|
||||
@Serializable
|
||||
object Close : SimpleRequest<Boolean> {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "close"
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.inmo.tgbotapi.requests.local
|
||||
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
/**
|
||||
* Use this method to log out from the cloud Bot API server before launching the bot locally. You **must** log out the bot
|
||||
* before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful
|
||||
* call, you will not be able to log in again using the same token for 10 minutes
|
||||
*/
|
||||
@Serializable
|
||||
object LogOut : SimpleRequest<Boolean> {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "logOut"
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package dev.inmo.tgbotapi.requests.send
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.types.MessageAction
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun CopyMessage(
|
||||
fromChatId: ChatIdentifier,
|
||||
toChatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = CopyMessage(fromChatId, toChatId, messageId, text, parseMode, null, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||
|
||||
fun CopyMessage(
|
||||
fromChatId: ChatIdentifier,
|
||||
toChatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
entities: List<TextSource>,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = CopyMessage(fromChatId, toChatId, messageId, entities.makeString(), null, entities.toRawMessageEntities(), disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||
|
||||
@Serializable
|
||||
data class CopyMessage internal constructor(
|
||||
@SerialName(fromChatIdField)
|
||||
val fromChatId: ChatIdentifier,
|
||||
@SerialName(chatIdField)
|
||||
val toChatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(captionField)
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
): SimpleRequest<MessageIdentifier>,
|
||||
ReplyingMarkupSendMessageRequest<MessageIdentifier>,
|
||||
MessageAction,
|
||||
TextedOutput {
|
||||
override val chatId: ChatIdentifier
|
||||
get() = fromChatId
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
|
||||
override fun method(): String = "copyMessage"
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<MessageIdentifier>
|
||||
get() = MessageIdSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -26,6 +26,8 @@ data class SendContact(
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendMessageRequest<ContentMessage<ContactContent>>,
|
||||
@@ -36,6 +38,7 @@ data class SendContact(
|
||||
contact: Contact,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): this(
|
||||
chatId,
|
||||
@@ -44,6 +47,7 @@ data class SendContact(
|
||||
contact.lastName,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@@ -58,11 +62,13 @@ fun Contact.toRequest(
|
||||
chatId: ChatIdentifier,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): SendContact = SendContact(
|
||||
chatId,
|
||||
this,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@@ -24,6 +24,8 @@ data class SendDice(
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : ReplyingMarkupSendMessageRequest<ContentMessage<DiceContent>>, ReplyMessageId, DisableNotification {
|
||||
|
||||
@@ -1,19 +1,79 @@
|
||||
package dev.inmo.tgbotapi.requests.send
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import dev.inmo.tgbotapi.types.message.content.LocationContent
|
||||
import dev.inmo.tgbotapi.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
|
||||
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
||||
= TelegramBotAPIMessageDeserializationStrategyClass()
|
||||
|
||||
fun SendLocation(
|
||||
chatId: ChatIdentifier,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendLocation(
|
||||
chatId,
|
||||
latitude,
|
||||
longitude,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
fun SendStaticLocation(
|
||||
chatId: ChatIdentifier,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendLocation(chatId, latitude, longitude, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||
|
||||
fun SendLiveLocation(
|
||||
chatId: ChatIdentifier,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
livePeriod: Seconds,
|
||||
horizontalAccuracy: Meters? = null,
|
||||
heading: Degrees? = null,
|
||||
proximityAlertRadius: Meters? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendLocation(
|
||||
chatId,
|
||||
latitude,
|
||||
longitude,
|
||||
livePeriod,
|
||||
horizontalAccuracy,
|
||||
heading,
|
||||
proximityAlertRadius,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SendLocation(
|
||||
data class SendLocation internal constructor(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(latitudeField)
|
||||
@@ -21,16 +81,28 @@ data class SendLocation(
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(livePeriodField)
|
||||
val livePeriod: Long? = null,
|
||||
override val livePeriod: Seconds? = null,
|
||||
@SerialName(horizontalAccuracyField)
|
||||
override val horizontalAccuracy: Meters? = null,
|
||||
@SerialName(headingField)
|
||||
override val heading: Degrees? = null,
|
||||
@SerialName(proximityAlertRadiusField)
|
||||
override val proximityAlertRadius: Meters? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendMessageRequest<ContentMessage<LocationContent>>,
|
||||
ReplyingMarkupSendMessageRequest<ContentMessage<LocationContent>>,
|
||||
PositionedSendMessageRequest<ContentMessage<LocationContent>>
|
||||
PositionedSendMessageRequest<ContentMessage<LocationContent>>,
|
||||
HorizontallyAccured,
|
||||
Livable,
|
||||
ProximityAlertable,
|
||||
Headed
|
||||
{
|
||||
override fun method(): String = "sendLocation"
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
||||
@@ -42,5 +114,8 @@ data class SendLocation(
|
||||
if (livePeriod != null && livePeriod !in livePeriodLimit) {
|
||||
error("Live period for sending location must be in $livePeriodLimit, but was $livePeriod")
|
||||
}
|
||||
if (horizontalAccuracy != null && horizontalAccuracy !in horizontalAccuracyLimit) {
|
||||
throwRangeError("horizontalAccuracy", horizontalAccuracyLimit, horizontalAccuracy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package dev.inmo.tgbotapi.requests.send
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
@@ -15,20 +17,65 @@ import kotlinx.serialization.*
|
||||
internal val TextContentMessageResultDeserializer: DeserializationStrategy<ContentMessage<TextContent>>
|
||||
= TelegramBotAPIMessageDeserializationStrategyClass()
|
||||
|
||||
fun SendTextMessage(
|
||||
chatId: ChatIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
disableWebPagePreview: Boolean? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendTextMessage(
|
||||
chatId,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
disableWebPagePreview,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
fun SendTextMessage(
|
||||
chatId: ChatIdentifier,
|
||||
entities: List<TextSource>,
|
||||
disableWebPagePreview: Boolean? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendTextMessage(
|
||||
chatId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
disableWebPagePreview,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SendTextMessage(
|
||||
data class SendTextMessage internal constructor(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(entitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(disableWebPagePreviewField)
|
||||
override val disableWebPagePreview: Boolean? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendMessageRequest<ContentMessage<TextContent>>,
|
||||
@@ -36,6 +83,10 @@ data class SendTextMessage(
|
||||
TextableSendMessageRequest<ContentMessage<TextContent>>,
|
||||
DisableWebPagePreview
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
}
|
||||
|
||||
init {
|
||||
if (text.length !in textLength) {
|
||||
throwRangeError("Text length", textLength, text.length)
|
||||
|
||||
@@ -25,11 +25,19 @@ data class SendVenue(
|
||||
@SerialName(addressField)
|
||||
val address: String,
|
||||
@SerialName(foursquareIdField)
|
||||
val foursquareId: String? = null,
|
||||
val foursquareId: FoursquareId? = null,
|
||||
@SerialName(foursquareTypeField)
|
||||
val foursquareType: FoursquareType? = null,
|
||||
@SerialName(googlePlaceIdField)
|
||||
val googlePlaceId: GooglePlaceId? = null,
|
||||
@SerialName(googlePlaceTypeField)
|
||||
val googlePlaceType: GooglePlaceType? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendMessageRequest<ContentMessage<VenueContent>>,
|
||||
@@ -42,17 +50,22 @@ data class SendVenue(
|
||||
venue: Venue,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): this(
|
||||
chatId,
|
||||
venue.location.latitude,
|
||||
venue.location.longitude,
|
||||
venue.title,
|
||||
venue.address,
|
||||
venue.foursquareId,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
chatId = chatId,
|
||||
latitude = venue.location.latitude,
|
||||
longitude = venue.location.longitude,
|
||||
title = venue.title,
|
||||
address = venue.address,
|
||||
foursquareId = venue.foursquareId,
|
||||
foursquareType = venue.foursquareType,
|
||||
googlePlaceId = venue.googlePlaceId,
|
||||
googlePlaceType = venue.googlePlaceType,
|
||||
disableNotification = disableNotification,
|
||||
replyToMessageId = replyToMessageId,
|
||||
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||
replyMarkup = replyMarkup
|
||||
)
|
||||
|
||||
override fun method(): String = "sendVenue"
|
||||
@@ -66,11 +79,13 @@ fun Venue.toRequest(
|
||||
chatId: ChatIdentifier,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): SendVenue = SendVenue(
|
||||
chatId,
|
||||
this,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.inmo.tgbotapi.requests.send.abstracts
|
||||
|
||||
interface PositionedSendMessageRequest<T: Any>: SendMessageRequest<T> {
|
||||
val latitude: Double
|
||||
val longitude: Double
|
||||
}
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.Locationed
|
||||
|
||||
interface PositionedSendMessageRequest<T: Any>: SendMessageRequest<T>, Locationed
|
||||
@@ -1,8 +1,5 @@
|
||||
package dev.inmo.tgbotapi.requests.send.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
|
||||
|
||||
interface TextableSendMessageRequest<T: Any>: SendMessageRequest<T> {
|
||||
val text: String?
|
||||
val parseMode: ParseMode?
|
||||
}
|
||||
interface TextableSendMessageRequest<T: Any>: SendMessageRequest<T>, TextedOutput
|
||||
|
||||
@@ -22,6 +22,8 @@ data class SendGame (
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendMessageRequest<ContentMessage<GameContent>>,
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
@@ -25,6 +27,7 @@ fun SendAnimation(
|
||||
height: Int? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<AnimationContent>> {
|
||||
val animationAsFileId = (animation as? FileId) ?.fileId
|
||||
@@ -38,11 +41,57 @@ fun SendAnimation(
|
||||
thumbAsFileId,
|
||||
caption,
|
||||
parseMode,
|
||||
null,
|
||||
duration,
|
||||
width,
|
||||
height,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
return if (animationAsFile == null && thumbAsFile == null) {
|
||||
data
|
||||
} else {
|
||||
MultipartRequestImpl(
|
||||
data,
|
||||
SendAnimationFiles(animationAsFile, thumbAsFile)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun SendAnimation(
|
||||
chatId: ChatIdentifier,
|
||||
animation: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
entities: List<TextSource>,
|
||||
duration: Long? = null,
|
||||
width: Int? = null,
|
||||
height: Int? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<AnimationContent>> {
|
||||
val animationAsFileId = (animation as? FileId) ?.fileId
|
||||
val animationAsFile = animation as? MultipartFile
|
||||
val thumbAsFileId = (thumb as? FileId) ?.fileId
|
||||
val thumbAsFile = thumb as? MultipartFile
|
||||
|
||||
val data = SendAnimationData(
|
||||
chatId,
|
||||
animationAsFileId,
|
||||
thumbAsFileId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
duration,
|
||||
width,
|
||||
height,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@@ -71,6 +120,8 @@ data class SendAnimationData internal constructor(
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(durationField)
|
||||
override val duration: Long? = null,
|
||||
@SerialName(widthField)
|
||||
@@ -81,6 +132,8 @@ data class SendAnimationData internal constructor(
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : DataRequest<ContentMessage<AnimationContent>>,
|
||||
@@ -91,6 +144,10 @@ data class SendAnimationData internal constructor(
|
||||
DuratedSendMessageRequest<ContentMessage<AnimationContent>>,
|
||||
SizedSendMessageRequest<ContentMessage<AnimationContent>>
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.Performerable
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
@@ -26,6 +27,7 @@ fun SendAudio(
|
||||
title: String? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<AudioContent>> {
|
||||
val audioAsFileId = (audio as? FileId) ?.fileId
|
||||
@@ -39,11 +41,57 @@ fun SendAudio(
|
||||
thumbAsFileId,
|
||||
caption,
|
||||
parseMode,
|
||||
null,
|
||||
duration,
|
||||
performer,
|
||||
title,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
return if (audioAsFile == null && thumbAsFile == null) {
|
||||
data
|
||||
} else {
|
||||
MultipartRequestImpl(
|
||||
data,
|
||||
SendAudioFiles(audioAsFile, thumbAsFile)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun SendAudio(
|
||||
chatId: ChatIdentifier,
|
||||
audio: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
entities: List<TextSource>,
|
||||
duration: Long? = null,
|
||||
performer: String? = null,
|
||||
title: String? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<AudioContent>> {
|
||||
val audioAsFileId = (audio as? FileId) ?.fileId
|
||||
val audioAsFile = audio as? MultipartFile
|
||||
val thumbAsFileId = (thumb as? FileId) ?.fileId
|
||||
val thumbAsFile = thumb as? MultipartFile
|
||||
|
||||
val data = SendAudioData(
|
||||
chatId,
|
||||
audioAsFileId,
|
||||
thumbAsFileId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
duration,
|
||||
performer,
|
||||
title,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@@ -72,6 +120,8 @@ data class SendAudioData internal constructor(
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(durationField)
|
||||
override val duration: Long? = null,
|
||||
@SerialName(performerField)
|
||||
@@ -82,6 +132,8 @@ data class SendAudioData internal constructor(
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : DataRequest<ContentMessage<AudioContent>>,
|
||||
@@ -93,6 +145,10 @@ data class SendAudioData internal constructor(
|
||||
DuratedSendMessageRequest<ContentMessage<AudioContent>>,
|
||||
Performerable
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
@@ -14,6 +16,15 @@ import dev.inmo.tgbotapi.utils.mapOfNotNull
|
||||
import dev.inmo.tgbotapi.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
/**
|
||||
* Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned.
|
||||
* Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
|
||||
*
|
||||
* @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile]
|
||||
*
|
||||
* @see ContentMessage
|
||||
* @see DocumentContent
|
||||
*/
|
||||
fun SendDocument(
|
||||
chatId: ChatIdentifier,
|
||||
document: InputFile,
|
||||
@@ -22,7 +33,9 @@ fun SendDocument(
|
||||
parseMode: ParseMode? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null,
|
||||
disableContentTypeDetection: Boolean? = null
|
||||
): Request<ContentMessage<DocumentContent>> {
|
||||
val documentAsFileId = (document as? FileId) ?.fileId
|
||||
val documentAsFile = document as? MultipartFile
|
||||
@@ -35,9 +48,61 @@ fun SendDocument(
|
||||
thumbAsFileId,
|
||||
caption,
|
||||
parseMode,
|
||||
null,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup,
|
||||
disableContentTypeDetection
|
||||
)
|
||||
|
||||
return if (documentAsFile == null && thumbAsFile == null) {
|
||||
data
|
||||
} else {
|
||||
MultipartRequestImpl(
|
||||
data,
|
||||
SendDocumentFiles(documentAsFile, thumbAsFile)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned.
|
||||
* Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
|
||||
*
|
||||
* @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile]
|
||||
*
|
||||
* @see ContentMessage
|
||||
* @see DocumentContent
|
||||
*/
|
||||
fun SendDocument(
|
||||
chatId: ChatIdentifier,
|
||||
document: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
entities: List<TextSource>,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null,
|
||||
disableContentTypeDetection: Boolean? = null
|
||||
): Request<ContentMessage<DocumentContent>> {
|
||||
val documentAsFileId = (document as? FileId) ?.fileId
|
||||
val documentAsFile = document as? MultipartFile
|
||||
val thumbAsFileId = (thumb as? FileId) ?.fileId
|
||||
val thumbAsFile = thumb as? MultipartFile
|
||||
|
||||
val data = SendDocumentData(
|
||||
chatId,
|
||||
documentAsFileId,
|
||||
thumbAsFileId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup,
|
||||
disableContentTypeDetection
|
||||
)
|
||||
|
||||
return if (documentAsFile == null && thumbAsFile == null) {
|
||||
@@ -53,6 +118,15 @@ fun SendDocument(
|
||||
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<DocumentContent>>
|
||||
= TelegramBotAPIMessageDeserializationStrategyClass()
|
||||
|
||||
/**
|
||||
* Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned.
|
||||
* Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
|
||||
*
|
||||
* @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile]
|
||||
*
|
||||
* @see ContentMessage
|
||||
* @see DocumentContent
|
||||
*/
|
||||
@Serializable
|
||||
data class SendDocumentData internal constructor(
|
||||
@SerialName(chatIdField)
|
||||
@@ -65,18 +139,28 @@ data class SendDocumentData internal constructor(
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
override val replyMarkup: KeyboardMarkup? = null,
|
||||
@SerialName(disableContentTypeDetectionField)
|
||||
val disableContentTypeDetection: Boolean? = null
|
||||
) : DataRequest<ContentMessage<DocumentContent>>,
|
||||
SendMessageRequest<ContentMessage<DocumentContent>>,
|
||||
ReplyingMarkupSendMessageRequest<ContentMessage<DocumentContent>>,
|
||||
TextableSendMessageRequest<ContentMessage<DocumentContent>>,
|
||||
ThumbedSendMessageRequest<ContentMessage<DocumentContent>>
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
|
||||
@@ -8,18 +8,26 @@ 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.utils.throwRangeError
|
||||
import dev.inmo.tgbotapi.utils.toJsonWithoutNulls
|
||||
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
|
||||
import kotlinx.serialization.json.buildJsonArray
|
||||
|
||||
fun SendMediaGroup(
|
||||
const val rawSendingMediaGroupsWarning = "Media groups contains restrictions related to combinations of media" +
|
||||
" types. Currently it is possible to combine photo + video OR audio OR documents"
|
||||
|
||||
@RiskFeature(rawSendingMediaGroupsWarning)
|
||||
fun <T : MediaGroupContent> SendMediaGroup(
|
||||
chatId: ChatIdentifier,
|
||||
media: List<MediaGroupMemberInputMedia>,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null
|
||||
): Request<List<MediaGroupMessage>> {
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null
|
||||
): Request<List<MediaGroupMessage<T>>> {
|
||||
if (media.size !in mediaCountInMediaGroup) {
|
||||
throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size)
|
||||
}
|
||||
@@ -39,20 +47,64 @@ fun SendMediaGroup(
|
||||
chatId,
|
||||
media,
|
||||
disableNotification,
|
||||
replyToMessageId
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply
|
||||
)
|
||||
|
||||
return if (files.isEmpty()) {
|
||||
return (if (files.isEmpty()) {
|
||||
data
|
||||
} else {
|
||||
MultipartRequestImpl(
|
||||
data,
|
||||
SendMediaGroupFiles(files)
|
||||
)
|
||||
}
|
||||
}) as Request<List<MediaGroupMessage<T>>>
|
||||
}
|
||||
|
||||
private val messagesListSerializer: KSerializer<List<MediaGroupMessage>>
|
||||
/**
|
||||
* Use this method to be sure that you are correctly sending playlist with audios
|
||||
*
|
||||
* @see InputMediaAudio
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun SendPlaylist(
|
||||
chatId: ChatIdentifier,
|
||||
media: List<AudioMediaGroupMemberInputMedia>,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null
|
||||
) = SendMediaGroup<AudioContent>(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply)
|
||||
|
||||
/**
|
||||
* Use this method to be sure that you are correctly sending documents media group
|
||||
*
|
||||
* @see InputMediaDocument
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun SendDocumentsGroup(
|
||||
chatId: ChatIdentifier,
|
||||
media: List<DocumentMediaGroupMemberInputMedia>,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null
|
||||
) = SendMediaGroup<DocumentContent>(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply)
|
||||
|
||||
/**
|
||||
* Use this method to be sure that you are correctly sending visual media group
|
||||
*
|
||||
* @see InputMediaPhoto
|
||||
* @see InputMediaVideo
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun SendVisualMediaGroup(
|
||||
chatId: ChatIdentifier,
|
||||
media: List<VisualMediaGroupMemberInputMedia>,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null
|
||||
) = SendMediaGroup<VisualMediaGroupContent>(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply)
|
||||
|
||||
private val messagesListSerializer: KSerializer<List<MediaGroupMessage<MediaGroupContent>>>
|
||||
= ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass())
|
||||
|
||||
@Serializable
|
||||
@@ -63,8 +115,10 @@ data class SendMediaGroupData internal constructor(
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null
|
||||
) : DataRequest<List<MediaGroupMessage>>, SendMessageRequest<List<MediaGroupMessage>> {
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null
|
||||
) : DataRequest<List<MediaGroupMessage<MediaGroupContent>>>, SendMessageRequest<List<MediaGroupMessage<MediaGroupContent>>> {
|
||||
@SerialName(mediaField)
|
||||
private val convertedMedia: String
|
||||
get() = buildJsonArray {
|
||||
@@ -77,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
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
@@ -20,6 +22,7 @@ fun SendPhoto(
|
||||
parseMode: ParseMode? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<PhotoContent>> {
|
||||
val data = SendPhotoData(
|
||||
@@ -27,8 +30,38 @@ fun SendPhoto(
|
||||
(photo as? FileId) ?.fileId,
|
||||
caption,
|
||||
parseMode,
|
||||
null,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
return data.photo ?.let {
|
||||
data
|
||||
} ?: MultipartRequestImpl(
|
||||
data,
|
||||
SendPhotoFiles(photo as MultipartFile)
|
||||
)
|
||||
}
|
||||
|
||||
fun SendPhoto(
|
||||
chatId: ChatIdentifier,
|
||||
photo: InputFile,
|
||||
entities: List<TextSource>,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<PhotoContent>> {
|
||||
val data = SendPhotoData(
|
||||
chatId,
|
||||
(photo as? FileId) ?.fileId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
return data.photo ?.let {
|
||||
@@ -52,10 +85,14 @@ data class SendPhotoData internal constructor(
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : DataRequest<ContentMessage<PhotoContent>>,
|
||||
@@ -63,6 +100,10 @@ data class SendPhotoData internal constructor(
|
||||
ReplyingMarkupSendMessageRequest<ContentMessage<PhotoContent>>,
|
||||
TextableSendMessageRequest<ContentMessage<PhotoContent>>
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
|
||||
@@ -17,12 +17,14 @@ fun SendSticker(
|
||||
sticker: InputFile,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<StickerContent>> = SendStickerByFileId(
|
||||
chatId,
|
||||
sticker as? FileId,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
).let {
|
||||
when (sticker) {
|
||||
@@ -44,6 +46,8 @@ data class SendStickerByFileId internal constructor(
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendMessageRequest<ContentMessage<StickerContent>>, ReplyingMarkupSendMessageRequest<ContentMessage<StickerContent>> {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
@@ -26,6 +28,7 @@ fun SendVideo(
|
||||
supportStreaming: Boolean? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<VideoContent>> {
|
||||
val videoAsFileId = (video as? FileId) ?.fileId
|
||||
@@ -39,12 +42,60 @@ fun SendVideo(
|
||||
thumbAsFileId,
|
||||
caption,
|
||||
parseMode,
|
||||
null,
|
||||
duration,
|
||||
width,
|
||||
height,
|
||||
supportStreaming,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
return if (videoAsFile == null && thumbAsFile == null) {
|
||||
data
|
||||
} else {
|
||||
MultipartRequestImpl(
|
||||
data,
|
||||
SendVideoFiles(videoAsFile, thumbAsFile)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun SendVideo(
|
||||
chatId: ChatIdentifier,
|
||||
video: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
entities: List<TextSource>,
|
||||
duration: Long? = null,
|
||||
width: Int? = null,
|
||||
height: Int? = null,
|
||||
supportStreaming: Boolean? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<VideoContent>> {
|
||||
val videoAsFileId = (video as? FileId) ?.fileId
|
||||
val videoAsFile = video as? MultipartFile
|
||||
val thumbAsFileId = (thumb as? FileId) ?.fileId
|
||||
val thumbAsFile = thumb as? MultipartFile
|
||||
|
||||
val data = SendVideoData(
|
||||
chatId,
|
||||
videoAsFileId,
|
||||
thumbAsFileId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
duration,
|
||||
width,
|
||||
height,
|
||||
supportStreaming,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@@ -73,6 +124,8 @@ data class SendVideoData internal constructor(
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(durationField)
|
||||
override val duration: Long? = null,
|
||||
@SerialName(widthField)
|
||||
@@ -85,6 +138,8 @@ data class SendVideoData internal constructor(
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : DataRequest<ContentMessage<VideoContent>>,
|
||||
@@ -95,6 +150,10 @@ data class SendVideoData internal constructor(
|
||||
DuratedSendMessageRequest<ContentMessage<VideoContent>>,
|
||||
SizedSendMessageRequest<ContentMessage<VideoContent>>
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
|
||||
@@ -4,26 +4,22 @@ import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import dev.inmo.tgbotapi.types.message.content.media.VideoNoteContent
|
||||
import dev.inmo.tgbotapi.utils.mapOfNotNull
|
||||
import dev.inmo.tgbotapi.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun SendVideoNote(
|
||||
chatId: ChatIdentifier,
|
||||
videoNote: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
caption: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
duration: Long? = null,
|
||||
size: Int? = null, // in documentation - length (size of video side)
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<VideoNoteContent>> {
|
||||
val videoNoteAsFileId = (videoNote as? FileId) ?.fileId
|
||||
@@ -35,12 +31,11 @@ fun SendVideoNote(
|
||||
chatId,
|
||||
videoNoteAsFileId,
|
||||
thumbAsFileId,
|
||||
caption,
|
||||
parseMode,
|
||||
duration,
|
||||
size,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@@ -65,10 +60,6 @@ data class SendVideoNoteData internal constructor(
|
||||
val videoNote: String? = null,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: String? = null,
|
||||
@SerialName(captionField)
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(durationField)
|
||||
override val duration: Long? = null,
|
||||
@SerialName(lengthField)
|
||||
@@ -77,12 +68,13 @@ data class SendVideoNoteData internal constructor(
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : DataRequest<ContentMessage<VideoNoteContent>>,
|
||||
SendMessageRequest<ContentMessage<VideoNoteContent>>,
|
||||
ReplyingMarkupSendMessageRequest<ContentMessage<VideoNoteContent>>,
|
||||
TextableSendMessageRequest<ContentMessage<VideoNoteContent>>,
|
||||
ThumbedSendMessageRequest<ContentMessage<VideoNoteContent>>,
|
||||
DuratedSendMessageRequest<ContentMessage<VideoNoteContent>>,
|
||||
SizedSendMessageRequest<ContentMessage<VideoNoteContent>>
|
||||
@@ -90,14 +82,6 @@ data class SendVideoNoteData internal constructor(
|
||||
override val height: Int?
|
||||
get() = width
|
||||
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
throwRangeError("Caption length", captionLength, it.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "sendVideoNote"
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<VideoNoteContent>>
|
||||
get() = commonResultDeserializer
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
@@ -22,6 +24,7 @@ fun SendVoice(
|
||||
duration: Long? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<VoiceContent>> {
|
||||
val voiceAsFileId = (voice as? FileId) ?.fileId
|
||||
@@ -32,9 +35,47 @@ fun SendVoice(
|
||||
voiceAsFileId,
|
||||
caption,
|
||||
parseMode,
|
||||
null,
|
||||
duration,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
return if (voiceAsFile == null) {
|
||||
data
|
||||
} else {
|
||||
MultipartRequestImpl(
|
||||
data,
|
||||
SendVoiceFiles(voiceAsFile)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun SendVoice(
|
||||
chatId: ChatIdentifier,
|
||||
voice: InputFile,
|
||||
entities: List<TextSource>,
|
||||
duration: Long? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): Request<ContentMessage<VoiceContent>> {
|
||||
val voiceAsFileId = (voice as? FileId) ?.fileId
|
||||
val voiceAsFile = voice as? MultipartFile
|
||||
|
||||
val data = SendVoiceData(
|
||||
chatId,
|
||||
voiceAsFileId,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
duration,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@@ -61,12 +102,16 @@ data class SendVoiceData internal constructor(
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(durationField)
|
||||
override val duration: Long? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : DataRequest<ContentMessage<VoiceContent>>,
|
||||
@@ -75,6 +120,10 @@ data class SendVoiceData internal constructor(
|
||||
TextableSendMessageRequest<ContentMessage<VoiceContent>>,
|
||||
DuratedSendMessageRequest<ContentMessage<VoiceContent>>
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
|
||||
@@ -57,6 +57,8 @@ data class SendInvoice(
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : Currencied,
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
package dev.inmo.tgbotapi.requests.send.polls
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import dev.inmo.tgbotapi.types.message.content.PollContent
|
||||
import dev.inmo.tgbotapi.types.polls.*
|
||||
import dev.inmo.tgbotapi.utils.fullListOfSubSource
|
||||
import dev.inmo.tgbotapi.utils.toMarkdownV2Captions
|
||||
import com.soywiz.klock.DateTime
|
||||
import kotlinx.serialization.*
|
||||
|
||||
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
|
||||
@@ -43,6 +41,7 @@ fun SendPoll(
|
||||
isClosed: Boolean = false,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendRegularPoll(
|
||||
chatId,
|
||||
@@ -50,6 +49,7 @@ fun SendPoll(
|
||||
options,
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||
disableNotification = disableNotification,
|
||||
replyToMessageId = replyToMessageId,
|
||||
replyMarkup = replyMarkup
|
||||
@@ -63,6 +63,7 @@ fun Poll.createRequest(
|
||||
chatId: ChatIdentifier,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = when (this) {
|
||||
is RegularPoll -> SendRegularPoll(
|
||||
@@ -75,6 +76,7 @@ fun Poll.createRequest(
|
||||
scheduledCloseInfo,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
is QuizPoll -> correctOptionId ?.let { correctOptionId ->
|
||||
@@ -85,11 +87,11 @@ fun Poll.createRequest(
|
||||
correctOptionId,
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
explanation ?.fullListOfSubSource(explanationEntities) ?.justTextSources() ?.toMarkdownV2Captions() ?.firstOrNull(),
|
||||
MarkdownV2,
|
||||
textSources,
|
||||
scheduledCloseInfo,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
} ?: SendRegularPoll(
|
||||
@@ -102,6 +104,7 @@ fun Poll.createRequest(
|
||||
scheduledCloseInfo,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
is UnknownPollType -> SendRegularPoll(
|
||||
@@ -114,6 +117,7 @@ fun Poll.createRequest(
|
||||
scheduledCloseInfo,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
}
|
||||
@@ -165,6 +169,8 @@ data class SendRegularPoll(
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendPoll() {
|
||||
@@ -186,8 +192,69 @@ data class SendRegularPoll(
|
||||
}
|
||||
}
|
||||
|
||||
fun SendQuizPoll(
|
||||
chatId: ChatIdentifier,
|
||||
question: String,
|
||||
options: List<String>,
|
||||
correctOptionId: Int,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
explanation: String? = null,
|
||||
parseMode: ParseMode? = 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,
|
||||
null,
|
||||
closeInfo,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
fun SendQuizPoll(
|
||||
chatId: ChatIdentifier,
|
||||
question: String,
|
||||
options: List<String>,
|
||||
correctOptionId: Int,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
entities: List<TextSource>,
|
||||
closeInfo: ScheduledCloseInfo? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendQuizPoll(
|
||||
chatId,
|
||||
question,
|
||||
options,
|
||||
correctOptionId,
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
closeInfo,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SendQuizPoll(
|
||||
data class SendQuizPoll internal constructor(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(questionField)
|
||||
@@ -204,18 +271,25 @@ data class SendQuizPoll(
|
||||
override val explanation: String? = null,
|
||||
@SerialName(explanationParseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(explanationEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@Transient
|
||||
override val closeInfo: ScheduledCloseInfo? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(allowSendingWithoutReplyField)
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendPoll(), ExplainedOutput {
|
||||
override val type: String = quizPollType
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds?
|
||||
|
||||
@@ -13,66 +13,123 @@ private fun correctWebhookUrl(sourceUrl: String) = if (sourceUrl.contains("://")
|
||||
"https://$sourceUrl"
|
||||
}
|
||||
|
||||
fun SetWebhook(
|
||||
sealed class SetWebhookRequest : Request<Boolean>
|
||||
class MultipartSetWebhookRequest(
|
||||
url: String,
|
||||
certificate: MultipartFile,
|
||||
ipAddress: String? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
allowedUpdates: List<String>? = null
|
||||
): MultipartRequestImpl<SetWebhook, Map<String, MultipartFile>, Boolean> = MultipartRequestImpl(
|
||||
allowedUpdates: List<String>? = null,
|
||||
dropPendingUpdates: Boolean? = null
|
||||
) : SetWebhookRequest(), MultipartRequest<Boolean> by MultipartRequestImpl(
|
||||
SetWebhook(
|
||||
correctWebhookUrl(url),
|
||||
null,
|
||||
null as String?,
|
||||
ipAddress,
|
||||
maxAllowedConnections,
|
||||
allowedUpdates
|
||||
allowedUpdates,
|
||||
dropPendingUpdates
|
||||
),
|
||||
mapOf(certificateField to certificate)
|
||||
)
|
||||
|
||||
fun SetWebhook(
|
||||
url: String,
|
||||
certificate: FileId,
|
||||
certificate: MultipartFile,
|
||||
ipAddress: String? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
allowedUpdates: List<String>? = null
|
||||
allowedUpdates: List<String>? = null,
|
||||
dropPendingUpdates: Boolean? = null
|
||||
): MultipartSetWebhookRequest = MultipartSetWebhookRequest(
|
||||
correctWebhookUrl(url),
|
||||
certificate,
|
||||
ipAddress,
|
||||
maxAllowedConnections,
|
||||
allowedUpdates,
|
||||
dropPendingUpdates
|
||||
)
|
||||
|
||||
fun SetWebhook(
|
||||
url: String,
|
||||
certificate: FileId,
|
||||
ipAddress: String? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
allowedUpdates: List<String>? = null,
|
||||
dropPendingUpdates: Boolean? = null
|
||||
): SetWebhook = SetWebhook(
|
||||
correctWebhookUrl(url),
|
||||
certificate.fileId,
|
||||
ipAddress,
|
||||
maxAllowedConnections,
|
||||
allowedUpdates
|
||||
allowedUpdates,
|
||||
dropPendingUpdates
|
||||
)
|
||||
|
||||
/**
|
||||
* Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update
|
||||
* for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update.
|
||||
*
|
||||
* If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url],
|
||||
* e.g. https://www.example.com/<token>. Since nobody else knows your bot's token, you can be pretty sure it's us.
|
||||
*/
|
||||
@Suppress("USELESS_CAST")
|
||||
fun SetWebhook(
|
||||
url: String,
|
||||
certificate: InputFile,
|
||||
ipAddress: String? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
allowedUpdates: List<String>? = null
|
||||
): Request<Boolean> = when (certificate) {
|
||||
is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, maxAllowedConnections, allowedUpdates)
|
||||
is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, maxAllowedConnections, allowedUpdates)
|
||||
allowedUpdates: List<String>? = null,
|
||||
dropPendingUpdates: Boolean? = null
|
||||
) = when (certificate) {
|
||||
is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates)
|
||||
is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates)
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update
|
||||
* for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update.
|
||||
*
|
||||
* If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url],
|
||||
* e.g. https://www.example.com/<token>. Since nobody else knows your bot's token, you can be pretty sure it's us.
|
||||
*/
|
||||
@Suppress("USELESS_CAST")
|
||||
fun SetWebhook(
|
||||
url: String,
|
||||
ipAddress: String? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
allowedUpdates: List<String>? = null
|
||||
allowedUpdates: List<String>? = null,
|
||||
dropPendingUpdates: Boolean? = null
|
||||
) = SetWebhook(
|
||||
correctWebhookUrl(url),
|
||||
null,
|
||||
ipAddress,
|
||||
maxAllowedConnections,
|
||||
allowedUpdates
|
||||
allowedUpdates,
|
||||
dropPendingUpdates
|
||||
)
|
||||
|
||||
/**
|
||||
* Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update
|
||||
* for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update.
|
||||
*
|
||||
* If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url],
|
||||
* e.g. https://www.example.com/<token>. Since nobody else knows your bot's token, you can be pretty sure it's us.
|
||||
*/
|
||||
@Serializable
|
||||
data class SetWebhook internal constructor(
|
||||
@SerialName(urlField)
|
||||
val url: String,
|
||||
@SerialName(certificateField)
|
||||
val certificateFile: String? = null,
|
||||
@SerialName(ipAddressField)
|
||||
val ipAddress: String? = null,
|
||||
@SerialName(maxAllowedConnectionsField)
|
||||
val maxAllowedConnections: Int? = null,
|
||||
@SerialName(allowedUpdatesField)
|
||||
val allowedUpdates: List<String>? = null
|
||||
) : DataRequest<Boolean> {
|
||||
val allowedUpdates: List<String>? = null,
|
||||
@SerialName(dropPendingUpdatesField)
|
||||
val dropPendingUpdates: Boolean? = null
|
||||
) : SetWebhookRequest(), DataRequest<Boolean> {
|
||||
override fun method(): String = "setWebhook"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
|
||||
@@ -3,7 +3,8 @@ package dev.inmo.tgbotapi.types
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.*
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.longOrNull
|
||||
|
||||
@Serializable(ChatIdentifierSerializer::class)
|
||||
sealed class ChatIdentifier
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package dev.inmo.tgbotapi.types
|
||||
|
||||
import dev.inmo.tgbotapi.types.location.StaticLocation
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Represents a location to which a chat is connected.
|
||||
*
|
||||
* @see dev.inmo.tgbotapi.requests.chat.get.GetChat
|
||||
* @see dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedSupergroupChat
|
||||
*/
|
||||
@Serializable
|
||||
data class ChatLocation(
|
||||
@SerialName(locationField)
|
||||
val location: StaticLocation,
|
||||
@SerialName(addressField)
|
||||
val address: String
|
||||
)
|
||||
@@ -1,18 +1,37 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class AdministratorChatMemberImpl(
|
||||
@SerialName(userField)
|
||||
override val user: User,
|
||||
override val canBeEdited: Boolean,
|
||||
override val canChangeInfo: Boolean,
|
||||
override val canPostMessages: Boolean,
|
||||
override val canEditMessages: Boolean,
|
||||
override val canRemoveMessages: Boolean,
|
||||
override val canInviteUsers: Boolean,
|
||||
override val canRestrictMembers: Boolean,
|
||||
override val canPinMessages: Boolean,
|
||||
override val canPromoteMembers: Boolean,
|
||||
override val customTitle: String?
|
||||
) : AdministratorChatMember
|
||||
@SerialName(canBeEditedField)
|
||||
override val canBeEdited: Boolean = false,
|
||||
@SerialName(canChangeInfoField)
|
||||
override val canChangeInfo: Boolean = false,
|
||||
@SerialName(canPostMessagesField)
|
||||
override val canPostMessages: Boolean = false,
|
||||
@SerialName(canEditMessagesField)
|
||||
override val canEditMessages: Boolean = false,
|
||||
@SerialName(canDeleteMessagesField)
|
||||
override val canRemoveMessages: Boolean = false,
|
||||
@SerialName(canInviteUsersField)
|
||||
override val canInviteUsers: Boolean = false,
|
||||
@SerialName(canRestrictMembersField)
|
||||
override val canRestrictMembers: Boolean = false,
|
||||
@SerialName(canPinMessagesField)
|
||||
override val canPinMessages: Boolean = false,
|
||||
@SerialName(canPromoteMembersField)
|
||||
override val canPromoteMembers: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
@SerialName(customTitleField)
|
||||
override val customTitle: String? = null
|
||||
) : AdministratorChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "administrator"
|
||||
}
|
||||
|
||||
@@ -1,19 +1,36 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class CreatorChatMember(
|
||||
override val user: User,
|
||||
override val customTitle: String?
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
@SerialName(customTitleField)
|
||||
override val customTitle: String? = null
|
||||
) : AdministratorChatMember {
|
||||
@Transient
|
||||
override val canBeEdited: Boolean = true
|
||||
@Transient
|
||||
override val canChangeInfo: Boolean = true
|
||||
@Transient
|
||||
override val canPostMessages: Boolean = true
|
||||
@Transient
|
||||
override val canEditMessages: Boolean = true
|
||||
@Transient
|
||||
override val canRemoveMessages: Boolean = true
|
||||
@Transient
|
||||
override val canInviteUsers: Boolean = true
|
||||
@Transient
|
||||
override val canRestrictMembers: Boolean = true
|
||||
@Transient
|
||||
override val canPinMessages: Boolean = true
|
||||
@Transient
|
||||
override val canPromoteMembers: Boolean = true
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "creator"
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.BannedChatMember
|
||||
import dev.inmo.tgbotapi.types.TelegramDate
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class KickedChatMember(
|
||||
@SerialName(userField)
|
||||
override val user: User,
|
||||
override val untilDate: TelegramDate?
|
||||
) : BannedChatMember
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null
|
||||
) : BannedChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "kicked"
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import kotlinx.serialization.*
|
||||
|
||||
data class LeftChatMember(override val user: User) :
|
||||
ChatMember
|
||||
@Serializable
|
||||
data class LeftChatMember(@SerialName(userField) override val user: User) : ChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "left"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import kotlinx.serialization.*
|
||||
|
||||
data class MemberChatMember(override val user: User) :
|
||||
ChatMember
|
||||
@Serializable
|
||||
data class MemberChatMember(@SerialName(userField) override val user: User) : ChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "member"
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
internal data class RawChatMember(
|
||||
val user: User,
|
||||
private val status: String,
|
||||
private val until_date: TelegramDate? = null,
|
||||
@SerialName(canBeEditedField)
|
||||
private val canBeEdited: Boolean = false,
|
||||
@SerialName(canChangeInfoField)
|
||||
private val canChangeInfo: Boolean = false,
|
||||
@SerialName(canPostMessagesField)
|
||||
private val canPostMessages: Boolean = false,
|
||||
@SerialName(canEditMessagesField)
|
||||
private val canEditMessages: Boolean = false,
|
||||
@SerialName(canDeleteMessagesField)
|
||||
private val canDeleteMessages: Boolean = false,
|
||||
@SerialName(canInviteUsersField)
|
||||
private val canInviteUsers: Boolean = false,
|
||||
@SerialName(canRestrictMembersField)
|
||||
private val canRestrictMembers: Boolean = false,
|
||||
@SerialName(canPinMessagesField)
|
||||
private val canPinMessages: Boolean = false,
|
||||
@SerialName(canPromoteMembersField)
|
||||
private val canPromoteMembers: Boolean = false,
|
||||
@SerialName(isMemberField)
|
||||
private val isMember: Boolean = false,
|
||||
@SerialName(canSendMessagesField)
|
||||
private val canSendMessages: Boolean = false,
|
||||
@SerialName(canSendMediaMessagesField)
|
||||
private val canSendMediaMessages: Boolean = false,
|
||||
@SerialName(canSendPollsField)
|
||||
private val canSendPolls: Boolean = false,
|
||||
@SerialName(canSendOtherMessagesField)
|
||||
private val canSendOtherMessages: Boolean = false,
|
||||
@SerialName(canAddWebPagePreviewsField)
|
||||
private val canAddWebPagePreviews: Boolean = false,
|
||||
@SerialName(customTitleField)
|
||||
private val customTitle: String? = null
|
||||
) {
|
||||
val asChatMember: ChatMember by lazy {
|
||||
when (status) {
|
||||
"creator" -> CreatorChatMember(user, customTitle)
|
||||
"administrator" -> AdministratorChatMemberImpl(
|
||||
user,
|
||||
canBeEdited,
|
||||
canChangeInfo,
|
||||
canPostMessages,
|
||||
canEditMessages,
|
||||
canDeleteMessages,
|
||||
canInviteUsers,
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers,
|
||||
customTitle
|
||||
)
|
||||
"member" -> MemberChatMember(user)
|
||||
"restricted" -> RestrictedChatMember(
|
||||
user,
|
||||
until_date,
|
||||
isMember,
|
||||
canSendMessages,
|
||||
canSendMediaMessages,
|
||||
canSendPolls,
|
||||
canSendOtherMessages,
|
||||
canAddWebPagePreviews,
|
||||
canChangeInfo,
|
||||
canInviteUsers,
|
||||
canPinMessages
|
||||
)
|
||||
"left" -> LeftChatMember(user)
|
||||
"kicked" -> KickedChatMember(
|
||||
user,
|
||||
until_date
|
||||
)
|
||||
else -> throw IllegalStateException("Can't understand type of user: $status")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,36 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.BannedChatMember
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.SpecialRightsChatMember
|
||||
import dev.inmo.tgbotapi.types.TelegramDate
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class RestrictedChatMember(
|
||||
@SerialName(userField)
|
||||
override val user: User,
|
||||
override val untilDate: TelegramDate?,
|
||||
val isMember: Boolean,
|
||||
val canSendMessages: Boolean,
|
||||
val canSendMediaMessages: Boolean,
|
||||
val canSendPolls: Boolean,
|
||||
val canSendOtherMessages: Boolean,
|
||||
val canAddWebpagePreviews: Boolean,
|
||||
override val canChangeInfo: Boolean,
|
||||
override val canInviteUsers: Boolean,
|
||||
override val canPinMessages: Boolean
|
||||
) : BannedChatMember, SpecialRightsChatMember
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null,
|
||||
@SerialName(isMemberField)
|
||||
val isMember: Boolean = false,
|
||||
@SerialName(canSendMessagesField)
|
||||
val canSendMessages: Boolean = false,
|
||||
@SerialName(canSendMediaMessagesField)
|
||||
val canSendMediaMessages: Boolean = false,
|
||||
@SerialName(canSendPollsField)
|
||||
val canSendPolls: Boolean = false,
|
||||
@SerialName(canSendOtherMessagesField)
|
||||
val canSendOtherMessages: Boolean = false,
|
||||
@SerialName(canAddWebPagePreviewsField)
|
||||
val canAddWebpagePreviews: Boolean = false,
|
||||
@SerialName(canChangeInfoField)
|
||||
override val canChangeInfo: Boolean = false,
|
||||
@SerialName(canInviteUsersField)
|
||||
override val canInviteUsers: Boolean = false,
|
||||
@SerialName(canPinMessagesField)
|
||||
override val canPinMessages: Boolean = false
|
||||
) : BannedChatMember, SpecialRightsChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "restricted"
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable(AdministratorChatMemberSerializer::class)
|
||||
interface AdministratorChatMember : SpecialRightsChatMember {
|
||||
val canBeEdited: Boolean
|
||||
val canPostMessages: Boolean
|
||||
@@ -7,5 +13,14 @@ interface AdministratorChatMember : SpecialRightsChatMember {
|
||||
val canRemoveMessages: Boolean
|
||||
val canRestrictMembers: Boolean
|
||||
val canPromoteMembers: Boolean
|
||||
val isAnonymous: Boolean
|
||||
val customTitle: String?
|
||||
}
|
||||
}
|
||||
|
||||
@Serializer(AdministratorChatMember::class)
|
||||
internal object AdministratorChatMemberSerializer : KSerializer<AdministratorChatMember> {
|
||||
override val descriptor: SerialDescriptor = ChatMemberSerializer.descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): AdministratorChatMember = ChatMemberSerializer.deserialize(decoder) as AdministratorChatMember
|
||||
override fun serialize(encoder: Encoder, value: AdministratorChatMember) = ChatMemberSerializer.serialize(encoder, value)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.types.UntilDate
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
interface BannedChatMember : ChatMember, UntilDate
|
||||
@@ -1,26 +1,46 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatMember.RawChatMember
|
||||
import dev.inmo.tgbotapi.types.ChatMember.*
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import dev.inmo.tgbotapi.types.statusField
|
||||
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.JsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
interface ChatMember {
|
||||
val user: User
|
||||
}
|
||||
|
||||
internal object AdministratorChatMemberSerializerWithoutDeserialization : KSerializer<AdministratorChatMember> {
|
||||
override val descriptor: SerialDescriptor = ChatMemberDeserializationStrategy.descriptor
|
||||
@Serializer(ChatMember::class)
|
||||
internal object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||
override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): AdministratorChatMember
|
||||
= ChatMemberDeserializationStrategy.deserialize(decoder) as AdministratorChatMember
|
||||
override fun serialize(encoder: Encoder, value: AdministratorChatMember) = throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
internal object ChatMemberDeserializationStrategy : DeserializationStrategy<ChatMember> {
|
||||
override val descriptor: SerialDescriptor = RawChatMember.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): ChatMember = RawChatMember.serializer().deserialize(decoder).asChatMember
|
||||
override fun deserialize(decoder: Decoder): ChatMember {
|
||||
val json = JsonObject.serializer().deserialize(decoder)
|
||||
return when (json[statusField] ?.jsonPrimitive ?.content ?: error("Status field of chat member must be specified, but incoming json contains next: $json")) {
|
||||
"creator" -> nonstrictJsonFormat.decodeFromJsonElement(CreatorChatMember.serializer(), json)
|
||||
"administrator" -> nonstrictJsonFormat.decodeFromJsonElement(AdministratorChatMemberImpl.serializer(), json)
|
||||
"member" -> nonstrictJsonFormat.decodeFromJsonElement(MemberChatMember.serializer(), json)
|
||||
"restricted" -> nonstrictJsonFormat.decodeFromJsonElement(RestrictedChatMember.serializer(), json)
|
||||
"left" -> nonstrictJsonFormat.decodeFromJsonElement(LeftChatMember.serializer(), json)
|
||||
"kicked" -> nonstrictJsonFormat.decodeFromJsonElement(KickedChatMember.serializer(), json)
|
||||
else -> error("Unknown type of chat member in json: $json")
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ChatMember) {
|
||||
when (value) {
|
||||
is CreatorChatMember -> CreatorChatMember.serializer()
|
||||
is AdministratorChatMemberImpl -> AdministratorChatMemberImpl.serializer()
|
||||
is MemberChatMember -> MemberChatMember.serializer()
|
||||
is RestrictedChatMember -> RestrictedChatMember.serializer()
|
||||
is LeftChatMember -> LeftChatMember.serializer()
|
||||
is KickedChatMember -> KickedChatMember.serializer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
interface SpecialRightsChatMember : ChatMember {
|
||||
val canChangeInfo: Boolean
|
||||
val canInviteUsers: Boolean
|
||||
|
||||
@@ -24,10 +24,19 @@ typealias FileUniqueId = String
|
||||
typealias DiceResult = Int
|
||||
typealias FoursquareId = String
|
||||
typealias FoursquareType = String
|
||||
typealias GooglePlaceId = String
|
||||
typealias GooglePlaceType = String
|
||||
|
||||
typealias Seconds = Int
|
||||
typealias MilliSeconds = Long
|
||||
typealias LongSeconds = Long
|
||||
|
||||
typealias Meters = Float
|
||||
typealias Degrees = Int
|
||||
|
||||
val degreesLimit = 1 .. 360
|
||||
val horizontalAccuracyLimit = 0F .. 1500F
|
||||
|
||||
val getUpdatesLimit = 1 .. 100
|
||||
val callbackQueryAnswerLength = 0 until 200
|
||||
val captionLength = 0 .. 1024
|
||||
@@ -43,7 +52,7 @@ val invoiceDescriptionLimit = 1 until 256
|
||||
val invoicePayloadBytesLimit = 1 until 128
|
||||
|
||||
val pollOptionTextLength = 1 .. 100
|
||||
val pollQuestionTextLength = 1 until 256
|
||||
val pollQuestionTextLength = 1 .. 300
|
||||
val pollOptionsLimit = 2 .. 10
|
||||
|
||||
val livePeriodLimit = 60 .. 86400
|
||||
@@ -52,7 +61,9 @@ val inlineQueryAnswerResultsLimit = 0 .. 50
|
||||
|
||||
val customTitleLength = 0 .. 16
|
||||
|
||||
val diceResultLimit = 1 .. 6
|
||||
val dartsCubeAndBowlingDiceResultLimit = 1 .. 6
|
||||
val basketballAndFootballDiceResultLimit = 1 .. 5
|
||||
val slotMachineDiceResultLimit = 1 .. 64
|
||||
|
||||
val botCommandLengthLimit = 1 .. 32
|
||||
val botCommandLimit = botCommandLengthLimit
|
||||
@@ -81,9 +92,12 @@ const val fromChatIdField = "from_chat_id"
|
||||
const val disableWebPagePreviewField = "disable_web_page_preview"
|
||||
const val disableNotificationField = "disable_notification"
|
||||
const val replyToMessageIdField = "reply_to_message_id"
|
||||
const val allowSendingWithoutReplyField = "allow_sending_without_reply"
|
||||
const val replyMarkupField = "reply_markup"
|
||||
const val disableContentTypeDetectionField = "disable_content_type_detection"
|
||||
const val supportStreamingField = "support_streaming"
|
||||
const val livePeriodField = "live_period"
|
||||
const val proximityAlertRadiusField = "proximity_alert_radius"
|
||||
const val isBotField = "is_bot"
|
||||
const val firstNameField = "first_name"
|
||||
const val lastNameField = "last_name"
|
||||
@@ -92,12 +106,14 @@ const val canJoinGroupsField = "can_join_groups"
|
||||
const val canReadAllGroupMessagesField = "can_read_all_group_messages"
|
||||
const val supportInlineQueriesField = "supports_inline_queries"
|
||||
const val textEntitiesField = "text_entities"
|
||||
const val entitiesField = "entities"
|
||||
const val stickerSetNameField = "set_name"
|
||||
const val stickerSetNameFullField = "sticker_set_name"
|
||||
const val slowModeDelayField = "slow_mode_delay"
|
||||
const val maskPositionField = "mask_position"
|
||||
const val phoneNumberField = "phone_number"
|
||||
const val userIdField = "user_id"
|
||||
const val onlyIfBannedField = "only_if_banned"
|
||||
const val containsMasksField = "contains_masks"
|
||||
const val resultIdField = "result_id"
|
||||
const val inlineMessageIdField = "inline_message_id"
|
||||
@@ -107,9 +123,11 @@ 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"
|
||||
const val googlePlaceTypeField = "google_place_type"
|
||||
const val untilDateField = "until_date"
|
||||
const val errorMessageField = "error_message"
|
||||
const val messageTextField = "message_text"
|
||||
@@ -119,6 +137,7 @@ const val switchPmTextField = "switch_pm_text"
|
||||
const val switchPmParameterField = "switch_pm_parameter"
|
||||
const val maxAllowedConnectionsField = "max_connections"
|
||||
const val allowedUpdatesField = "allowed_updates"
|
||||
const val dropPendingUpdatesField = "drop_pending_updates"
|
||||
const val hasCustomCertificateField = "has_custom_certificate"
|
||||
const val pendingUpdateCountField = "pending_update_count"
|
||||
const val lastErrorDateField = "last_error_date"
|
||||
@@ -129,6 +148,7 @@ const val totalVoterCountField = "total_voter_count"
|
||||
const val correctOptionIdField = "correct_option_id"
|
||||
const val allowsMultipleAnswersField = "allows_multiple_answers"
|
||||
const val isAnonymousField = "is_anonymous"
|
||||
const val captionEntitiesField = "caption_entities"
|
||||
const val loginUrlField = "login_url"
|
||||
const val forwardTextField = "forward_text"
|
||||
const val botUsernameField = "bot_username"
|
||||
@@ -139,6 +159,9 @@ const val inviteLinkField = "invite_link"
|
||||
const val pinnedMessageField = "pinned_message"
|
||||
const val customTitleField = "custom_title"
|
||||
const val optionIdsField = "option_ids"
|
||||
const val ipAddressField = "ip_address"
|
||||
const val linkedChatIdField = "linked_chat_id"
|
||||
const val horizontalAccuracyField = "horizontal_accuracy"
|
||||
|
||||
const val requestContactField = "request_contact"
|
||||
const val requestLocationField = "request_location"
|
||||
@@ -206,6 +229,7 @@ const val canSendPollsField = "can_send_polls"
|
||||
const val canAddWebPagePreviewsField = "can_add_web_page_previews"
|
||||
const val canSetStickerSetField = "can_set_sticker_set"
|
||||
|
||||
const val statusField = "status"
|
||||
const val canBeEditedField = "can_be_edited"
|
||||
const val canChangeInfoField = "can_change_info"
|
||||
const val canPostMessagesField = "can_post_messages"
|
||||
@@ -236,11 +260,13 @@ const val heightField = "height"
|
||||
const val lengthField = "length"
|
||||
const val latitudeField = "latitude"
|
||||
const val longitudeField = "longitude"
|
||||
const val headingField = "heading"
|
||||
const val fromField = "from"
|
||||
const val userField = "user"
|
||||
const val dateField = "date"
|
||||
const val chatField = "chat"
|
||||
const val usernameField = "username"
|
||||
const val bioField = "bio"
|
||||
const val nameField = "name"
|
||||
const val emailField = "email"
|
||||
const val locationField = "location"
|
||||
@@ -331,3 +357,39 @@ const val forceField = "force"
|
||||
|
||||
const val regularPollType = "regular"
|
||||
const val quizPollType = "quiz"
|
||||
|
||||
const val dataField = "data"
|
||||
const val credentialsField = "credentials"
|
||||
const val hashField = "hash"
|
||||
const val translationField = "translation"
|
||||
const val 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"
|
||||
|
||||
@@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult
|
||||
import dev.inmo.tgbotapi.types.location.StaticLocation
|
||||
|
||||
data class LocationChosenInlineResult(
|
||||
override val resultId: InlineQueryIdentifier,
|
||||
override val user: User,
|
||||
val location: Location,
|
||||
val location: StaticLocation,
|
||||
override val inlineMessageId: InlineMessageIdentifier?,
|
||||
override val query: String
|
||||
) : ChosenInlineResult
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult
|
||||
import dev.inmo.tgbotapi.types.location.StaticLocation
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@@ -14,7 +15,7 @@ internal data class RawChosenInlineResult(
|
||||
@SerialName(queryField)
|
||||
val query: String,
|
||||
@SerialName(locationField)
|
||||
val location: Location? = null,
|
||||
val location: StaticLocation? = null,
|
||||
@SerialName(inlineMessageIdField)
|
||||
val inlineMessageId: InlineMessageIdentifier? = null
|
||||
) {
|
||||
|
||||
@@ -1,30 +1,54 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudioCached
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.inlineQueryResultAudioType
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
fun InlineQueryResultAudioCachedImpl(
|
||||
id: InlineQueryIdentifier,
|
||||
fileId: FileId,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null,
|
||||
inputMessageContent: InputMessageContent? = null
|
||||
) = InlineQueryResultAudioCachedImpl(id, fileId, text, parseMode, null, replyMarkup, inputMessageContent)
|
||||
|
||||
fun InlineQueryResultAudioCachedImpl(
|
||||
id: InlineQueryIdentifier,
|
||||
fileId: FileId,
|
||||
entities: List<TextSource>,
|
||||
replyMarkup: InlineKeyboardMarkup? = null,
|
||||
inputMessageContent: InputMessageContent? = null
|
||||
) = InlineQueryResultAudioCachedImpl(id, fileId, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
|
||||
|
||||
@Serializable
|
||||
data class InlineQueryResultAudioCachedImpl(
|
||||
data class InlineQueryResultAudioCachedImpl internal constructor(
|
||||
@SerialName(idField)
|
||||
override val id: InlineQueryIdentifier,
|
||||
@SerialName(audioFileIdField)
|
||||
override val fileId: FileId,
|
||||
@SerialName(captionField)
|
||||
override val caption: String? = null,
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null,
|
||||
@SerialName(inputMessageContentField)
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultAudioCached {
|
||||
override val type: String = inlineQueryResultAudioType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,42 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudio
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.inlineQueryResultAudioType
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
fun InlineQueryResultAudioImpl(
|
||||
id: InlineQueryIdentifier,
|
||||
url: String,
|
||||
title: String,
|
||||
performer: String? = null,
|
||||
duration: Int? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null,
|
||||
inputMessageContent: InputMessageContent? = null
|
||||
) = InlineQueryResultAudioImpl(id, url, title, performer, duration, text, parseMode, null, replyMarkup, inputMessageContent)
|
||||
|
||||
fun InlineQueryResultAudioImpl(
|
||||
id: InlineQueryIdentifier,
|
||||
url: String,
|
||||
title: String,
|
||||
performer: String? = null,
|
||||
duration: Int? = null,
|
||||
entities: List<TextSource>,
|
||||
replyMarkup: InlineKeyboardMarkup? = null,
|
||||
inputMessageContent: InputMessageContent? = null
|
||||
) = InlineQueryResultAudioImpl(id, url, title, performer, duration, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
|
||||
|
||||
@Serializable
|
||||
data class InlineQueryResultAudioImpl(
|
||||
data class InlineQueryResultAudioImpl internal constructor(
|
||||
@SerialName(idField)
|
||||
override val id: InlineQueryIdentifier,
|
||||
@SerialName(audioUrlField)
|
||||
@@ -23,13 +48,18 @@ data class InlineQueryResultAudioImpl(
|
||||
@SerialName(audioDurationField)
|
||||
override val duration: Int? = null,
|
||||
@SerialName(captionField)
|
||||
override val caption: String? = null,
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null,
|
||||
@SerialName(inputMessageContentField)
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultAudio {
|
||||
override val type: String = inlineQueryResultAudioType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,41 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocumentCached
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
fun InlineQueryResultDocumentCachedImpl(
|
||||
id: InlineQueryIdentifier,
|
||||
fileId: FileId,
|
||||
title: String,
|
||||
description: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null,
|
||||
inputMessageContent: InputMessageContent? = null
|
||||
) = InlineQueryResultDocumentCachedImpl(id, fileId, title, description, text, parseMode, null, replyMarkup, inputMessageContent)
|
||||
|
||||
fun InlineQueryResultDocumentCachedImpl(
|
||||
id: InlineQueryIdentifier,
|
||||
fileId: FileId,
|
||||
title: String,
|
||||
description: String? = null,
|
||||
entities: List<TextSource>,
|
||||
replyMarkup: InlineKeyboardMarkup? = null,
|
||||
inputMessageContent: InputMessageContent? = null
|
||||
) = InlineQueryResultDocumentCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
|
||||
|
||||
@Serializable
|
||||
data class InlineQueryResultDocumentCachedImpl(
|
||||
data class InlineQueryResultDocumentCachedImpl internal constructor(
|
||||
@SerialName(idField)
|
||||
override val id: InlineQueryIdentifier,
|
||||
@SerialName(documentFileIdField)
|
||||
@@ -22,13 +45,18 @@ data class InlineQueryResultDocumentCachedImpl(
|
||||
@SerialName(descriptionField)
|
||||
override val description: String? = null,
|
||||
@SerialName(captionField)
|
||||
override val caption: String? = null,
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null,
|
||||
@SerialName(inputMessageContentField)
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultDocumentCached {
|
||||
override val type: String = inlineQueryResultDocumentType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocument
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
@@ -12,8 +14,37 @@ import dev.inmo.tgbotapi.utils.MimeType
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
fun InlineQueryResultDocumentImpl(
|
||||
id: InlineQueryIdentifier,
|
||||
url: String,
|
||||
title: String,
|
||||
mimeType: MimeType,
|
||||
thumbUrl: String? = null,
|
||||
thumbWidth: Int? = null,
|
||||
thumbHeight: Int? = null,
|
||||
description: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null,
|
||||
inputMessageContent: InputMessageContent? = null
|
||||
) = InlineQueryResultDocumentImpl(id, url, title, mimeType, thumbUrl, thumbWidth, thumbHeight, description, text, parseMode, null, replyMarkup, inputMessageContent)
|
||||
|
||||
fun InlineQueryResultDocumentImpl(
|
||||
id: InlineQueryIdentifier,
|
||||
url: String,
|
||||
title: String,
|
||||
mimeType: MimeType,
|
||||
thumbUrl: String? = null,
|
||||
thumbWidth: Int? = null,
|
||||
thumbHeight: Int? = null,
|
||||
description: String? = null,
|
||||
entities: List<TextSource>,
|
||||
replyMarkup: InlineKeyboardMarkup? = null,
|
||||
inputMessageContent: InputMessageContent? = null
|
||||
) = InlineQueryResultDocumentImpl(id, url, title, mimeType, thumbUrl, thumbWidth, thumbHeight, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
|
||||
|
||||
@Serializable
|
||||
data class InlineQueryResultDocumentImpl(
|
||||
data class InlineQueryResultDocumentImpl internal constructor(
|
||||
@SerialName(idField)
|
||||
override val id: InlineQueryIdentifier,
|
||||
@SerialName(documentUrlField)
|
||||
@@ -31,13 +62,18 @@ data class InlineQueryResultDocumentImpl(
|
||||
@SerialName(descriptionField)
|
||||
override val description: String? = null,
|
||||
@SerialName(captionField)
|
||||
override val caption: String? = null,
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null,
|
||||
@SerialName(inputMessageContentField)
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultDocument {
|
||||
override val type: String = inlineQueryResultDocumentType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,39 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGifCached
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.inlineQueryResultGifType
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
fun InlineQueryResultGifCachedImpl(
|
||||
id: InlineQueryIdentifier,
|
||||
fileId: FileId,
|
||||
title: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null,
|
||||
inputMessageContent: InputMessageContent? = null
|
||||
) = InlineQueryResultGifCachedImpl(id, fileId, title, text, parseMode, null, replyMarkup, inputMessageContent)
|
||||
|
||||
fun InlineQueryResultGifCachedImpl(
|
||||
id: InlineQueryIdentifier,
|
||||
fileId: FileId,
|
||||
title: String? = null,
|
||||
entities: List<TextSource>,
|
||||
replyMarkup: InlineKeyboardMarkup? = null,
|
||||
inputMessageContent: InputMessageContent? = null
|
||||
) = InlineQueryResultGifCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
|
||||
|
||||
@Serializable
|
||||
data class InlineQueryResultGifCachedImpl(
|
||||
data class InlineQueryResultGifCachedImpl internal constructor(
|
||||
@SerialName(idField)
|
||||
override val id: InlineQueryIdentifier,
|
||||
@SerialName(gifFileIdField)
|
||||
@@ -20,13 +41,18 @@ data class InlineQueryResultGifCachedImpl(
|
||||
@SerialName(titleField)
|
||||
override val title: String? = null,
|
||||
@SerialName(captionField)
|
||||
override val caption: String? = null,
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null,
|
||||
@SerialName(inputMessageContentField)
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultGifCached {
|
||||
override val type: String = inlineQueryResultGifType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user