mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-16 20:10:18 +00:00
Compare commits
244 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2f9a5a432 | |||
| 8337da34ca | |||
| f45956b554 | |||
| bec1255d67 | |||
| 39ca29279f | |||
| 70b592baad | |||
| 403aa684a8 | |||
| e10e257c80 | |||
| 5e7bc96b44 | |||
| 79d0eda61d | |||
| 9916b3f469 | |||
| 2bac5f0eed | |||
|
|
01eb072caa | ||
| 496af479b0 | |||
| 386e91e28b | |||
| 91dbcecefc | |||
| 2d743e4c19 | |||
| 8804a24013 | |||
| 8b5244d8df | |||
| 034901a479 | |||
| 7043647584 | |||
| acd9505a5d | |||
| 46c33d5ec4 | |||
| 89dc7a4b2a | |||
| e4f305b3ec | |||
| d56c132201 | |||
| d336e177dd | |||
| 15e29286fb | |||
| 314ceed78e | |||
| 3fa3aa50d9 | |||
| 571296b9a0 | |||
| 3f13e5d062 | |||
| 1874023c05 | |||
| dc0fda2066 | |||
| c0d4a4f01b | |||
| 603762bc22 | |||
| 4db82d6ce2 | |||
| 9bf8f56254 | |||
| 9c926a2265 | |||
| 747854f4f4 | |||
| dcfb14553d | |||
| 6eaa9d699b | |||
| 6788c4d1dd | |||
| 6420737a82 | |||
| 4c36750431 | |||
| fd022742aa | |||
| 0472e35752 | |||
| 768d00eedd | |||
| e9347075ed | |||
|
|
3da74b0c66 | ||
|
|
8b79c5c76b | ||
|
|
a1b471d2ca | ||
|
|
e2c7125f6c | ||
| ec8df3c31c | |||
| 94a35349aa | |||
| 046402454f | |||
| c3978f2dab | |||
| 1019fd4d19 | |||
| 76a9fd1a55 | |||
| aec4c7323a | |||
| 7bdfd5cf69 | |||
| ce95a60fbc | |||
| 3c17a67b01 | |||
| 35bf5b9e9d | |||
| 0087d02b5f | |||
| 212d8946c8 | |||
| 319e43901a | |||
| da01955507 | |||
| 095382040c | |||
| 5545708d38 | |||
| 5d06d86549 | |||
| c081e5c457 | |||
| 555c2ffa04 | |||
| bcee64c103 | |||
| 44a35bd26e | |||
| 1f5c719294 | |||
| 6013c3ba86 | |||
| d4551490f7 | |||
| cc0498a89a | |||
| 0b78c0382f | |||
| c91426a910 | |||
| 5d1c59ff75 | |||
| d2228e274c | |||
| 790959ea49 | |||
| ce9f7f35dc | |||
| 4f984d1dbc | |||
| c83da6be70 | |||
|
|
710438489c | ||
| 6f650f6d6c | |||
| 2d15e13ae6 | |||
| d60ee7b8a5 | |||
| 8f882e9825 | |||
| 48e946c2d0 | |||
| 1758d80020 | |||
| 63b2bd61b5 | |||
| ff2c70fc76 | |||
| e3bfc4472a | |||
| 1cff6f616f | |||
| 1dfe4bf276 | |||
| e4b09032cd | |||
| e8e54a0aea | |||
| 8f85b4cba3 | |||
| 46d65a271d | |||
| e088329ce1 | |||
| 8d9ebb754b | |||
| c0a43077ad | |||
| 1811a63a13 | |||
| cba0e30710 | |||
| ff0b7faa48 | |||
| 975898660c | |||
| cfb7f35d20 | |||
| 147889a66a | |||
| ed9ed715a0 | |||
| a9a3f55c8d | |||
| 58943f2504 | |||
| 5f7633a57e | |||
| 65cfc3220d | |||
| 36d30ef91b | |||
| 41e5c579a2 | |||
| bbf63c51ec | |||
| fb91199f83 | |||
| d76c09ffb2 | |||
| acfb7066d2 | |||
| 7507c107b4 | |||
| 2acb177ad6 | |||
| b5a14077fd | |||
| 5f60bf003f | |||
| f9b2c4c403 | |||
| c909774403 | |||
| 670cfcca13 | |||
| 130e00b62b | |||
| ca4beee95f | |||
| ca784e67df | |||
| 835b8b34f9 | |||
| e6430a729c | |||
| 6c4c9f2fc6 | |||
| 310a7e6e82 | |||
| 7375894645 | |||
| 69973c597b | |||
| 22e8b06fda | |||
| 7ede53fdbb | |||
| ca9051920d | |||
| b477e8d585 | |||
| 8ae2f57d55 | |||
| 1fb2ecf15f | |||
| 6073d914d5 | |||
| 16f55d70af | |||
| b484a31a4a | |||
| 0a162c4129 | |||
| 648f1b488b | |||
| 5fbde4bc06 | |||
| 2a276d9272 | |||
| 9ae252717d | |||
| 456143a266 | |||
| 0bcc98e126 | |||
| ab9ceba41c | |||
| 7cd5666e88 | |||
| 35dcd6ada7 | |||
| ec37df82a9 | |||
| 220cb47615 | |||
| d79b8a337a | |||
| cef6a6f741 | |||
| 9471df1f2d | |||
| f121e5f9c3 | |||
| 7f4fe318c5 | |||
| dbf5c2dbb2 | |||
| 105415873d | |||
| ff32fd1dfc | |||
| 006251ed07 | |||
| 9307582654 | |||
| fe11a2119e | |||
| c31403c1a2 | |||
| 0260e7bedc | |||
| fa43a55f26 | |||
| e9e1f4b9cf | |||
| e7b5b9184d | |||
| 81aa3f2307 | |||
| a9fe584504 | |||
| 4c8861ba79 | |||
| 0ec18cbf06 | |||
| 7008f312dc | |||
| 85317a510e | |||
| d629aa206e | |||
| 6394e1a52b | |||
| 23dca3d307 | |||
| 3032aa8474 | |||
| db19b69ca0 | |||
| f3827f81a7 | |||
| 0532dbb1ae | |||
| efc2681da8 | |||
| 735ed9fd86 | |||
| e856dc4754 | |||
| 0706ff1f95 | |||
| 336b830b0b | |||
| 1a638fe0a5 | |||
| 45467e5bd7 | |||
| 8419b0ab6a | |||
| 49573607fb | |||
| 35fe48db35 | |||
| 590db3e672 | |||
| ea40474c47 | |||
| 7354389f2d | |||
| 1f20ae16aa | |||
| 095c91bf39 | |||
| dc173d752c | |||
| a1788e35b2 | |||
| ea224fd765 | |||
| 7f51544bb9 | |||
| dfb22b0e89 | |||
| e675e841da | |||
| dea43aad8e | |||
| 52e25e934d | |||
| acc067585d | |||
| 47aa1a0795 | |||
| b40cc0c1ea | |||
| b5632626ad | |||
| 67fafdac00 | |||
| 738e628a89 | |||
| 420b846466 | |||
| 05e8c9c90d | |||
| e776c5182f | |||
| be5b3745b9 | |||
| 0de1d9cfda | |||
| 01da98d2fe | |||
| e985100c21 | |||
| 671faabef9 | |||
| bb9c9e22a2 | |||
| 42228f0eaa | |||
| dafd0a8ece | |||
| bee9d82372 | |||
| ec6cf0f029 | |||
| 9cee22165d | |||
| a58aad1198 | |||
| aa78d99179 | |||
| 603efe9259 | |||
| 21e3e10222 | |||
| 34eb6eb4bf | |||
| 565a724b9c | |||
| e87c4a0126 | |||
| 9b16d5d82b | |||
| 9747c8bff1 | |||
| 3ee84700f4 | |||
| 04a463f42c | |||
| 668a201789 |
10
.github/labeler.yml
vendored
Normal file
10
.github/labeler.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
api: "TelegramBotAPI-extensions-api/**"
|
||||
utils: "TelegramBotAPI-extensions-utils/**"
|
||||
core: "TelegramBotAPI/**" # currently not work
|
||||
|
||||
code: "**/*.kt"
|
||||
gradle: "**/*.gradle"
|
||||
versions: "**/gradle.properties"
|
||||
markdown:
|
||||
- "**/*.md"
|
||||
- "!CHANGELOG.md"
|
||||
13
.github/workflows/greetings.yml
vendored
Normal file
13
.github/workflows/greetings.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
name: Greetings
|
||||
|
||||
on: [pull_request, issues]
|
||||
|
||||
jobs:
|
||||
greeting:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/first-interaction@v1
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
issue-message: 'Welcome with your first issue'
|
||||
pr-message: 'Welcome with your first PullRequest'
|
||||
18
.github/workflows/label.yml
vendored
Normal file
18
.github/workflows/label.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# This workflow will triage pull requests and apply a label based on the
|
||||
# paths that are modified in the pull request.
|
||||
#
|
||||
# To use this workflow, you will need to set up a .github/labeler.yml
|
||||
# file with configuration. For more information, see:
|
||||
# https://github.com/actions/labeler/blob/master/README.md
|
||||
|
||||
name: "Pull Request Labeler"
|
||||
on:
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
triage:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/labeler@v2
|
||||
with:
|
||||
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -8,3 +8,6 @@ settings.xml
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
|
||||
local.properties
|
||||
secret.gradle
|
||||
|
||||
@@ -5,6 +5,9 @@ os: linux
|
||||
dist: trusty
|
||||
jdk: oraclejdk8
|
||||
|
||||
script:
|
||||
- ./gradlew build -s
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: build
|
||||
script: ./gradlew build -s -x jvmTest -x jsIrTest -x jsIrBrowserTest -x jsIrNodeTest -x jsLegacyTest -x jsLegacyBrowserTest -x jsLegacyNodeTest
|
||||
- state: test
|
||||
script: ./gradlew allTests
|
||||
|
||||
329
CHANGELOG.md
329
CHANGELOG.md
@@ -1,5 +1,121 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 0.28.0
|
||||
|
||||
**THIS VERSION CONTAINS BREAKING CHANGES**
|
||||
|
||||
***PROJECT PACKAGES WERE CHANGED***
|
||||
|
||||
* Project `TelegramBotAPI` -> `TelegramBotAPI-core`
|
||||
* Project `TelegramBotAPI-all` -> `TelegramBotAPI`
|
||||
|
||||
* `Common`:
|
||||
* Version updates:
|
||||
* `Kotlin`: `1.3.72` -> `1.4.0`
|
||||
* `Coroutines`: `1.3.8` -> `1.3.9`
|
||||
* `Serialization`: `0.20.0` -> `1.0.0-RC`
|
||||
* `Klock`: `1.11.14` -> `1.12.0`
|
||||
* `UUID`: `0.1.1` -> `0.2.1`
|
||||
* `Ktor`: `1.3.2` -> `1.4.0`
|
||||
* `buildMimeType` function now is cache-oriented getter which will save already got mime types into internal map
|
||||
* All deprecations from previous versions were removed
|
||||
* `TelegramBotAPI-core`:
|
||||
* Typealias `TelegramBot` was added
|
||||
* Fully rebuilt `KtorCallFactory` interface to be able to handle custom answers from telegram bot api system
|
||||
* New implementation of `KtorCallFactory` was added: `DownloadFileRequestCallFactory`
|
||||
* `DownloadFile` request was added
|
||||
* All included `KtorCallFactory` realizations (except of abstract) now are objects:
|
||||
* `MultipartRequestCallFactory`
|
||||
* `SimpleRequestCallFactory`
|
||||
* `MediaGroupMemberInputMedia` members now will not have `arguments` property due to redundancy and buggy of that
|
||||
* Field `media` now is common for all `InputMedia` objects
|
||||
* `TelegramBotAPI-extensions-api`:
|
||||
* Extensions `TelegramBot#downloadFile` were added
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* All extensions for media groups (except of `mediaGroupId`) have changed their context: `List<MediaGroupMessage>`
|
||||
-> `List<CommonMessage<MediaGroupContent>>`
|
||||
* `forwardInfo`
|
||||
* `replyTo`
|
||||
* `chat`
|
||||
* `createResend` (several extensions)
|
||||
* Several extensions for downloading of files:
|
||||
* `HttpClient#loadFile`
|
||||
* `PathedFile#download`
|
||||
|
||||
### 0.28.5
|
||||
|
||||
* `TelegramBotAPI-core`:
|
||||
* Now in forward info you can get `ForwardFromSupergroupInfo`
|
||||
* **BREAKING CHANGE** `SendVoice` factory function has changed its signature: now it have now `thumb`
|
||||
(according to the [documentation](https://core.telegram.org/bots/api#sendvoice))
|
||||
* `TelegramBotAPI-extensions-api`:
|
||||
* ALL REQUESTS EXECUTOR USAGES WERE REPLACED WITH `TelegramBot` TYPEALIAS. It should not bring any break changes
|
||||
* Internal changes of `sendRegularPoll` and `sendQuizPoll` extensions
|
||||
* Variable `defaultLivePeriodDelayMillis` now is public
|
||||
* All `send` extensions for `TelegramBot` got their `reply` variations (issue [#144](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/144))
|
||||
* A lot of `send` extensions for `TelegramBot` got their variation with `Chat` instead of `ChatIdentifier`
|
||||
|
||||
### 0.28.4
|
||||
|
||||
* `Common`:
|
||||
* Version updates:
|
||||
* `Ktor`: `1.4.0` -> `1.4.1`
|
||||
* `TelegramBotAPI-core`
|
||||
* Interface `GroupEventMessage` has been added ([#140](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/140))
|
||||
* Old `GroupEventMessage` was renamed to `CommonGroupEventMessage` ([#140](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/140))
|
||||
* Interface `SupergroupEventMessage` has been added ([#140](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/140))
|
||||
* Old `SupergroupEventMessage` was renamed to `CommonSupergroupEventMessage` ([#140](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/140))
|
||||
* Any `GroupEventMessage` now have `from` field ([#140](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/140))
|
||||
* `TelegramBotAPI-extensions-utils`
|
||||
* Extensions `Flow<ChatEventMessage>#onlyGroupEvents` and `Flow<ChatEventMessage>#onlySupergroupEvents` now returns
|
||||
`CommonGroupEventMessage` and `CommonSupergroupEventMessage`
|
||||
|
||||
### 0.28.3
|
||||
|
||||
* Common:
|
||||
* Version updates:
|
||||
* `Klock`: `0.12.0` -> `0.12.1`
|
||||
* `Kotlin serialization`: `1.0.0-RC` -> `1.0.0-RC2` (dependency `kotlinx-serialization-core` was replaced with
|
||||
`kotlinx-serialization-json` due to [kotlinx.serialization library update](https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md#100-rc2--2020-09-21))
|
||||
* `TelegramBotAPI-core`:
|
||||
* All `InlineQueryResult` has changed their type of id for more obvious relation between `InlineQueryResult#id` and
|
||||
`ChosenInlineResult#resultId`: `String` -> `InlineQueryIdentifier`
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Several extensions for updates flows based on `InlineQueryUpdate` has been added:
|
||||
* `Flow<InlineQueryUpdate>#onlyBaseInlineQueriesWithUpdates`
|
||||
* `Flow<InlineQueryUpdate>#onlyBaseInlineQueries`
|
||||
* `Flow<InlineQueryUpdate>#onlyLocationInlineQueriesWithUpdates`
|
||||
* `Flow<InlineQueryUpdate>#onlyLocationInlineQueries`
|
||||
* Several extensions for updates flows based on `ChosenInlineResultUpdate` has been added:
|
||||
* `Flow<ChosenInlineResultUpdate>.onlyBaseChosenInlineResultsWithUpdates`
|
||||
* `Flow<ChosenInlineResultUpdate>.onlyBaseChosenInlineResults`
|
||||
* `Flow<ChosenInlineResultUpdate>.onlyLocationChosenInlineResultsWithUpdates`
|
||||
* `Flow<ChosenInlineResultUpdate>.onlyLocationChosenInlineResults`
|
||||
|
||||
### 0.28.2
|
||||
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Several commands shortcuts for `Flow<ContentMessage<TextContent>>` has been added:
|
||||
* `filterExactCommands`
|
||||
* `filterCommandsInsideTextMessages`
|
||||
* `filterCommandsWithArgs`
|
||||
* Extension `Flow<BaseSentMessageUpdate>.filterCommandsWithArgs` has changed its signature: now it will also have
|
||||
original message paired with list of text sources
|
||||
* Shortcut method `commonMessages` for `onlyCommonMessages`
|
||||
* Shortcuts `onlySentViaBot` and `withoutSentViaBot` now are extensions for any `Flow` with types which implementing
|
||||
`ContentMessage`
|
||||
|
||||
### 0.28.1
|
||||
|
||||
* Common:
|
||||
* Versions updates:
|
||||
* `Kotlin`: `1.4.0` -> `1.4.10`
|
||||
* `UUID`: `0.2.1` -> `0.2.2`
|
||||
* `TelegramBotAPI-core`:
|
||||
* `ExceptionHandler` has changed its incoming type: `Exception` -> `Throwable`
|
||||
* `handleSafely` has changed its signature
|
||||
* `executeUnsafe` has changed its signature
|
||||
|
||||
## 0.27.0
|
||||
|
||||
* `Common`:
|
||||
@@ -49,6 +165,219 @@
|
||||
* `closePollExactAfter`
|
||||
* `closePollAfter`
|
||||
|
||||
### 0.27.11
|
||||
|
||||
* `TelegramBotAPI`:
|
||||
* Extension `String#filenameFromUrl` was created
|
||||
* Extension `PathedFile#filename` was created
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* `Flow<Iterable<T>>.flatMap` extension was added
|
||||
* Extensions for `FlowUpdatesFilter` were added:
|
||||
* `FlowsUpdatesFilter#allSentMessagesFlow` (combination of `messageFlow` and `channelPostFlow`)
|
||||
* `FlowsUpdatesFilter#allSentMediaGroupsFlow` (combination of `messageMediaGroupFlow` and `channelPostMediaGroupFlow`)
|
||||
* `FlowsUpdatesFilter#sentMessages`
|
||||
* `FlowsUpdatesFilter#sentMessagesWithMediaGroups`
|
||||
* `FlowsUpdatesFilter#photoMessagesWithMediaGroups`
|
||||
* `FlowsUpdatesFilter#imageMessagesWithMediaGroups`
|
||||
* `FlowsUpdatesFilter#videoMessagesWithMediaGroups`
|
||||
* `FlowsUpdatesFilter#mediaGroupMessages`
|
||||
* `FlowsUpdatesFilter#mediaGroupPhotosMessages`
|
||||
* `FlowsUpdatesFilter#mediaGroupVideosMessages`
|
||||
* A lot of extensions like `Flow<BaseSentMessageUpdate>#textMessages` were added:
|
||||
* `Flow<BaseSentMessageUpdate>#animationMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#audioMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#contactMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#diceMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#documentMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#gameMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#invoiceMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#locationMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#photoMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#imageMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#pollMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#stickerMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#textMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#venueMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#videoMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#videoNoteMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#voiceMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#mediaGroupMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#mediaGroupPhotosMessages`
|
||||
* `Flow<BaseSentMessageUpdate>#mediaGroupVideosMessages`
|
||||
|
||||
### 0.27.10
|
||||
|
||||
* `TelegramBotAPI-extensions-api`:
|
||||
* Function `telegramBot(TelegramAPIUrlsKeeper)` was added
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Extension `Route#includeWebhookHandlingInRouteWithFlows` was added
|
||||
* A lot of extensions like `FlowsUpdatesFilter#textMessages` were added:
|
||||
* `FlowsUpdatesFilter#animationMessages`
|
||||
* `FlowsUpdatesFilter#audioMessages`
|
||||
* `FlowsUpdatesFilter#contactMessages`
|
||||
* `FlowsUpdatesFilter#diceMessages`
|
||||
* `FlowsUpdatesFilter#documentMessages`
|
||||
* `FlowsUpdatesFilter#gameMessages`
|
||||
* `FlowsUpdatesFilter#invoiceMessages`
|
||||
* `FlowsUpdatesFilter#locationMessages`
|
||||
* `FlowsUpdatesFilter#photoMessages`
|
||||
* `FlowsUpdatesFilter#imageMessages`
|
||||
* `FlowsUpdatesFilter#pollMessages`
|
||||
* `FlowsUpdatesFilter#stickerMessages`
|
||||
* `FlowsUpdatesFilter#textMessages`
|
||||
* `FlowsUpdatesFilter#venueMessages`
|
||||
* `FlowsUpdatesFilter#videoMessages`
|
||||
* `FlowsUpdatesFilter#videoNoteMessages`
|
||||
* `FlowsUpdatesFilter#voiceMessages`
|
||||
|
||||
### 0.27.9
|
||||
|
||||
* `Common`
|
||||
* Versions updates:
|
||||
* `Gradle Wrapper`: `6.5-all` -> `6.5.1-bin`
|
||||
* `Coroutines`: `1.3.7` -> `1.3.8`
|
||||
* `Klock`: `1.11.3` -> `1.11.14`
|
||||
* `UUID`: `0.1.0` -> `0.1.1`
|
||||
|
||||
### 0.27.8
|
||||
|
||||
* `TelegramBotAPI`:
|
||||
* `UnknownUpdateType` was renamed to `UnknownUpdate`
|
||||
* Refactoring and optimization of `FlowsUpdatesFilter`
|
||||
* `Venue` type was replaced to a new package: `com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue`
|
||||
* `Venue` type now implements `Locationed` and delegate realisation to its `location` field
|
||||
* `FoursquareId` and `FoursquareType` typealiases were added
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Several new functions `makeLinkToMessage` was added
|
||||
* `Foursquare` data class was added
|
||||
* Extension `Venue#foursquare` was added
|
||||
* Factory function `Venue` with `Foursquare` parameter was added
|
||||
|
||||
### 0.27.7
|
||||
|
||||
* `TelegramBotAPI`:
|
||||
* Operator function `unaryPlus` was added to `RowBuilder`. Now it is possible to write `row { +button }`
|
||||
* Function `flatMatrix` was added for single-row columns
|
||||
* Operator extension `RowBuilder#plus` was added to be able to write things like `row { this + button }`
|
||||
* `TelegramBotAPI-extensions-api`:
|
||||
* Extensions `RequestsExecutor#sendVenue` with `Location` args were added
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Function `InlineKeyboardMarkup` for flat keyboards was added
|
||||
* Function `ReplyKeyboardMarkup` for flat keyboards was added
|
||||
|
||||
### 0.27.6
|
||||
|
||||
* `Common`:
|
||||
* Versions:
|
||||
* `Kotlin Coroutines`: `1.3.6` -> `1.3.7`
|
||||
* `TelegramBotAPI`:
|
||||
* Interface `PossiblySentViaBot` has been added
|
||||
* Additional interface `PossiblySentViaBotCommonMessage` was added for more explicit typing declaration for
|
||||
compiler
|
||||
* Currently, only `ChannelMessage` and `CommonMessageImpl` are implementing the interface
|
||||
`PossiblySentViaBotCommonMessage`. It could be changed in future
|
||||
* Factory `buildMimeType` was added
|
||||
* `BuiltinMimeTypes` was added
|
||||
* Abstraction `ThumbedWithMimeTypeInlineQueryResult` with `thumbMimeType` field was added
|
||||
* `InlineQueryResultGif` and `InlineQueryResultMpeg4Gif` now extend `ThumbedWithMimeTypeInlineQueryResult`
|
||||
instead of `ThumbedInlineQueryResult`
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* New extensions `onlyCommonMessages`, `onlySentViaBot` and `withoutSentViaBot` was added
|
||||
|
||||
### 0.27.5
|
||||
|
||||
* `Common`:
|
||||
* Versions:
|
||||
* `Klock`: `1.11.1` -> `1.11.3`
|
||||
* `TelegramotAPI`:
|
||||
* Fix: for sending requests caption and text lengths limits were updated
|
||||
* New variant of `row` was added
|
||||
* `makeLinkToMessage` extensions has been deprecated (replaced into `TelegramBotAPI-extensions-utils`)
|
||||
* Next things was deprecated and replaced into `TelegramBotAPI-extensions-utils`:
|
||||
* All `String` formatting public extensions and functions
|
||||
* All extensions like `CaptionedInput#toHtmlCaptions`
|
||||
* All helper extensions for `List<BaseMessageUpdate>`
|
||||
* All `RequestsExecutor#executeAsync` and `RequestsExecutor#executeUnsafe`
|
||||
* `BotCommand` now more strictly check commands which passed to it
|
||||
* Regex `BotCommandNameRegex` was added
|
||||
* `TelegramBotAPI-extensions-api`:
|
||||
* A lot of `RequesstExecutor#getChat` extensions was added for more explicit types showing
|
||||
* New `RequesstExecutor#setMyCommands` extension was added
|
||||
* New field `BotBuilder#ktorClientEngineFactory` introduced
|
||||
* Field `BotBuilder#ktorClientEngine` now is deprecated
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* `safely` function was introduced. It is in `PreviewFeature` state currently
|
||||
* `makeLinkToMessage` extensions has been added
|
||||
* `makeLinkToAddStickerSet` function and its variations were added
|
||||
* Next tools was added from `TelegramBotAPI`:
|
||||
* All `String` formatting extensions and functions
|
||||
* All extensions like `CaptionedInput#toHtmlCaptions`
|
||||
* All helper extensions for `List<BaseMessageUpdate>`
|
||||
* Several new extensions for `SentMediaGroupUpdate` were added:
|
||||
* `SentMediaGroupUpdate#forwardInfo`
|
||||
* `SentMediaGroupUpdate#replyTo`
|
||||
* `SentMediaGroupUpdate#chat`
|
||||
* `SentMediaGroupUpdate#mediaGroupId`
|
||||
* Several `List<MediaGroupMessage>.createResend` extensions were added
|
||||
* `RequestsExecutor#executeAsync` and `RequestsExecutor#executeUnsafe`
|
||||
|
||||
### 0.27.4
|
||||
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Several extensions for updates was added:
|
||||
* `onlyBaseMessageUpdates`
|
||||
* `onlySentMessageUpdates`
|
||||
* `onlyEditMessageUpdates`
|
||||
* `onlyMediaGroupsUpdates`
|
||||
* `onlySentMediaGroupUpdates`
|
||||
* `onlyEditMediaGroupUpdates`
|
||||
* Renames in chat filters extensions:
|
||||
* `filterBaseMessageUpdates` -> `filterBaseMessageUpdatesByChatId` and `filterBaseMessageUpdatesByChat`
|
||||
* `filterSentMediaGroupUpdates` -> `filterSentMediaGroupUpdatesByChatId` and `filterSentMediaGroupUpdatesByChat`
|
||||
|
||||
### 0.27.3
|
||||
|
||||
* `TelegramBotAPI`:
|
||||
* `UpdateDeserializationStrategy` is publicly available now
|
||||
* All `setWebhook` extensions was marked as deprecated, renamed and replaced into `TelegramBotAPI-extensions-utils`
|
||||
* Typealias `ExceptionHandler` was added - it will be used for `handleSafely`
|
||||
* `SetWebhook` factories signatures was changed (backward compatibility was not broken)
|
||||
* `executeUnsafe` now working differently
|
||||
* Now it is possible to pass exceptions handler into `executeUnsafe`
|
||||
* `BasketballDiceAnimationType` was added
|
||||
* `UnknownDiceAnimationType` now is deprecated due to renaming - currently it is typealias for `CustomDiceAnimationType`
|
||||
* `CustomDiceAnimationType` now is `data` class instead of common class
|
||||
* `FlowsUpdatesFilter` will use size 64 by default for internal broadcast channels
|
||||
* `TelegramBotAPI-extensions-api`:
|
||||
* Long Polling extensions now are deprecated in this project. It was replaced into `TelegramBotAPI-extensions-utils`
|
||||
* Several `telegramBot` functions was renamed into `telegramBotWithCustomClientConfig`
|
||||
* Add one more `setWebhookInfo` realisation
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Extension `toTelegramUpdate` was added
|
||||
* Long Polling extensions were added
|
||||
* Updates utils were added
|
||||
* New extensions `startListenWebhooks`, `setWebhookInfoAndStartListenWebhooks` and `includeWebhookHandlingInRoute` was added
|
||||
* New extension `CoroutineScope#updateHandlerWithMediaGroupsAdaptation` was added
|
||||
* New extension `flowsUpdatesFilter` was added
|
||||
* `TelegramBotAPI-all`:
|
||||
* Project was created
|
||||
|
||||
### 0.27.2
|
||||
|
||||
* `Common`:
|
||||
* Versions:
|
||||
* Coroutines: `1.3.5` -> `1.3.6`
|
||||
* Klock: `1.10.5` -> `1.11.1`
|
||||
* `TelegramBotAPI`:
|
||||
* Expected class `MimeType` was added
|
||||
* Field `MimeTyped#mimeType` now typed by `MimeType` instead of `String`
|
||||
* `MediaGroupMemberInputMedia` children now can be deserialized (but only those ones who are declared inside library)
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Chat events splitters added:
|
||||
* Extension `Flow<ChatEventMessage>#onlyChannelEvents` was added
|
||||
* Extension `Flow<ChatEventMessage>#onlyGroupEvents` was added
|
||||
* Extension `Flow<ChatEventMessage>#onlySupergroupEvents` was added
|
||||
|
||||
### 0.27.1
|
||||
|
||||
* `TelegramBotAPI`:
|
||||
|
||||
79
README.md
79
README.md
@@ -1,30 +1,40 @@
|
||||
# TelegramBotAPI
|
||||
|
||||
| Common info | [](https://github.com/KotlinBy/awesome-kotlin) [](https://t.me/InMoTelegramBotAPI) [](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI) |
|
||||
| Common info | [](https://github.com/KotlinBy/awesome-kotlin) [](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI) [Small survey](https://forms.gle/tnjuExdSKEr32ygKA)|
|
||||
| -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| TelegramBotAPI status | [](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI) |
|
||||
| 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) |
|
||||
| TelegramBotAPI Core status | [](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-core/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI) |
|
||||
| TelegramBotAPI Extensions status | [](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-api/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-api) |
|
||||
| TelegramBotAPI Util Extensions status | [](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-utils/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-utils) |
|
||||
| TelegramBotAPI All status | [](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-all) |
|
||||
|
||||
**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`**
|
||||
|
||||
|
||||
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:
|
||||
|
||||
* [TelegramBotAPI](TelegramBotAPI/README.md) - core of library. In fact it is independent library and can be used alone
|
||||
* [TelegramBotAPI-core](TelegramBotAPI-core/README.md) - core of library. In fact it is independent library and can be used alone
|
||||
without any additional library
|
||||
* [TelegramBotAPI Extensions](TelegramBotAPI-extensions-api/README.md) - contains extensions (mostly for
|
||||
`RequestsExecutor`), which allows to use the core library in more pleasant way
|
||||
* [TelegramBotAPI Util Extensions](TelegramBotAPI-extensions-utils/README.md) - contains extensions for more comfortable
|
||||
work with commands, updates and other different things
|
||||
* [TelegramBotAPI](TelegramBotAPI/README.md) - concentration of all previously mentioned libraries
|
||||
|
||||
Most part of some specific solves or unuseful
|
||||
moments are describing by official [Telegram Bot API](https://core.telegram.org/bots/api).
|
||||
|
||||
## JavaScript notes
|
||||
|
||||
### Versions before `0.28.0`
|
||||
|
||||
In case if you are want to use this library inside of browser, you will need additional settings (thanks for help to [Alexander Nozik](https://research.jetbrains.org/researchers/altavir)):
|
||||
|
||||
<details>
|
||||
<summary>Gradle build script help</summary>
|
||||
<summary>Gradle build script help (for versions before 0.28.0)</summary>
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
@@ -62,11 +72,16 @@ kotlin {
|
||||
|
||||
## Ok, where should I start?
|
||||
|
||||
In most cases, the most simple way will be to implement
|
||||
[TelegramBotAPI Extensions](TelegramBotAPI-extensions-api/README.md) and
|
||||
[TelegramBotAPI Util Extensions](TelegramBotAPI-extensions-utils/README.md) for the reason that they contains more
|
||||
simple tools. If you want to dive deeper in the core of library or develop something for it - welcome to
|
||||
[TelegramBotAPI](TelegramBotAPI/README.md).
|
||||

|
||||
|
||||
In most cases, the most simple way will be to implement [TelegramBotAPI](TelegramBotAPI/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 API Extensions](TelegramBotAPI-extensions-api/README.md),
|
||||
[TelegramBotAPI Util Extensions](TelegramBotAPI-extensions-utils/README.md) or even
|
||||
[TelegramBotAPI-core](TelegramBotAPI-core/README.md).
|
||||
|
||||
If you want to dive deeper in the core of library or develop something for it - welcome to learn more from
|
||||
[TelegramBotAPI-core](TelegramBotAPI-core/README.md) and our [Telegram Chat](https://teleg.one/InMoTelegramBotAPIChat).
|
||||
|
||||
Anyway, all libraries are very typical inside of them. Examples:
|
||||
|
||||
@@ -74,3 +89,49 @@ Anyway, all libraries are very typical inside of them. Examples:
|
||||
* `TelegramBotAPI-extensions-api` typical syntax look like `requestsExecutor.someRequest()` (in most cases it would be
|
||||
better to use `bot` name instead of `requestsExecutor`)
|
||||
* `TelegramBotAPI-extensions-utils` will look like `filter.filterBaseMessageUpdates(chatId).filterExactCommands(Regex("^.*$"))...`
|
||||
|
||||
## Build instruction
|
||||
|
||||
If you want to build this project or to contribute, there are several recommendations:
|
||||
|
||||
### Build
|
||||
|
||||
In case if you want to just build project, run next command:
|
||||
|
||||
```bash
|
||||
./gradlew clean build
|
||||
```
|
||||
|
||||
On windows:
|
||||
|
||||
```
|
||||
gradlew.bat clean build
|
||||
```
|
||||
|
||||
### Publishing for work with your version locally
|
||||
|
||||
In case, if you want to work in your other projects using your modification (or some state) of this library,
|
||||
you can use next code:
|
||||
|
||||
```bash
|
||||
./gradlew clean build publishToMavenLocal
|
||||
```
|
||||
|
||||
On windows:
|
||||
|
||||
```
|
||||
gradlew.bat clean build publishToMavenLocal
|
||||
```
|
||||
|
||||
But you must remember, that in this case your local maven repo must be the first one from
|
||||
your project retrieving libraries:
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
mavenLocal() // that must be the first one
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
```
|
||||
|
||||
Besides, for your own version you can change variable `library_version` in the file [gradle.properties](./gradle.properties).
|
||||
|
||||
151
TelegramBotAPI-core/README.md
Normal file
151
TelegramBotAPI-core/README.md
Normal file
@@ -0,0 +1,151 @@
|
||||
# TelegramBotAPI-core
|
||||
|
||||
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-core/_latestVersion)
|
||||
[](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI)
|
||||
|
||||
## What is it?
|
||||
|
||||
Library for Object-Oriented and type-safe work with Telegram Bot API. Most part of some specific solves or unuseful
|
||||
moments are describing by official [Telegram Bot API](https://core.telegram.org/bots/api).
|
||||
|
||||
## 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.
|
||||
|
||||
## How to implement library?
|
||||
|
||||
Common ways to implement this library are presented here. In some cases it will require additional steps
|
||||
like inserting of additional libraries (like `kotlin stdlib`). In the examples will be used variable
|
||||
`telegrambotapi.version`, which must be set up by developer. Available versions are presented on
|
||||
[bintray](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-core), next version is last published:
|
||||
|
||||
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-core/_latestVersion)
|
||||
|
||||
Currently, last versions of library can be available from the Maven repository with errors (for the reason difficult in publishing
|
||||
of signed artifacts in Bintray). You can:
|
||||
|
||||
* Use earlier version (available version you can find
|
||||
[here](https://mvnrepository.com/artifact/com.github.insanusmokrassar/TelegramBotAPI) (before 0.28.0) or [here](https://mvnrepository.com/artifact/com.github.insanusmokrassar/TelegramBotAPI-core))
|
||||
* Add `jCenter` repository in build config
|
||||
|
||||
### Maven
|
||||
|
||||
Dependency config presented here:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.insanusmokrassar</groupId>
|
||||
<artifactId>TelegramBotAPI-core</artifactId>
|
||||
<version>${telegrambotapi.version}</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle
|
||||
|
||||
To use last versions you will need to add one line in repositories block of your `build.gradle`:
|
||||
|
||||
`jcenter()` or `mavenCentral()`
|
||||
|
||||
And add next line to your dependencies block:
|
||||
|
||||
```groovy
|
||||
implementation "com.github.insanusmokrassar:TelegramBotAPI-core:$telegrambotapi_version"
|
||||
```
|
||||
|
||||
or for old gradle:
|
||||
|
||||
```groovy
|
||||
compile "com.github.insanusmokrassar:TelegramBotAPI-core:$telegrambotapi_version"
|
||||
```
|
||||
|
||||
## How to work with library?
|
||||
|
||||
For now, this library have no some API god-object. Instead of this, this library has several
|
||||
important objects:
|
||||
|
||||
* [RequestsExecutor](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt)
|
||||
* [Requests](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests)
|
||||
* [Types](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types)
|
||||
|
||||
### Types
|
||||
|
||||
Types declare different objects representation. For example, `Chat` for now represented as
|
||||
interface and has several realisations:
|
||||
|
||||
* `PrivateChat`
|
||||
* `GroupChat`
|
||||
* `SupergroupChat`
|
||||
* `ChannelChat`
|
||||
|
||||
Instead of common garbage with all information as in original [Chat](https://core.telegram.org/bots/api#chat),
|
||||
here it was separated for more obvious difference between chats types and their possible content.
|
||||
|
||||
The same principle work with a lot of others things in this Telegram bot API.
|
||||
|
||||
### Requests
|
||||
|
||||
Requests usually are very simple objects, but some of them are using their own
|
||||
build factories. For example, the next code show, how to get information about bot:
|
||||
|
||||
```kotlin
|
||||
val requestsExecutor: RequestsExecutor = ...
|
||||
requestsExecutor.execute(GetMe())
|
||||
```
|
||||
|
||||
Also there is an alternative syntax for requests (like `requestsExecutor.getMe()` in project
|
||||
[TelegramBotAPI-extensions-api](../TelegramBotAPI-extensions-api/README.md))
|
||||
|
||||
The result type of [GetMe (and getMe extension)](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt)
|
||||
request is
|
||||
[ExtendedBot](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt).
|
||||
|
||||
### RequestsExecutor
|
||||
|
||||
It is base object which can be used to execute requests in API. For now by default included Ktor
|
||||
realisation of `RequestsExecutor`, but it is possible, that in future it will be extracted in separated
|
||||
project. How to create `RequestsExecutor`:
|
||||
|
||||
```kotlin
|
||||
val requestsExecutor = KtorRequestsExecutor(
|
||||
TelegramAPIUrlsKeeper(TOKEN)
|
||||
)
|
||||
```
|
||||
|
||||
Here:
|
||||
|
||||
* `KtorRequestsExecutor` - default realisation with [ktor](https://ktor.io)
|
||||
* `TelegramAPIUrlsKeeper` - special keeper, which you can save and use for getting files full urls (`resolveFileURL`
|
||||
extension inside of `PathedFile.kt`)
|
||||
* `TOKEN` is just a token of bot which was retrieved according to
|
||||
[instruction](https://core.telegram.org/bots#3-how-do-i-create-a-bot).
|
||||
|
||||
By default, for JVM there is implemented `CIO` client engine, but there is not server engine. Both can be changed like
|
||||
here:
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
// ...
|
||||
implementation "io.ktor:ktor-server-cio:$ktor_version" // for implementing of server engine
|
||||
implementation "io.ktor:ktor-client-okhttp:$ktor_version" // for implementing of additional client engine
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
You can avoid using of `server` dependency in case if you will not use `Webhook`s. In this case,
|
||||
dependencies list will be simplify:
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
// ...
|
||||
implementation "io.ktor:ktor-client-okhttp:$ktor_version" // for implementing of additional client engine
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Here was used `okhttp` realisation of client, but there are several others engines for Ktor. More information
|
||||
available on ktor.io site for [client](https://ktor.io/clients/http-client/engines.html) and [server](https://ktor.io/quickstart/artifacts.html)
|
||||
engines.
|
||||
|
||||
91
TelegramBotAPI-core/build.gradle
Normal file
91
TelegramBotAPI-core/build.gradle
Normal file
@@ -0,0 +1,91 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
}
|
||||
|
||||
project.version = "$library_version"
|
||||
project.group = "$library_group"
|
||||
|
||||
apply from: "publish.gradle"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js(BOTH) {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlin_serialisation_runtime_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-properties:$kotlin_serialisation_runtime_version"
|
||||
|
||||
api "com.soywiz.korlibs.klock:klock:$klock_version"
|
||||
api "com.benasher44:uuid:$uuid_version"
|
||||
|
||||
api "io.ktor:ktor-client-core:$ktor_version"
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-common')
|
||||
implementation kotlin('test-annotations-common')
|
||||
}
|
||||
}
|
||||
|
||||
jvmMain {
|
||||
dependencies {
|
||||
api "io.ktor:ktor-server:$ktor_version"
|
||||
api "io.ktor:ktor-server-host-common:$ktor_version"
|
||||
|
||||
api "io.ktor:ktor-client-cio:$ktor_version"
|
||||
|
||||
api "javax.activation:activation:$javax_activation_version"
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
|
||||
jsTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
implementation kotlin('test-js')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targets.all {
|
||||
compilations.all {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs += ["-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi", "-Xopt-in=kotlin.RequiresOptIn"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
53
TelegramBotAPI-core/maven.publish.gradle
Normal file
53
TelegramBotAPI-core/maven.publish.gradle
Normal file
@@ -0,0 +1,53 @@
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
task javadocsJar(type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
project.publishing.publications.all {
|
||||
// rename artifacts
|
||||
groupId "${project.group}"
|
||||
if (it.name.contains('kotlinMultiplatform')) {
|
||||
artifactId = "${project.name}"
|
||||
} else {
|
||||
artifactId = "${project.name}-$name"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
TelegramBotAPI-core/mpp_publish_template.kpsb
Normal file
1
TelegramBotAPI-core/mpp_publish_template.kpsb
Normal file
@@ -0,0 +1 @@
|
||||
{"bintrayConfig":{"repo":"StandardRepository","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"}
|
||||
58
TelegramBotAPI-core/publish.gradle
Normal file
58
TelegramBotAPI-core/publish.gradle
Normal file
@@ -0,0 +1,58 @@
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
|
||||
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 = "StandardRepository"
|
||||
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')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bintrayUpload.doFirst {
|
||||
publications = publishing.publications.collect {
|
||||
if (it.name.contains('kotlinMultiplatform')) {
|
||||
null
|
||||
} else {
|
||||
it.name
|
||||
}
|
||||
} - null
|
||||
}
|
||||
|
||||
bintrayUpload.dependsOn publishToMavenLocal
|
||||
@@ -12,7 +12,15 @@ interface CaptionedOutput : Captioned {
|
||||
}
|
||||
|
||||
interface CaptionedInput : Captioned {
|
||||
/**
|
||||
* Not full list of entities. This list WILL NOT contain [TextPart]s with [com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.RegularTextSource]
|
||||
* @see [CaptionedInput.fullEntitiesList]
|
||||
*/
|
||||
val captionEntities: List<TextPart>
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert its [CaptionedInput.captionEntities] to list of [com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource]
|
||||
* with [com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.RegularTextSource]
|
||||
*/
|
||||
fun CaptionedInput.fullEntitiesList(): FullTextSourcesList = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList()
|
||||
@@ -12,7 +12,15 @@ interface ExplainedOutput : Explained {
|
||||
}
|
||||
|
||||
interface ExplainedInput : Explained {
|
||||
/**
|
||||
* Not full list of entities. This list WILL NOT contain [TextPart]s with [com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.RegularTextSource]
|
||||
* @see [ExplainedInput.fullEntitiesList]
|
||||
*/
|
||||
val explanationEntities: List<TextPart>
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert its [ExplainedInput.explanationEntities] to list of [com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource]
|
||||
* with [com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.RegularTextSource]
|
||||
*/
|
||||
fun ExplainedInput.fullEntitiesList(): FullTextSourcesList = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList()
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||
|
||||
interface MimeTyped {
|
||||
val mimeType: MimeType?
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
import io.ktor.client.HttpClient
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
interface KtorCallFactory {
|
||||
suspend fun <T: Any> makeCall(
|
||||
client: HttpClient,
|
||||
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||
request: Request<T>,
|
||||
jsonFormatter: Json
|
||||
): T?
|
||||
}
|
||||
@@ -1,21 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.BaseRequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.MultipartRequestCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.SimpleRequestCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.newRequestException
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.EmptyLimiter
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.RequestLimiter
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.receive
|
||||
import io.ktor.client.features.*
|
||||
import io.ktor.client.statement.HttpStatement
|
||||
import io.ktor.client.statement.readText
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class KtorRequestsExecutor(
|
||||
@@ -28,7 +24,7 @@ class KtorRequestsExecutor(
|
||||
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
||||
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
||||
if (!excludeDefaultFactories) {
|
||||
asSequence().plus(SimpleRequestCallFactory()).plus(MultipartRequestCallFactory()).toList()
|
||||
this + listOf(SimpleRequestCallFactory, MultipartRequestCallFactory, DownloadFileRequestCallFactory)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
@@ -44,8 +40,8 @@ class KtorRequestsExecutor(
|
||||
return handleSafely(
|
||||
{ e ->
|
||||
throw if (e is ClientRequestException) {
|
||||
val content = e.response.readText()
|
||||
val responseObject = jsonFormatter.parse(Response.serializer(), content)
|
||||
val content = e.response ?.readText() ?: throw e
|
||||
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
|
||||
newRequestException(
|
||||
responseObject,
|
||||
content,
|
||||
@@ -57,39 +53,20 @@ class KtorRequestsExecutor(
|
||||
}
|
||||
) {
|
||||
requestsLimiter.limit {
|
||||
var statement: HttpStatement? = null
|
||||
for (factory in callsFactories) {
|
||||
statement = factory.prepareCall(
|
||||
var result: T? = null
|
||||
for (potentialFactory in callsFactories) {
|
||||
result = potentialFactory.makeCall(
|
||||
client,
|
||||
telegramAPIUrlsKeeper.commonAPIUrl,
|
||||
request
|
||||
telegramAPIUrlsKeeper,
|
||||
request,
|
||||
jsonFormatter
|
||||
)
|
||||
if (statement != null) {
|
||||
if (result != null) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
val response = statement?.execute() ?: throw IllegalArgumentException("Can't execute request: $request")
|
||||
val content = response.receive<String>()
|
||||
val responseObject = jsonFormatter.parse(Response.serializer(), content)
|
||||
|
||||
(responseObject.result?.let {
|
||||
jsonFormatter.fromJson(request.resultDeserializer, it)
|
||||
} ?: responseObject.parameters?.let {
|
||||
val error = it.error
|
||||
if (error is RetryAfterError) {
|
||||
delay(error.leftToRetry)
|
||||
execute(request)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?: response.let {
|
||||
throw newRequestException(
|
||||
responseObject,
|
||||
content,
|
||||
"Can't get result object from $content"
|
||||
)
|
||||
})
|
||||
result ?: error("Can't execute request: $request")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.newRequestException
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.GetUpdates
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.receive
|
||||
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
|
||||
|
||||
abstract class AbstractRequestCallFactory : KtorCallFactory {
|
||||
private val methodsCache: MutableMap<String, String> = mutableMapOf()
|
||||
override suspend fun <T : Any> makeCall(
|
||||
client: HttpClient,
|
||||
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||
request: Request<T>,
|
||||
jsonFormatter: Json
|
||||
): T? {
|
||||
val preparedBody = prepareCallBody(client, urlsKeeper, request) ?: return null
|
||||
|
||||
client.post<HttpResponse> {
|
||||
url(
|
||||
methodsCache[request.method()] ?: "${urlsKeeper.commonAPIUrl}/${request.method()}".also {
|
||||
methodsCache[request.method()] = it
|
||||
}
|
||||
)
|
||||
accept(ContentType.Application.Json)
|
||||
|
||||
if (request is GetUpdates) {
|
||||
request.timeout?.times(1000L)?.let { customTimeoutMillis ->
|
||||
if (customTimeoutMillis > 0) {
|
||||
timeout {
|
||||
requestTimeoutMillis = customTimeoutMillis
|
||||
socketTimeoutMillis = customTimeoutMillis
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body = preparedBody
|
||||
}.let { response ->
|
||||
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"
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun <T : Any> prepareCallBody(
|
||||
client: HttpClient,
|
||||
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||
request: Request<T>
|
||||
): Any?
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.DownloadFile
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.handleSafely
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.HttpMethod
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
object DownloadFileRequestCallFactory : KtorCallFactory {
|
||||
override suspend fun <T : Any> makeCall(
|
||||
client: HttpClient,
|
||||
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||
request: Request<T>,
|
||||
jsonFormatter: Json
|
||||
): T? = (request as? DownloadFile) ?.let {
|
||||
val fullUrl = "${urlsKeeper.fileBaseUrl}/${it.filePath}"
|
||||
|
||||
return handleSafely {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
client.get<ByteArray>(fullUrl) as T // always ByteArray
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapWithCommonValues
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
@@ -8,11 +9,10 @@ import io.ktor.client.request.forms.formData
|
||||
import io.ktor.http.Headers
|
||||
import io.ktor.http.HttpHeaders
|
||||
|
||||
class MultipartRequestCallFactory : AbstractRequestCallFactory() {
|
||||
|
||||
object MultipartRequestCallFactory : AbstractRequestCallFactory() {
|
||||
override fun <T : Any> prepareCallBody(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||
request: Request<T>
|
||||
): Any? = (request as? MultipartRequest) ?.let { castedRequest ->
|
||||
MultiPartFormDataContent(
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.content.TextContent
|
||||
|
||||
class SimpleRequestCallFactory : AbstractRequestCallFactory() {
|
||||
object SimpleRequestCallFactory : AbstractRequestCallFactory() {
|
||||
override fun <T : Any> prepareCallBody(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||
request: Request<T>
|
||||
): Any? = (request as? SimpleRequest<T>) ?.let { _ ->
|
||||
val content = request.json().toString()
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import io.ktor.utils.io.core.Closeable
|
||||
|
||||
/**
|
||||
* Interface for making requests to Telegram Bot API. Currently, there is only one built-in implementation -
|
||||
* [com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorRequestsExecutor]
|
||||
*
|
||||
* @see Request
|
||||
* @see com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorRequestsExecutor
|
||||
*/
|
||||
interface RequestsExecutor : Closeable {
|
||||
/**
|
||||
* Unsafe execution of incoming [request]. Can throw almost any exception. So, it is better to use
|
||||
* something like [com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.shortcuts.executeAsync] or
|
||||
* [com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.shortcuts.executeUnsafe]
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
suspend fun <T : Any> execute(request: Request<T>): T
|
||||
}
|
||||
|
||||
typealias TelegramBot = RequestsExecutor
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.builtins.ByteArraySerializer
|
||||
|
||||
class DownloadFile(
|
||||
val filePath: String
|
||||
) : Request<ByteArray> {
|
||||
override fun method(): String = filePath
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<ByteArray>
|
||||
get() = ByteArraySerializer()
|
||||
}
|
||||
@@ -11,6 +11,15 @@ private val updatesListSerializer = ListSerializer(
|
||||
UpdateSerializerWithoutSerialization
|
||||
)
|
||||
|
||||
/**
|
||||
* Request updates from Telegram Bot API system. It is important, that the result updates WILL NOT include
|
||||
* [com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.MediaGroupUpdate] objects due to the fact,
|
||||
* that it is internal abstraction and in fact any [com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage]
|
||||
* is just a common [com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message]
|
||||
*
|
||||
* @see com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates.retrieving.updateHandlerWithMediaGroupsAdaptation
|
||||
* @see com.github.insanusmokrassar.TelegramBotAPI.utils.convertWithMediaGroupUpdates
|
||||
*/
|
||||
@Serializable
|
||||
data class GetUpdates(
|
||||
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.toInputMediaFileAttachmentName
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.*
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable(InputFileSerializer::class)
|
||||
sealed class InputFile {
|
||||
@@ -21,11 +25,17 @@ fun String.toInputFile() = FileId(this)
|
||||
|
||||
@Serializer(InputFile::class)
|
||||
internal object InputFileSerializer : KSerializer<InputFile> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveDescriptor(FileId::class.toString(), PrimitiveKind.STRING)
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(FileId::class.toString(), PrimitiveKind.STRING)
|
||||
override fun serialize(encoder: Encoder, value: InputFile) = encoder.encodeString(value.fileId)
|
||||
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
|
||||
@@ -5,11 +5,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
/**
|
||||
* Representation of https://core.telegram.org/bots/api#setchatadministratorcustomtitle
|
||||
*
|
||||
* Please, remember about restrictions for characters in custom title
|
||||
*/
|
||||
@Serializable
|
||||
data class SetChatAdministratorCustomTitle(
|
||||
@SerialName(chatIdField)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user