mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-18 13:00:18 +00:00
Compare commits
185 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| b336b17eef | |||
| 76b25d719a | |||
| a4d077dd17 | |||
| 469712150b | |||
| fad27ede78 | |||
| 1de90412b3 | |||
| 215c8793e1 | |||
| 54835f97d1 | |||
| 923e929670 | |||
| 37488e92e6 | |||
| 830ca8122d | |||
| fbb2758bdb | |||
| a5c3e06f1c | |||
| c6fb50c4a6 | |||
| 976c0b86dc | |||
| fee5d8f925 | |||
| 808746e12d | |||
| 3fb80dd475 | |||
| db8ea0da94 | |||
| fbdfb714a3 | |||
| 1facfbc2b7 | |||
| 914a0662a9 | |||
| eda3003b7d | |||
| 459942de36 | |||
| 17f64f9b48 | |||
| 3f896c2240 | |||
| 94f8c971c5 | |||
| c43109c063 | |||
| f6058e29b4 | |||
| 3a37311331 | |||
| 9fe1472e64 | |||
| f1480c40a7 | |||
| 88eebdc448 | |||
| 8c76283db5 | |||
| 7668c48081 | |||
| 35d2135f73 | |||
| 1cb0e096be | |||
| 31f7c7f31b | |||
| 82d3b3bc48 | |||
| b3734a5c2a | |||
| 55b8736d50 | |||
| 3334fd3ca6 | |||
|
|
e2416b405a | ||
| 14f012fbfa | |||
| 1ff55057f2 | |||
| 71b5e33dbc | |||
| 08d9d183f4 | |||
| 7183634fd6 | |||
| cf9f270651 | |||
| bd87938e9c | |||
| ba76eaeb90 | |||
| d8492ae168 | |||
| 0db85232d3 | |||
| bcf2325be8 | |||
| 51174a13de | |||
| dfc1fa4d7e | |||
| 10a1d1cb38 | |||
| 6c39dc4d06 | |||
| 4877b8958e | |||
| db9c460e66 | |||
| 2bd5d53b2a | |||
| 577436843d | |||
| 048aa93044 | |||
| 4e49de0dd7 | |||
| 9dc5a7624d | |||
| 21a15db031 | |||
| a6aa4b8758 | |||
| e85d5df03e | |||
| 6833640c48 | |||
| c22c1bb144 | |||
| 8293d6683c | |||
| 7e6e892c45 | |||
| 43ac09a79b | |||
| ee1f115d77 | |||
| 7d85b6fb88 | |||
| 013944c5c9 | |||
| 55ed3e165b | |||
| 9c0106d229 | |||
| 9cd2a6220c | |||
| 033ec8f2da | |||
| 274afe8efc | |||
| e60630b331 | |||
| f6692a22d1 | |||
| 53257ff131 | |||
| ec70813e49 | |||
| 54589ed17b | |||
| 1d3736c44e | |||
| 8ef7acab2d | |||
| c3fca5c6c4 | |||
| 84d2c88032 | |||
| b7ec2f2b86 | |||
| 97d6d3ad13 | |||
| 3dd428c7d9 | |||
| 688de1053b | |||
| a4fae36b22 | |||
| 909a7fd26a | |||
| 041232e260 | |||
| d4c409107a | |||
| a0db95d929 | |||
| fb34b0bec1 | |||
| d18863b7b3 | |||
| c5c8a743e6 | |||
| 89881a7349 | |||
| 865edf385f | |||
| c85faa73c0 | |||
| 6b3f836096 | |||
| 574ffbc44d | |||
| a0120afb08 | |||
| 0b4b4950c2 | |||
| b3391330a0 | |||
| 518dee46b3 | |||
| c9de4bc79e | |||
| badb138bc1 |
7
.github/labeler.yml
vendored
Normal file
7
.github/labeler.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
api: "TelegramBotAPI-extensions-api/**"
|
||||||
|
utils: "TelegramBotAPI-extensions-utils/**"
|
||||||
|
core: "TelegramBotAPI/**" # currently not work
|
||||||
|
|
||||||
|
code: "**/*.kt"
|
||||||
|
gradle: "**/*.gradle"
|
||||||
|
markdown: "**/*.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 }}"
|
||||||
1
.github/write-good.yml
vendored
Normal file
1
.github/write-good.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
spellchecker: true
|
||||||
246
CHANGELOG.md
246
CHANGELOG.md
@@ -1,5 +1,251 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 0.27.0
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* Versions updates:
|
||||||
|
* `Kotlin`: `1.3.71` -> `1.3.72`
|
||||||
|
* `Klock`: `1.10.3` -> `1.10.5`
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* Typealias `LongSeconds` was added for correct explanation of seconds in `Long` primitive type
|
||||||
|
* Several new fields was added:
|
||||||
|
* `explanationField`
|
||||||
|
* `explanationEntitiesField`
|
||||||
|
* `openPeriodField`
|
||||||
|
* `closeDateField`
|
||||||
|
* Extension `List<TextPart>#justTextSources` was added for mapping of `List<TextPart>` to `List<TextSource>`
|
||||||
|
* Field `SendPoll#closeInfo` was added
|
||||||
|
* Range `openPeriodPollSecondsLimit` was added and used in all `SendPoll` requests for checking income data
|
||||||
|
* `SendQuizPoll` now able to use fields `caption` and `parseMode` for `explanation` functionality
|
||||||
|
* `quizPollExplanationLimit` was added for checking `QuizPoll` explanation size
|
||||||
|
* Field `TextLinkTextSource#url` was added
|
||||||
|
* Field `TextMentionTextSource#user` was added
|
||||||
|
* Sealed class `ScheduledCloseInfo` was added
|
||||||
|
* Class `ExactScheduledCloseInfo` was added for cases with `close_date`
|
||||||
|
* Class `ApproximateScheduledCloseInfo` was added for cases with `open_period`
|
||||||
|
* Field `Poll#scheduledCloseInfo` was added
|
||||||
|
* Sealed class `MultipleAnswersPoll` was added
|
||||||
|
* Class `RegularPoll` now extends `MultipleAnswersPoll`
|
||||||
|
* `Dice` class was replaced into new package
|
||||||
|
* Sealed class `DiceAnimationType` was added
|
||||||
|
* Field `Dice#animationType` was added as `emoji` API representation
|
||||||
|
* `SendDice` now receive `animationType` as second parameter
|
||||||
|
* For `List<TextSource>` was added several extensions:
|
||||||
|
* `toMarkdownCaptions`
|
||||||
|
* `toMarkdownTexts`
|
||||||
|
* `toMarkdownV2Captions`
|
||||||
|
* `toMarkdownV2Texts`
|
||||||
|
* `toHtmlCaptions`
|
||||||
|
* `toHtmlTexts`
|
||||||
|
* `TelegramBotAPI-extensions-api`:
|
||||||
|
* All `RequestsExecutor#sendDice` extensions now accept `DiceAnimationType?` as second parameter
|
||||||
|
* All `RequestsExecutor#sendRegularPoll` extensions now accept `ScheduledCloseInfo` fourth parameter
|
||||||
|
* All `RequestsExecutor#sendQuizPoll` extensions now accept additional parameters `caption: String` and
|
||||||
|
`parseMode: ParseMode` for `explanation` functionality and `closeInfo: ScheduledCloseInfo?` for autoclose poll
|
||||||
|
functionality
|
||||||
|
* `TelegramBotAPI-extensions-utils`:
|
||||||
|
* Several shortcuts for `ScheduledCloseInfo` was added:
|
||||||
|
* `closePollExactAt`
|
||||||
|
* `closePollExactAfter`
|
||||||
|
* `closePollAfter`
|
||||||
|
|
||||||
|
### 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`:
|
||||||
|
* Interface `Explained` and subsinterfaces `ExplainedInput` and `ExplainedOutput` was added
|
||||||
|
* Class `QuizPoll` now implement `ExplainedInput`
|
||||||
|
* In `QuizPoll#caption` and `QuizPoll#captionEntities` are deprecated now
|
||||||
|
* Class `SendQuizPoll` now implement `ExplainedOutput`
|
||||||
|
* In `SendQuizPoll#caption` is deprecated now
|
||||||
|
* `explanationLimit` range was added as future replacement of `quizPollExplanationLimit`
|
||||||
|
* `quizPollExplanationLimit` now is deprecated
|
||||||
|
* Extensions `toMarkdownExplanations`, `toMarkdownV2Explanations` and `toHtmlExplanations` was added
|
||||||
|
* Typealias `FullTextSourcesList` was added
|
||||||
|
* All extensions `fullEntitiesList` now return `FullTextSourcesList`
|
||||||
|
* All extensions of `List<TextSource>` now are extensions for `FullTextSourcesList`
|
||||||
|
* `TelegramBotAPI-extensions-api`:
|
||||||
|
* `sendQuizPoll` now is using `explanation` parameter instead of `caption`
|
||||||
|
|
||||||
|
## 0.26.0
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* Versions updates:
|
||||||
|
* `Klock`: `1.10.0` -> `1.10.3`
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* Request `SendDice` was added (calling [sendDice](https://core.telegram.org/bots/api#senddice))
|
||||||
|
* Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice))
|
||||||
|
* Class `DiceContent` was added (for including it in [message](https://core.telegram.org/bots/api#message) object)
|
||||||
|
* `BotCommand` was added
|
||||||
|
* `GetMyCommands` request was added
|
||||||
|
* `SetMyCommands` request was added
|
||||||
|
* `GetMe` now is object instead of class
|
||||||
|
* `GetMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe`
|
||||||
|
* `CreateNewStickerSet` renamed to `CreateStaticNewStickerSet`
|
||||||
|
* `CreateNewAnimatedStickerSet` request was added (it handle work with `tgs_sticker`)
|
||||||
|
* `StickerSet#thumb` was added
|
||||||
|
* `AddStickerToSet` renamed to `AddStaticStickerToSet`
|
||||||
|
* `AddAnimatedStickerToSet` request was added
|
||||||
|
* `SetStickerSetThumb` request was added
|
||||||
|
* Most of sticker actions now implements `StandardStickerSetAction` instead of `StickerSetAction`
|
||||||
|
* `getUpdatesLimit` was added to be ensure in get updates limit
|
||||||
|
* `GetUpdates` now will check count of requesting updates and throw exception if it is not in range `1 .. 100`
|
||||||
|
* `GetUpdates#limit` now is not nullable and by default set up to 100
|
||||||
|
* `TelegramBotAPI-extensions-api`:
|
||||||
|
* Extensions `sendDice` was added
|
||||||
|
* Extension `getMyCommands` request was added
|
||||||
|
* Extension `setMyCommands` request was added
|
||||||
|
* Extension `getMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe`
|
||||||
|
* **All extensions `createNewStickerSet` was renamed to `createNewStaticStickerSet`**
|
||||||
|
* Extensions `createNewAnimatedStickerSet` was added
|
||||||
|
* **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`**
|
||||||
|
* Extensions `addAnimatedStickerToSet` was added
|
||||||
|
* Extensions `setStickerSetThumb` was added
|
||||||
|
* Extension `startGettingUpdates` now will drop `SentMediaGroupUpdate` in case if it is the last in updates group
|
||||||
|
and size of retrieved updates is equal to 100 (max count of retrieved updates)
|
||||||
|
* Extensions `getUpdates` now will receive only not nullable `limit` parameter
|
||||||
|
|
||||||
|
### 0.26.4
|
||||||
|
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* Now any getting of updates will return `UnknownUpdateType` when inside of deserialization will be
|
||||||
|
`SerializationException` or `NotImplemented` error
|
||||||
|
* `CallbackGame` currently is an object
|
||||||
|
* It is possible to use `CallbackGame` for now
|
||||||
|
* `CallbackGameInlineKeyboardButton` now will not accept `callbackGame` as income object
|
||||||
|
* Now it is possible to pass exception handler in webhook
|
||||||
|
|
||||||
|
### 0.26.3
|
||||||
|
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* `CallbackGameInlineKeyboardButton` was added
|
||||||
|
([Issue-79](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/79),
|
||||||
|
[PR-80](https://github.com/InsanusMokrassar/TelegramBotAPI/pull/80))
|
||||||
|
* `UnknownInlineKeyboardButton` was added. It is unavailable for creating, but you can receive it, for example, in
|
||||||
|
`InlineQueryResult`
|
||||||
|
* `Update` now will be created even if was `SerializationException` inside of creating the update instance - in this
|
||||||
|
case will be created `UnknownUpdateType`
|
||||||
|
* `UnknownUpdateType$rawJson` value now is included (`JsonElement`)
|
||||||
|
* **EXPERIMENTALLY** `BaseEditMessageUpdate#data` now is `CommonMessage<*>`
|
||||||
|
* Suspend inline function `handleSafely` was added
|
||||||
|
* `KtorRequestsExecutor` now use `handleSafely` instead of `try` with `supervisorScope`
|
||||||
|
* `UpdatesPolling` now use `handleSafely` instead of `try` with `supervisorScope`
|
||||||
|
|
||||||
|
### 0.26.2
|
||||||
|
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* Now `EditMediaGroupUpdate` also extends `BaseEditMessageUpdate`
|
||||||
|
* **EXPERIMENTALLY** Now all `TextSource` realisations will contain `source` field as a property inside of them
|
||||||
|
* `TelegramBotAPI-extensions-api`:
|
||||||
|
* `startGettingFlowsUpdates` extension which do not require filter (but return a new one) was added
|
||||||
|
* `TelegramBotAPI-extensions-utils`:
|
||||||
|
* Subproject was added
|
||||||
|
* `filterBaseMessageUpdates`, `filterSentMediaGroupUpdates` and `filterEditMediaGroupUpdates` extensions was added
|
||||||
|
* `filterCommandsWithArgs`, `filterExactCommands` and `filterCommandsInsideTextMessages` extensions was added
|
||||||
|
* `asContentMessagesFlow`, `asChatEventsFlow` and `asUnknownMessagesFlow` extensions was added
|
||||||
|
* `withContentType` extension was added
|
||||||
|
* `onlyAnimationContentMessages` extension was added
|
||||||
|
* `onlyAudioContentMessages` extension was added
|
||||||
|
* `onlyContactContentMessages` extension was added
|
||||||
|
* `onlyDiceContentMessages` extension was added
|
||||||
|
* `onlyDocumentContentMessages` extension was added
|
||||||
|
* `onlyGameContentMessages` extension was added
|
||||||
|
* `onlyInvoiceContentMessages` extension was added
|
||||||
|
* `onlyLocationContentMessages` extension was added
|
||||||
|
* `onlyPhotoContentMessages` extension was added
|
||||||
|
* `onlyPollContentMessages` extension was added
|
||||||
|
* `onlyStickerContentMessages` extension was added
|
||||||
|
* `onlyTextContentMessages` extension was added
|
||||||
|
* `onlyVenueContentMessages` extension was added
|
||||||
|
* `onlyVideoContentMessages` extension was added
|
||||||
|
* `onlyVideoNoteContentMessages` extension was added
|
||||||
|
* `onlyVoiceContentMessages` extension was added
|
||||||
|
|
||||||
|
### 0.26.1
|
||||||
|
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* `BotCommand` now will check and throw error in case when command or description lengths is/are incorrect
|
||||||
|
* `StorageFile` now is common for all platforms
|
||||||
|
* JavaScript realization was removed due to its redundancy
|
||||||
|
* JVM realization was replaced with `fun` factory
|
||||||
|
* `StorageFile` now able to accept any factory of `Input`
|
||||||
|
* `StorageFileInfo` was added to avoid strange collisions with throws in `StorageFile`
|
||||||
|
* Fixes issue with `hashTag` for markdown
|
||||||
|
* `InvalidPhotoDimensionsException` was added for cases when `PHOTO_INVALID_DIMENSION` answer received
|
||||||
|
* Other fixes
|
||||||
|
|
||||||
|
## 0.25.0
|
||||||
|
|
||||||
|
* Common:
|
||||||
|
* Versions updates:
|
||||||
|
* `Kotlin`: `1.3.61` -> `1.3.70`
|
||||||
|
* `Kotlin coroutines`: `1.3.3` -> `1.3.5`
|
||||||
|
* `Kotlin serialization`: `0.14.0` -> `0.20.0`
|
||||||
|
* `Ktor`: `1.3.1` -> `1.3.2`
|
||||||
|
* `Klock`: `1.8.7` -> `1.10.0`
|
||||||
|
* `UUID`: `0.0.7` -> `0.1.0`
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* `Bot` implementations (as and `Bot` itself) now have not nullable `username`
|
||||||
|
* `File#toInputFile` extension now will throw error when file does not exists
|
||||||
|
* `InlineKeyboardMarkup` will check that `PayInlineKeyboardButton` is the first in case if it is exists in
|
||||||
|
`keyboard`
|
||||||
|
* `makeLinkToMessage` now is not `PreviewFeature`
|
||||||
|
* All deprecations was removed
|
||||||
|
* `RequestException` now extends `io.ktor.utils.io.errors.IOException` instead of `kotlinx.io.IOException`
|
||||||
|
* `Any#toJson` now is NOT `inline`
|
||||||
|
* `FlowsUpdatesFilter` now as marked my annotation `FlowPreview`
|
||||||
|
* `PathedFile#fullUrl` now is not `inline` function
|
||||||
|
* `SimpleRequest#json` now is not `inline` and `internal` function
|
||||||
|
* `FlowsUpdatesFilter` now have two additional flows: `pollAnswerFlow`, `unknownUpdateTypeFlow`
|
||||||
|
* `ExtendedUser` (`typealias`) was added as a `PreviewFeature`
|
||||||
|
|
||||||
|
### 0.25.1
|
||||||
|
|
||||||
|
* Update kotlin: `1.3.70` -> `1.3.71`
|
||||||
|
* Fix of error inside of update utils for media groups
|
||||||
|
|
||||||
## 0.24.0
|
## 0.24.0
|
||||||
|
|
||||||
* `TelegramBotAPI`:
|
* `TelegramBotAPI`:
|
||||||
|
|||||||
119
README.md
119
README.md
@@ -1,27 +1,126 @@
|
|||||||
# TelegramBotAPI
|
# 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://teleg.one/InMoTelegramBotAPI) [](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI) |
|
||||||
| -----------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
| TelegramBotAPI status | [](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI) |
|
| TelegramBotAPI status | [](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_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 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) |
|
||||||
|
|
||||||
It is a complex of libraries for working with `TelegramBotAPI` in type-safe and strict way as much as it possible. In
|
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:
|
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](TelegramBotAPI/README.md) - core of library. In fact it is independent library and can be used alone
|
||||||
without any additional library
|
without any additional library
|
||||||
* [TelegramBotAPI Extensions](TelegramBotAPI-extensions-api/README.md) - contains extensions (mostly for
|
* [TelegramBotAPI Extensions](TelegramBotAPI-extensions-api/README.md) - contains extensions (mostly for
|
||||||
`RequestsExecutor`), which allows to use the core library in more pleasant way
|
`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 All](TelegramBotAPI-all/README.md) - concentration of all previously mentioned libraries
|
||||||
|
|
||||||
Most part of some specific solves or unuseful
|
Most part of some specific solves or unuseful
|
||||||
moments are describing by official [Telegram Bot API](https://core.telegram.org/bots/api).
|
moments are describing by official [Telegram Bot API](https://core.telegram.org/bots/api).
|
||||||
|
|
||||||
|
## JavaScript notes
|
||||||
|
|
||||||
|
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>
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
dependencies {
|
||||||
|
/* ... */
|
||||||
|
|
||||||
|
implementation "com.github.insanusmokrassar:TelegramBotAPI:$tgbot_api_version"
|
||||||
|
implementation "com.github.insanusmokrassar:TelegramBotAPI-extensions-api:$tgbot_api_version" // optional
|
||||||
|
implementation "com.github.insanusmokrassar:TelegramBotAPI-extensions-utils:$tgbot_api_version" // optional
|
||||||
|
|
||||||
|
/* Block of dependencies for correct building in browser */
|
||||||
|
implementation(npm("fs"))
|
||||||
|
implementation(npm("bufferutil"))
|
||||||
|
implementation(npm("utf-8-validate"))
|
||||||
|
implementation(npm("abort-controller"))
|
||||||
|
implementation(npm("text-encoding"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ... */
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
target {
|
||||||
|
browser {
|
||||||
|
/* Block for fix of exception in absence of some functionality, https://github.com/ktorio/ktor/issues/1339 */
|
||||||
|
dceTask {
|
||||||
|
dceOptions {
|
||||||
|
keep("ktor-ktor-io.\$\$importsForInline\$\$.ktor-ktor-io.io.ktor.utils.io")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## Ok, where should I start?
|
## Ok, where should I start?
|
||||||
|
|
||||||
Firstly, look at the [TelegramBotAPI](TelegramBotAPI/README.md). Here you can find all information about currently
|
In most cases, the most simple way will be to implement [TelegramBotAPI All](TelegramBotAPI-all/README.md) - it contains
|
||||||
covered Telegram Bot API and other things. After this you can look at the
|
all necessary tools for comfort usage of this library. If you want to exclude some libraries, you can implement just
|
||||||
[TelegramBotAPI Extensions](TelegramBotAPI-extensions-api/README.md).
|
[TelegramBotAPI API Extensions](TelegramBotAPI-extensions-api/README.md),
|
||||||
|
[TelegramBotAPI Util Extensions](TelegramBotAPI-extensions-utils/README.md) or even
|
||||||
|
[TelegramBotAPI](TelegramBotAPI/README.md).
|
||||||
|
|
||||||
Anyway, all libraries are very typical inside of them. For example, any request in TelegramBotAPI look like
|
If you want to dive deeper in the core of library or develop something for it - welcome to learn more from
|
||||||
`requestsExecutor.execute(SomeRequest())`.
|
[TelegramBotAPI](TelegramBotAPI/README.md) and our [Telegram Chat](https://teleg.one/InMoTelegramBotAPIChat).
|
||||||
|
|
||||||
|
Anyway, all libraries are very typical inside of them. Examples:
|
||||||
|
|
||||||
|
* In `TelegramBotAPI` common request look like `requestsExecutor.execute(SomeRequest())`
|
||||||
|
* `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).
|
||||||
|
|||||||
16
TelegramBotAPI-all/README.md
Normal file
16
TelegramBotAPI-all/README.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# TelegramBotAPI-all
|
||||||
|
|
||||||
|
Concentration of all TelegramBotAPI libraries:
|
||||||
|
|
||||||
|
* [TelegramBotAPI](../TelegramBotAPI/README.md)
|
||||||
|
* [TelegramBotAPI Extensions](../TelegramBotAPI-extensions-api/README.md)
|
||||||
|
* [TelegramBotAPI Util Extensions](../TelegramBotAPI-extensions-utils/README.md)
|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
dependencies {
|
||||||
|
// ...
|
||||||
|
implementation "com.github.insanusmokrassar:TelegramBotAPI-all:tgBotAPIVersion"
|
||||||
|
}
|
||||||
|
```
|
||||||
52
TelegramBotAPI-all/build.gradle
Normal file
52
TelegramBotAPI-all/build.gradle
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
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" version "$kotlin_version"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
|
||||||
|
api "${project.group}:TelegramBotAPI:$library_version"
|
||||||
|
api "${project.group}:TelegramBotAPI-extensions-api:$library_version"
|
||||||
|
api "${project.group}:TelegramBotAPI-extensions-utils:$library_version"
|
||||||
|
} else {
|
||||||
|
api project(":TelegramBotAPI")
|
||||||
|
api project(":TelegramBotAPI-extensions-api")
|
||||||
|
api project(":TelegramBotAPI-extensions-utils")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
57
TelegramBotAPI-all/maven.publish.gradle
Normal file
57
TelegramBotAPI-all/maven.publish.gradle
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
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.withXml {
|
||||||
|
asNode().children().last() + {
|
||||||
|
resolveStrategy = Closure.DELEGATE_FIRST
|
||||||
|
|
||||||
|
description "This project just include all subproject of TelegramBotAPI"
|
||||||
|
name "Telegram Bot API All"
|
||||||
|
url "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-all"
|
||||||
|
|
||||||
|
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-all/mpp_publish_template.json
Normal file
1
TelegramBotAPI-all/mpp_publish_template.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"bintrayConfig":{"repo":"StandardRepository","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI"},"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 All","description":"This project just include all subproject of TelegramBotAPI","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-all","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"}
|
||||||
55
TelegramBotAPI-all/publish.gradle
Normal file
55
TelegramBotAPI-all/publish.gradle
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
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(".", "/")
|
||||||
|
}
|
||||||
|
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
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
# TelegramBotAPI extensions
|
# TelegramBotAPI extensions
|
||||||
|
|
||||||
[](https://github.com/KotlinBy/awesome-kotlin)
|
|
||||||
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-api/_latestVersion)
|
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-api/_latestVersion)
|
||||||
[](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-api)
|
[](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-api)
|
||||||
[](https://jenkins.insanusmokrassar.com/job/TelegramBotAPI-extensions-api_master__publishing/)
|
|
||||||
|
|
||||||
## What is it?
|
## What is it?
|
||||||
|
|
||||||
@@ -56,20 +54,76 @@ compile "com.github.insanusmokrassar:TelegramBotAPI-extensions-api:$telegrambota
|
|||||||
|
|
||||||
## Example of usage and comparison with `TelegramBotAPI`
|
## Example of usage and comparison with `TelegramBotAPI`
|
||||||
|
|
||||||
As said in [TelegramBotAPI](../TelegramBotAPI/README.md#Requests), it is possible to use next syntax for requests:
|
Here presented review table for comparison of api from original [TelegramBotAPI](../TelegramBotAPI/README.md#Requests)
|
||||||
|
and extensions-api library. First of all, this library allow to create bot instance in a new way:
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
val requestsExecutor: RequestsExecutor = ...
|
val bot = telegramBot("IT IS YOUR TOKEN")
|
||||||
requestsExecutor.execute(GetMe())
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This library offer a little bit another way for this:
|
There are a lot of signature for this. For example, you can create bot with next code:
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
val bot: RequestsExecutor = ...
|
val bot = telegramBot("IT IS YOUR TOKEN") {
|
||||||
bot.getMe()
|
proxy = ProxyBuilder.socks("127.0.0.1", 1080)
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The result type of [GetMe (and getMe extension)](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt)
|
In all examples supposed that you have created bot.
|
||||||
request is
|
|
||||||
[ExtendedBot](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt).
|
| TelegramBotAPI | TelegramBotAPI-extensions-api |
|
||||||
|
|----------------|-------------------------------|
|
||||||
|
| bot.execute(GetMe) | bot.getMe() |
|
||||||
|
| bot.execute(SendTextMessage(someChatId, text)) | bot.sendTextMessage(chat, text) |
|
||||||
|
|
||||||
|
## Updates
|
||||||
|
|
||||||
|
**Currently, these paragraphs almost outdated due to the fact that extensions for listening of updates and webhooks were
|
||||||
|
replaced into `TelegramBotAPI-extensions-utils`. But, most part of information below is correct with small fixes and
|
||||||
|
adding of `TelegramBotAPI-extensions-utils` dependency.**
|
||||||
|
|
||||||
|
Usually, it is more comfortable to use filter object to get separated types of updates:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val filter = FlowsUpdatesFilter(100)
|
||||||
|
```
|
||||||
|
|
||||||
|
In this case you will be able:
|
||||||
|
|
||||||
|
* Separate types of incoming updates (even media groups)
|
||||||
|
* Simplify launch of getting updates:
|
||||||
|
```kotlin
|
||||||
|
bot.startGettingOfUpdates(
|
||||||
|
filter,
|
||||||
|
scope = CoroutineScope(Dispatchers.Default)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
* Use `filter` flows to comfortable filter, map and do other operations with the whole
|
||||||
|
getting updates process:
|
||||||
|
```kotlin
|
||||||
|
filter.messageFlow.mapNotNull {
|
||||||
|
it.data as? ContentMessage<*>
|
||||||
|
}.onEach {
|
||||||
|
println(it)
|
||||||
|
}.launchIn(
|
||||||
|
CoroutineScope(Dispatchers.Default)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Alternative way
|
||||||
|
|
||||||
|
There is an alternative way to get updates. In fact it is almost the same, but could be more useful for some cases:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val filter = bot.startGettingOfUpdates(
|
||||||
|
scope = CoroutineScope(Dispatchers.Default)
|
||||||
|
) { // Here as reveiver will be FlowsUpdatesFilter
|
||||||
|
messageFlow.mapNotNull {
|
||||||
|
it.data as? ContentMessage<*>
|
||||||
|
}.onEach {
|
||||||
|
println(it)
|
||||||
|
}.launchIn(
|
||||||
|
CoroutineScope(Dispatchers.Default)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ kotlin {
|
|||||||
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
|
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
|
||||||
api "${project.group}:TelegramBotAPI:$library_version"
|
api "${project.group}:TelegramBotAPI:$library_version"
|
||||||
} else {
|
} else {
|
||||||
implementation project(":TelegramBotAPI")
|
api project(":TelegramBotAPI")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ publishing {
|
|||||||
|
|
||||||
description "API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference"
|
description "API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference"
|
||||||
name "Telegram Bot API Extensions for API"
|
name "Telegram Bot API Extensions for API"
|
||||||
url "https://insanusmokrassar.github.io/TelegramBotAPI"
|
url "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api"
|
||||||
|
|
||||||
scm {
|
scm {
|
||||||
developerConnection "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
|
developerConnection "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"bintrayConfig":{"repo":"StandardRepository","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI"},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Extensions for API","description":"API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference","url":"https://insanusmokrassar.github.io/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"}
|
{"bintrayConfig":{"repo":"StandardRepository","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI"},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Extensions for API","description":"API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.client.HttpClientConfig
|
||||||
|
import io.ktor.client.engine.HttpClientEngine
|
||||||
|
import io.ktor.client.engine.ProxyConfig
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param proxy Standard ktor [ProxyConfig]
|
||||||
|
* @param ktorClientEngine Engine like [io.ktor.client.engine.cio.CIO]
|
||||||
|
* @param ktorClientConfig Config block for preconfiguring of bot [HttpClient]
|
||||||
|
*/
|
||||||
|
data class BotBuilder internal constructor(
|
||||||
|
var proxy: ProxyConfig? = null,
|
||||||
|
var ktorClientEngine: HttpClientEngine? = null,
|
||||||
|
var ktorClientConfig: (HttpClientConfig<*>.() -> Unit) ? = null
|
||||||
|
) {
|
||||||
|
internal fun createHttpClient(): HttpClient = ktorClientEngine ?.let { engine ->
|
||||||
|
HttpClient(engine) {
|
||||||
|
ktorClientConfig ?.let { it() }
|
||||||
|
engine {
|
||||||
|
proxy = this@BotBuilder.proxy ?: proxy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ?: HttpClient {
|
||||||
|
ktorClientConfig ?.let { it() }
|
||||||
|
engine {
|
||||||
|
proxy = this@BotBuilder.proxy ?: proxy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Created by [telegramBotWithCustomClientConfig] function [RequestsExecutor]. This executor will be preconfigured using [token] and
|
||||||
|
* [block]
|
||||||
|
*/
|
||||||
|
fun telegramBot(
|
||||||
|
token: String,
|
||||||
|
block: BotBuilder.() -> Unit
|
||||||
|
): RequestsExecutor = telegramBot(
|
||||||
|
TelegramAPIUrlsKeeper(token),
|
||||||
|
BotBuilder().apply(block).createHttpClient()
|
||||||
|
)
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorRequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.client.HttpClientConfig
|
||||||
|
import io.ktor.client.engine.HttpClientEngine
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to create bot using bot [urlsKeeper] and already prepared [client]
|
||||||
|
*/
|
||||||
|
fun telegramBot(
|
||||||
|
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
|
client: HttpClient
|
||||||
|
): RequestsExecutor = KtorRequestsExecutor(
|
||||||
|
urlsKeeper,
|
||||||
|
client
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by passing [clientEngine] param and optionally
|
||||||
|
* configure [HttpClient] using [clientConfig]
|
||||||
|
*/
|
||||||
|
fun telegramBotWithCustomClientConfig(
|
||||||
|
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
|
clientEngine: HttpClientEngine,
|
||||||
|
clientConfig: HttpClientConfig<*>.() -> Unit = {}
|
||||||
|
): RequestsExecutor = telegramBot(
|
||||||
|
urlsKeeper,
|
||||||
|
HttpClient(clientEngine, clientConfig)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to create bot using bot [urlsKeeper] and optionally configure [HttpClient] using [clientConfig]
|
||||||
|
*/
|
||||||
|
fun telegramBotWithCustomClientConfig(
|
||||||
|
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
|
clientConfig: HttpClientConfig<*>.() -> Unit = {}
|
||||||
|
): RequestsExecutor = telegramBot(
|
||||||
|
urlsKeeper,
|
||||||
|
HttpClient(clientConfig)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to create bot using bot [token]
|
||||||
|
*/
|
||||||
|
fun telegramBot(
|
||||||
|
token: String
|
||||||
|
): RequestsExecutor = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to create bot using bot [token] and already prepared [client]
|
||||||
|
*/
|
||||||
|
fun telegramBot(
|
||||||
|
token: String,
|
||||||
|
client: HttpClient
|
||||||
|
): RequestsExecutor = telegramBot(TelegramAPIUrlsKeeper(token), client)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to create bot using bot [token] and configure [HttpClient] using [clientConfig]
|
||||||
|
*/
|
||||||
|
fun telegramBotWithCustomClientConfig(
|
||||||
|
token: String,
|
||||||
|
clientConfig: HttpClientConfig<*>.() -> Unit
|
||||||
|
): RequestsExecutor = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token), clientConfig)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally
|
||||||
|
* configure [HttpClient] using [clientConfig]
|
||||||
|
*/
|
||||||
|
fun telegramBot(
|
||||||
|
token: String,
|
||||||
|
clientEngine: HttpClientEngine,
|
||||||
|
clientConfig: HttpClientConfig<*>.() -> Unit = {}
|
||||||
|
): RequestsExecutor = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token), clientEngine, clientConfig)
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.GetMe
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.getMe
|
||||||
|
|
||||||
suspend fun RequestsExecutor.getMe() = execute(GetMe())
|
@Deprecated(
|
||||||
|
"Replaced",
|
||||||
|
ReplaceWith("getMe", "com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe")
|
||||||
|
)
|
||||||
|
suspend fun RequestsExecutor.getMe() = getMe()
|
||||||
@@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
|||||||
|
|
||||||
suspend fun RequestsExecutor.getUpdates(
|
suspend fun RequestsExecutor.getUpdates(
|
||||||
offset: UpdateIdentifier? = null,
|
offset: UpdateIdentifier? = null,
|
||||||
limit: Int? = null,
|
limit: Int = getUpdatesLimit.last,
|
||||||
timeout: Seconds? = null,
|
timeout: Seconds? = null,
|
||||||
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||||
) = execute(
|
) = execute(
|
||||||
@@ -18,7 +18,7 @@ suspend fun RequestsExecutor.getUpdates(
|
|||||||
|
|
||||||
suspend fun RequestsExecutor.getUpdates(
|
suspend fun RequestsExecutor.getUpdates(
|
||||||
lastUpdate: Update,
|
lastUpdate: Update,
|
||||||
limit: Int? = null,
|
limit: Int = getUpdatesLimit.last,
|
||||||
timeout: Seconds? = null,
|
timeout: Seconds? = null,
|
||||||
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||||
) = getUpdates(
|
) = getUpdates(
|
||||||
|
|||||||
@@ -23,19 +23,19 @@ internal fun List<Update>.convertWithMediaGroupUpdates(): List<Update> {
|
|||||||
val resultUpdates = mutableListOf<Update>()
|
val resultUpdates = mutableListOf<Update>()
|
||||||
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<BaseSentMessageUpdate>>()
|
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<BaseSentMessageUpdate>>()
|
||||||
for (update in this) {
|
for (update in this) {
|
||||||
|
val data = (update.data as? MediaGroupMessage)
|
||||||
|
if (data == null) {
|
||||||
|
resultUpdates.add(update)
|
||||||
|
continue
|
||||||
|
}
|
||||||
when (update) {
|
when (update) {
|
||||||
is BaseEditMessageUpdate -> resultUpdates.add(
|
is BaseEditMessageUpdate -> resultUpdates.add(
|
||||||
update.toEditMediaGroupUpdate()
|
update.toEditMediaGroupUpdate()
|
||||||
)
|
)
|
||||||
is BaseSentMessageUpdate -> {
|
is BaseSentMessageUpdate -> {
|
||||||
val data = update.data
|
|
||||||
if (data is MediaGroupMessage) {
|
|
||||||
mediaGroups.getOrPut(data.mediaGroupId) {
|
mediaGroups.getOrPut(data.mediaGroupId) {
|
||||||
mutableListOf()
|
mutableListOf()
|
||||||
}.add(update)
|
}.add(update)
|
||||||
} else {
|
|
||||||
resultUpdates.add(update)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else -> resultUpdates.add(update)
|
else -> resultUpdates.add(update)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api
|
||||||
|
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
|
@Suppress("EXPERIMENTAL_API_USAGE")
|
||||||
|
internal val nonstrictJsonFormat = Json {
|
||||||
|
isLenient = true
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
serializeSpecialFloatingPointValues = true
|
||||||
|
useArrayPolymorphism = true
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.getMe() = execute(GetMe)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMyCommands
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.getMyCommands() = execute(GetMyCommands)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.SetMyCommands
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.BotCommand
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setMyCommands(
|
||||||
|
commands: List<BotCommand>
|
||||||
|
) = execute(SetMyCommands(commands))
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendDice
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.dice.DiceAnimationType
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.sendDice(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
animationType: DiceAnimationType? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = execute(
|
||||||
|
SendDice(chatId, animationType, disableNotification, replyToMessageId, replyMarkup)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.sendDice(
|
||||||
|
chat: Chat,
|
||||||
|
animationType: DiceAnimationType? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendDice(chat.id, animationType, disableNotification, replyToMessageId, replyMarkup)
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAnimation
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAnimation
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AnimationFile
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AnimationFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
|
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendAnimation(
|
suspend fun RequestsExecutor.sendAnimation(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAudio
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAudio
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AudioFile
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AudioFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
|
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendAudio(
|
suspend fun RequestsExecutor.sendAudio(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendDocument
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendDocument
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.DocumentFile
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.DocumentFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
|
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendDocument(
|
suspend fun RequestsExecutor.sendDocument(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendPhoto
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendPhoto
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.*
|
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendPhoto(
|
suspend fun RequestsExecutor.sendPhoto(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendSticker
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendSticker
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker
|
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendSticker(
|
suspend fun RequestsExecutor.sendSticker(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideo
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideo
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoFile
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoFile
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendVideo(
|
suspend fun RequestsExecutor.sendVideo(
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideoNote
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideoNote
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoFile
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoFile
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendVideoNote(
|
suspend fun RequestsExecutor.sendVideoNote(
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVoice
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVoice
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AudioFile
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AudioFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
|
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendVoice(
|
suspend fun RequestsExecutor.sendVoice(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.polls.SendQuizPo
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.polls.SendRegularPoll
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.polls.SendRegularPoll
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.QuizPoll
|
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.RegularPoll
|
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendRegularPoll(
|
suspend fun RequestsExecutor.sendRegularPoll(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
@@ -17,12 +17,13 @@ suspend fun RequestsExecutor.sendRegularPoll(
|
|||||||
isAnonymous: Boolean = true,
|
isAnonymous: Boolean = true,
|
||||||
isClosed: Boolean = false,
|
isClosed: Boolean = false,
|
||||||
allowMultipleAnswers: Boolean = false,
|
allowMultipleAnswers: Boolean = false,
|
||||||
|
closeInfo: ScheduledCloseInfo? = null,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = execute(
|
) = execute(
|
||||||
SendRegularPoll(
|
SendRegularPoll(
|
||||||
chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, disableNotification, replyToMessageId, replyMarkup
|
chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
suspend fun RequestsExecutor.sendRegularPoll(
|
suspend fun RequestsExecutor.sendRegularPoll(
|
||||||
@@ -33,12 +34,13 @@ suspend fun RequestsExecutor.sendRegularPoll(
|
|||||||
options: List<String> = poll.options.map { it.text },
|
options: List<String> = poll.options.map { it.text },
|
||||||
isAnonymous: Boolean = poll.isAnonymous,
|
isAnonymous: Boolean = poll.isAnonymous,
|
||||||
allowMultipleAnswers: Boolean = poll.allowMultipleAnswers,
|
allowMultipleAnswers: Boolean = poll.allowMultipleAnswers,
|
||||||
|
closeInfo: ScheduledCloseInfo? = null,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = execute(
|
) = execute(
|
||||||
SendRegularPoll(
|
SendRegularPoll(
|
||||||
chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, disableNotification, replyToMessageId, replyMarkup
|
chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,11 +51,12 @@ suspend fun RequestsExecutor.sendRegularPoll(
|
|||||||
isAnonymous: Boolean = true,
|
isAnonymous: Boolean = true,
|
||||||
isClosed: Boolean = false,
|
isClosed: Boolean = false,
|
||||||
allowMultipleAnswers: Boolean = false,
|
allowMultipleAnswers: Boolean = false,
|
||||||
|
closeInfo: ScheduledCloseInfo? = null,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendRegularPoll(
|
) = sendRegularPoll(
|
||||||
chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, disableNotification, replyToMessageId, replyMarkup
|
chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendRegularPoll(
|
suspend fun RequestsExecutor.sendRegularPoll(
|
||||||
@@ -64,11 +67,12 @@ suspend fun RequestsExecutor.sendRegularPoll(
|
|||||||
options: List<String> = poll.options.map { it.text },
|
options: List<String> = poll.options.map { it.text },
|
||||||
isAnonymous: Boolean = poll.isAnonymous,
|
isAnonymous: Boolean = poll.isAnonymous,
|
||||||
allowMultipleAnswers: Boolean = poll.allowMultipleAnswers,
|
allowMultipleAnswers: Boolean = poll.allowMultipleAnswers,
|
||||||
|
closeInfo: ScheduledCloseInfo? = null,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendRegularPoll(
|
) = sendRegularPoll(
|
||||||
chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, disableNotification, replyToMessageId, replyMarkup
|
chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -79,12 +83,15 @@ suspend fun RequestsExecutor.sendQuizPoll(
|
|||||||
correctOptionId: Int,
|
correctOptionId: Int,
|
||||||
isAnonymous: Boolean = true,
|
isAnonymous: Boolean = true,
|
||||||
isClosed: Boolean = false,
|
isClosed: Boolean = false,
|
||||||
|
explanation: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
closeInfo: ScheduledCloseInfo? = null,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = execute(
|
) = execute(
|
||||||
SendQuizPoll(
|
SendQuizPoll(
|
||||||
chatId, question, options, correctOptionId, isAnonymous, isClosed, disableNotification, replyToMessageId, replyMarkup
|
chatId, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -95,11 +102,14 @@ suspend fun RequestsExecutor.sendQuizPoll(
|
|||||||
correctOptionId: Int,
|
correctOptionId: Int,
|
||||||
isAnonymous: Boolean = true,
|
isAnonymous: Boolean = true,
|
||||||
isClosed: Boolean = false,
|
isClosed: Boolean = false,
|
||||||
|
explanation: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
closeInfo: ScheduledCloseInfo? = null,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendQuizPoll(
|
) = sendQuizPoll(
|
||||||
chat.id, question, options, correctOptionId, isAnonymous, isClosed, disableNotification, replyToMessageId, replyMarkup
|
chat.id, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.sendQuizPoll(
|
suspend fun RequestsExecutor.sendQuizPoll(
|
||||||
@@ -110,12 +120,15 @@ suspend fun RequestsExecutor.sendQuizPoll(
|
|||||||
options: List<String> = quizPoll.options.map { it.text },
|
options: List<String> = quizPoll.options.map { it.text },
|
||||||
correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"),
|
correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"),
|
||||||
isAnonymous: Boolean = quizPoll.isAnonymous,
|
isAnonymous: Boolean = quizPoll.isAnonymous,
|
||||||
|
explanation: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
closeInfo: ScheduledCloseInfo? = null,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = execute(
|
) = execute(
|
||||||
SendQuizPoll(
|
SendQuizPoll(
|
||||||
chatId, question, options, correctOptionId, isAnonymous, isClosed, disableNotification, replyToMessageId, replyMarkup
|
chatId, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -127,9 +140,12 @@ suspend fun RequestsExecutor.sendQuizPoll(
|
|||||||
options: List<String> = quizPoll.options.map { it.text },
|
options: List<String> = quizPoll.options.map { it.text },
|
||||||
correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"),
|
correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"),
|
||||||
isAnonymous: Boolean = quizPoll.isAnonymous,
|
isAnonymous: Boolean = quizPoll.isAnonymous,
|
||||||
|
explanation: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
closeInfo: ScheduledCloseInfo? = null,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendQuizPoll(
|
) = sendQuizPoll(
|
||||||
chat.id, question, options, correctOptionId, isAnonymous, isClosed, disableNotification, replyToMessageId, replyMarkup
|
chat.id, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddAnimatedStickerToSet
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.addAnimatedStickerToSet(
|
||||||
|
userId: UserId,
|
||||||
|
stickerSetName: String,
|
||||||
|
sticker: FileId,
|
||||||
|
emojis: String,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = execute(
|
||||||
|
AddAnimatedStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.addAnimatedStickerToSet(
|
||||||
|
userId: UserId,
|
||||||
|
stickerSetName: String,
|
||||||
|
sticker: MultipartFile,
|
||||||
|
emojis: String,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = execute(
|
||||||
|
AddAnimatedStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.addAnimatedStickerToSet(
|
||||||
|
user: CommonUser,
|
||||||
|
stickerSetName: String,
|
||||||
|
sticker: FileId,
|
||||||
|
emojis: String,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = addAnimatedStickerToSet(
|
||||||
|
user.id, stickerSetName, sticker, emojis, maskPosition
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.addAnimatedStickerToSet(
|
||||||
|
user: CommonUser,
|
||||||
|
stickerSetName: String,
|
||||||
|
sticker: MultipartFile,
|
||||||
|
emojis: String,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = addAnimatedStickerToSet(
|
||||||
|
user.id, stickerSetName, sticker, emojis, maskPosition
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.addAnimatedStickerToSet(
|
||||||
|
userId: UserId,
|
||||||
|
stickerSet: StickerSet,
|
||||||
|
sticker: FileId,
|
||||||
|
emojis: String,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = addAnimatedStickerToSet(
|
||||||
|
userId, stickerSet.name, sticker, emojis, maskPosition
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.addAnimatedStickerToSet(
|
||||||
|
userId: UserId,
|
||||||
|
stickerSet: StickerSet,
|
||||||
|
sticker: MultipartFile,
|
||||||
|
emojis: String,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = addAnimatedStickerToSet(
|
||||||
|
userId, stickerSet.name, sticker, emojis, maskPosition
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.addAnimatedStickerToSet(
|
||||||
|
user: CommonUser,
|
||||||
|
stickerSet: StickerSet,
|
||||||
|
sticker: FileId,
|
||||||
|
emojis: String,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = addAnimatedStickerToSet(
|
||||||
|
user.id, stickerSet.name, sticker, emojis, maskPosition
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.addAnimatedStickerToSet(
|
||||||
|
user: CommonUser,
|
||||||
|
stickerSet: StickerSet,
|
||||||
|
sticker: MultipartFile,
|
||||||
|
emojis: String,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = addAnimatedStickerToSet(
|
||||||
|
user.id, stickerSet.name, sticker, emojis, maskPosition
|
||||||
|
)
|
||||||
@@ -3,88 +3,88 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStickerToSet
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser
|
import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet
|
||||||
|
|
||||||
suspend fun RequestsExecutor.addStickerToSet(
|
suspend fun RequestsExecutor.addStaticStickerToSet(
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
stickerSetName: String,
|
stickerSetName: String,
|
||||||
sticker: FileId,
|
sticker: FileId,
|
||||||
emojis: String,
|
emojis: String,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = execute(
|
) = execute(
|
||||||
AddStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
|
AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.addStickerToSet(
|
suspend fun RequestsExecutor.addStaticStickerToSet(
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
stickerSetName: String,
|
stickerSetName: String,
|
||||||
sticker: MultipartFile,
|
sticker: MultipartFile,
|
||||||
emojis: String,
|
emojis: String,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = execute(
|
) = execute(
|
||||||
AddStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
|
AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.addStickerToSet(
|
suspend fun RequestsExecutor.addStaticStickerToSet(
|
||||||
user: CommonUser,
|
user: CommonUser,
|
||||||
stickerSetName: String,
|
stickerSetName: String,
|
||||||
sticker: FileId,
|
sticker: FileId,
|
||||||
emojis: String,
|
emojis: String,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = addStickerToSet(
|
) = addStaticStickerToSet(
|
||||||
user.id, stickerSetName, sticker, emojis, maskPosition
|
user.id, stickerSetName, sticker, emojis, maskPosition
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.addStickerToSet(
|
suspend fun RequestsExecutor.addStaticStickerToSet(
|
||||||
user: CommonUser,
|
user: CommonUser,
|
||||||
stickerSetName: String,
|
stickerSetName: String,
|
||||||
sticker: MultipartFile,
|
sticker: MultipartFile,
|
||||||
emojis: String,
|
emojis: String,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = addStickerToSet(
|
) = addStaticStickerToSet(
|
||||||
user.id, stickerSetName, sticker, emojis, maskPosition
|
user.id, stickerSetName, sticker, emojis, maskPosition
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.addStickerToSet(
|
suspend fun RequestsExecutor.addStaticStickerToSet(
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
stickerSet: StickerSet,
|
stickerSet: StickerSet,
|
||||||
sticker: FileId,
|
sticker: FileId,
|
||||||
emojis: String,
|
emojis: String,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = addStickerToSet(
|
) = addStaticStickerToSet(
|
||||||
userId, stickerSet.name, sticker, emojis, maskPosition
|
userId, stickerSet.name, sticker, emojis, maskPosition
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.addStickerToSet(
|
suspend fun RequestsExecutor.addStaticStickerToSet(
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
stickerSet: StickerSet,
|
stickerSet: StickerSet,
|
||||||
sticker: MultipartFile,
|
sticker: MultipartFile,
|
||||||
emojis: String,
|
emojis: String,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = addStickerToSet(
|
) = addStaticStickerToSet(
|
||||||
userId, stickerSet.name, sticker, emojis, maskPosition
|
userId, stickerSet.name, sticker, emojis, maskPosition
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.addStickerToSet(
|
suspend fun RequestsExecutor.addStaticStickerToSet(
|
||||||
user: CommonUser,
|
user: CommonUser,
|
||||||
stickerSet: StickerSet,
|
stickerSet: StickerSet,
|
||||||
sticker: FileId,
|
sticker: FileId,
|
||||||
emojis: String,
|
emojis: String,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = addStickerToSet(
|
) = addStaticStickerToSet(
|
||||||
user.id, stickerSet.name, sticker, emojis, maskPosition
|
user.id, stickerSet.name, sticker, emojis, maskPosition
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.addStickerToSet(
|
suspend fun RequestsExecutor.addStaticStickerToSet(
|
||||||
user: CommonUser,
|
user: CommonUser,
|
||||||
stickerSet: StickerSet,
|
stickerSet: StickerSet,
|
||||||
sticker: MultipartFile,
|
sticker: MultipartFile,
|
||||||
emojis: String,
|
emojis: String,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = addStickerToSet(
|
) = addStaticStickerToSet(
|
||||||
user.id, stickerSet.name, sticker, emojis, maskPosition
|
user.id, stickerSet.name, sticker, emojis, maskPosition
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewAnimatedStickerSet
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.createNewAnimatedStickerSet(
|
||||||
|
userId: UserId,
|
||||||
|
name: String,
|
||||||
|
sticker: FileId,
|
||||||
|
emojis: String,
|
||||||
|
containsMasks: Boolean? = null,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = execute(
|
||||||
|
CreateNewAnimatedStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.createNewAnimatedStickerSet(
|
||||||
|
userId: UserId,
|
||||||
|
name: String,
|
||||||
|
sticker: MultipartFile,
|
||||||
|
emojis: String,
|
||||||
|
containsMasks: Boolean? = null,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = execute(
|
||||||
|
CreateNewAnimatedStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.createNewAnimatedStickerSet(
|
||||||
|
user: CommonUser,
|
||||||
|
name: String,
|
||||||
|
sticker: FileId,
|
||||||
|
emojis: String,
|
||||||
|
containsMasks: Boolean? = null,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = createNewAnimatedStickerSet(
|
||||||
|
user.id, name, sticker, emojis, containsMasks, maskPosition
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.createNewAnimatedStickerSet(
|
||||||
|
user: CommonUser,
|
||||||
|
name: String,
|
||||||
|
sticker: MultipartFile,
|
||||||
|
emojis: String,
|
||||||
|
containsMasks: Boolean? = null,
|
||||||
|
maskPosition: MaskPosition? = null
|
||||||
|
) = createNewAnimatedStickerSet(
|
||||||
|
user.id, name, sticker, emojis, containsMasks, maskPosition
|
||||||
|
)
|
||||||
@@ -3,12 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewStickerSet
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewStaticStickerSet
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser
|
import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
||||||
|
|
||||||
suspend fun RequestsExecutor.createNewStickerSet(
|
suspend fun RequestsExecutor.createNewStaticStickerSet(
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
name: String,
|
name: String,
|
||||||
sticker: FileId,
|
sticker: FileId,
|
||||||
@@ -16,10 +16,10 @@ suspend fun RequestsExecutor.createNewStickerSet(
|
|||||||
containsMasks: Boolean? = null,
|
containsMasks: Boolean? = null,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = execute(
|
) = execute(
|
||||||
CreateNewStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition)
|
CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition)
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.createNewStickerSet(
|
suspend fun RequestsExecutor.createNewStaticStickerSet(
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
name: String,
|
name: String,
|
||||||
sticker: MultipartFile,
|
sticker: MultipartFile,
|
||||||
@@ -27,28 +27,28 @@ suspend fun RequestsExecutor.createNewStickerSet(
|
|||||||
containsMasks: Boolean? = null,
|
containsMasks: Boolean? = null,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = execute(
|
) = execute(
|
||||||
CreateNewStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition)
|
CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
suspend fun RequestsExecutor.createNewStickerSet(
|
suspend fun RequestsExecutor.createNewStaticStickerSet(
|
||||||
user: CommonUser,
|
user: CommonUser,
|
||||||
name: String,
|
name: String,
|
||||||
sticker: FileId,
|
sticker: FileId,
|
||||||
emojis: String,
|
emojis: String,
|
||||||
containsMasks: Boolean? = null,
|
containsMasks: Boolean? = null,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = createNewStickerSet(
|
) = createNewStaticStickerSet(
|
||||||
user.id, name, sticker, emojis, containsMasks, maskPosition
|
user.id, name, sticker, emojis, containsMasks, maskPosition
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun RequestsExecutor.createNewStickerSet(
|
suspend fun RequestsExecutor.createNewStaticStickerSet(
|
||||||
user: CommonUser,
|
user: CommonUser,
|
||||||
name: String,
|
name: String,
|
||||||
sticker: MultipartFile,
|
sticker: MultipartFile,
|
||||||
emojis: String,
|
emojis: String,
|
||||||
containsMasks: Boolean? = null,
|
containsMasks: Boolean? = null,
|
||||||
maskPosition: MaskPosition? = null
|
maskPosition: MaskPosition? = null
|
||||||
) = createNewStickerSet(
|
) = createNewStaticStickerSet(
|
||||||
user.id, name, sticker, emojis, containsMasks, maskPosition
|
user.id, name, sticker, emojis, containsMasks, maskPosition
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.thumbs
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.SetStickerSetThumb
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
userId: UserId,
|
||||||
|
thumbSetName: String,
|
||||||
|
thumb: FileId
|
||||||
|
) = execute(
|
||||||
|
SetStickerSetThumb(userId, thumbSetName, thumb)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
userId: UserId,
|
||||||
|
thumbSetName: String,
|
||||||
|
thumb: MultipartFile
|
||||||
|
) = execute(
|
||||||
|
SetStickerSetThumb(userId, thumbSetName, thumb)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
user: CommonUser,
|
||||||
|
thumbSetName: String,
|
||||||
|
thumb: FileId
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
user.id, thumbSetName, thumb
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
user: CommonUser,
|
||||||
|
thumbSetName: String,
|
||||||
|
thumb: MultipartFile
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
user.id, thumbSetName, thumb
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
userId: UserId,
|
||||||
|
thumbSet: StickerSet,
|
||||||
|
thumb: FileId
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
userId, thumbSet.name, thumb
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
userId: UserId,
|
||||||
|
thumbSet: StickerSet,
|
||||||
|
thumb: MultipartFile
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
userId, thumbSet.name, thumb
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
user: CommonUser,
|
||||||
|
thumbSet: StickerSet,
|
||||||
|
thumb: FileId
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
user.id, thumbSet.name, thumb
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
user: CommonUser,
|
||||||
|
thumbSet: StickerSet,
|
||||||
|
thumb: MultipartFile
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
user.id, thumbSet.name, thumb
|
||||||
|
)
|
||||||
|
|
||||||
@@ -5,33 +5,53 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestExceptio
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.convertWithMediaGroupUpdates
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.convertWithMediaGroupUpdates
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.lastUpdateIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.lastUpdateIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.getUpdates
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.getUpdates
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Seconds
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.*
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.*
|
||||||
import io.ktor.client.features.HttpRequestTimeoutException
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils")
|
||||||
fun RequestsExecutor.startGettingOfUpdates(
|
fun RequestsExecutor.startGettingOfUpdates(
|
||||||
timeoutSeconds: Seconds = 30,
|
timeoutSeconds: Seconds = 30,
|
||||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||||
|
exceptionsHandler: (ExceptionHandler<Unit>)? = null,
|
||||||
allowedUpdates: List<String>? = null,
|
allowedUpdates: List<String>? = null,
|
||||||
updatesReceiver: UpdateReceiver<Update>
|
updatesReceiver: UpdateReceiver<Update>
|
||||||
): Job = scope.launch {
|
): Job = scope.launch {
|
||||||
var lastUpdateIdentifier: UpdateIdentifier? = null
|
var lastUpdateIdentifier: UpdateIdentifier? = null
|
||||||
|
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
try {
|
handleSafely(
|
||||||
supervisorScope {
|
{ e ->
|
||||||
|
exceptionsHandler ?.invoke(e)
|
||||||
|
if (e is RequestException) {
|
||||||
|
delay(1000L)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
val updates = getUpdates(
|
val updates = getUpdates(
|
||||||
offset = lastUpdateIdentifier?.plus(1),
|
offset = lastUpdateIdentifier?.plus(1),
|
||||||
timeout = timeoutSeconds,
|
timeout = timeoutSeconds,
|
||||||
allowed_updates = allowedUpdates
|
allowed_updates = allowedUpdates
|
||||||
).convertWithMediaGroupUpdates()
|
).let { originalUpdates ->
|
||||||
|
val converted = originalUpdates.convertWithMediaGroupUpdates()
|
||||||
|
/**
|
||||||
|
* Dirty hack for cases when the media group was retrieved not fully:
|
||||||
|
*
|
||||||
|
* We are throw out the last media group and will reretrieve it again in the next get updates
|
||||||
|
* and it will guarantee that it is full
|
||||||
|
*/
|
||||||
|
if (originalUpdates.size == getUpdatesLimit.last && converted.last() is SentMediaGroupUpdate) {
|
||||||
|
converted - converted.last()
|
||||||
|
} else {
|
||||||
|
converted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
supervisorScope {
|
handleSafely {
|
||||||
for (update in updates) {
|
for (update in updates) {
|
||||||
updatesReceiver(update)
|
updatesReceiver(update)
|
||||||
|
|
||||||
@@ -39,26 +59,45 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: HttpRequestTimeoutException) {
|
|
||||||
e // it is ok due to mechanism of long polling
|
|
||||||
} catch (e: RequestException) {
|
|
||||||
e // it is not ok, but in most cases it will mean that there is some limit for requests count
|
|
||||||
delay(1000L)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will create a new one [FlowsUpdatesFilter]. This method could be unsafe due to the fact that it will start
|
||||||
|
* getting updates IMMEDIATELY. That means that your bot will be able to skip some of them until you will call
|
||||||
|
* [kotlinx.coroutines.flow.Flow.collect] on one of [FlowsUpdatesFilter] flows. To avoid it, you can pass
|
||||||
|
* [flowUpdatesPreset] lambda - it will be called BEFORE starting updates getting
|
||||||
|
*/
|
||||||
|
@FlowPreview
|
||||||
|
@PreviewFeature
|
||||||
|
@Suppress("unused")
|
||||||
|
@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils")
|
||||||
|
fun RequestsExecutor.startGettingFlowsUpdates(
|
||||||
|
timeoutSeconds: Seconds = 30,
|
||||||
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||||
|
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||||
|
flowsUpdatesFilterUpdatesKeeperCount: Int = 64,
|
||||||
|
flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit = {}
|
||||||
|
): FlowsUpdatesFilter = FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply {
|
||||||
|
flowUpdatesPreset()
|
||||||
|
startGettingOfUpdates(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils")
|
||||||
fun RequestsExecutor.startGettingOfUpdates(
|
fun RequestsExecutor.startGettingOfUpdates(
|
||||||
updatesFilter: UpdatesFilter,
|
updatesFilter: UpdatesFilter,
|
||||||
timeoutSeconds: Seconds = 30,
|
timeoutSeconds: Seconds = 30,
|
||||||
|
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||||
): Job = startGettingOfUpdates(
|
): Job = startGettingOfUpdates(
|
||||||
timeoutSeconds,
|
timeoutSeconds,
|
||||||
scope,
|
scope,
|
||||||
|
exceptionsHandler,
|
||||||
updatesFilter.allowedUpdates,
|
updatesFilter.allowedUpdates,
|
||||||
updatesFilter.asUpdateReceiver
|
updatesFilter.asUpdateReceiver
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils")
|
||||||
fun RequestsExecutor.startGettingOfUpdates(
|
fun RequestsExecutor.startGettingOfUpdates(
|
||||||
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
||||||
messageMediaGroupCallback: UpdateReceiver<MessageMediaGroupUpdate>? = null,
|
messageMediaGroupCallback: UpdateReceiver<MessageMediaGroupUpdate>? = null,
|
||||||
@@ -76,6 +115,7 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
||||||
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||||
timeoutSeconds: Seconds = 30,
|
timeoutSeconds: Seconds = 30,
|
||||||
|
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||||
scope: CoroutineScope = GlobalScope
|
scope: CoroutineScope = GlobalScope
|
||||||
): Job {
|
): Job {
|
||||||
return startGettingOfUpdates(
|
return startGettingOfUpdates(
|
||||||
@@ -97,10 +137,13 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
pollAnswerCallback
|
pollAnswerCallback
|
||||||
),
|
),
|
||||||
timeoutSeconds,
|
timeoutSeconds,
|
||||||
|
exceptionsHandler,
|
||||||
scope
|
scope
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils")
|
||||||
fun RequestsExecutor.startGettingOfUpdates(
|
fun RequestsExecutor.startGettingOfUpdates(
|
||||||
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
||||||
mediaGroupCallback: UpdateReceiver<MediaGroupUpdate>? = null,
|
mediaGroupCallback: UpdateReceiver<MediaGroupUpdate>? = null,
|
||||||
@@ -115,6 +158,7 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
||||||
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||||
timeoutSeconds: Seconds = 30,
|
timeoutSeconds: Seconds = 30,
|
||||||
|
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||||
): Job = startGettingOfUpdates(
|
): Job = startGettingOfUpdates(
|
||||||
messageCallback = messageCallback,
|
messageCallback = messageCallback,
|
||||||
@@ -133,5 +177,6 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
pollCallback = pollCallback,
|
pollCallback = pollCallback,
|
||||||
pollAnswerCallback = pollAnswerCallback,
|
pollAnswerCallback = pollAnswerCallback,
|
||||||
timeoutSeconds = timeoutSeconds,
|
timeoutSeconds = timeoutSeconds,
|
||||||
|
exceptionsHandler = exceptionsHandler,
|
||||||
scope = scope
|
scope = scope
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.utils
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.convertWithMediaGroupUpdates
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdateReceiver
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.accumulateByKey
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.channels.Channel
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create [UpdateReceiver] object which will correctly accumulate updates and send into output updates which INCLUDE
|
||||||
|
* [com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.MediaGroupUpdate]s.
|
||||||
|
*
|
||||||
|
* @see UpdateReceiver
|
||||||
|
*/
|
||||||
|
fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation(
|
||||||
|
output: UpdateReceiver<Update>,
|
||||||
|
mediaGroupsDebounceMillis: Long = 1000L
|
||||||
|
): UpdateReceiver<Update> {
|
||||||
|
val updatesChannel = Channel<Update>(Channel.UNLIMITED)
|
||||||
|
val mediaGroupChannel = Channel<Pair<String, BaseMessageUpdate>>(Channel.UNLIMITED)
|
||||||
|
val mediaGroupAccumulatedChannel = mediaGroupChannel.accumulateByKey(
|
||||||
|
mediaGroupsDebounceMillis,
|
||||||
|
scope = this
|
||||||
|
)
|
||||||
|
|
||||||
|
launch {
|
||||||
|
launch {
|
||||||
|
for (update in updatesChannel) {
|
||||||
|
when (val data = update.data) {
|
||||||
|
is MediaGroupMessage -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
|
||||||
|
else -> output(update)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
launch {
|
||||||
|
for ((_, mediaGroup) in mediaGroupAccumulatedChannel) {
|
||||||
|
mediaGroup.convertWithMediaGroupUpdates().forEach {
|
||||||
|
output(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { updatesChannel.send(it) }
|
||||||
|
}
|
||||||
@@ -5,6 +5,22 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.webhook.SetWebhook
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.webhook.SetWebhook
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this method to send information about webhook (like [url])
|
||||||
|
*/
|
||||||
|
suspend fun RequestsExecutor.setWebhookInfo(
|
||||||
|
url: String,
|
||||||
|
maxAllowedConnections: Int? = null,
|
||||||
|
allowedUpdates: List<String>? = null
|
||||||
|
) = execute(
|
||||||
|
SetWebhook(
|
||||||
|
url, maxAllowedConnections, allowedUpdates
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this method to send information about webhook (like [url] and [certificate])
|
||||||
|
*/
|
||||||
suspend fun RequestsExecutor.setWebhookInfo(
|
suspend fun RequestsExecutor.setWebhookInfo(
|
||||||
url: String,
|
url: String,
|
||||||
certificate: FileId,
|
certificate: FileId,
|
||||||
@@ -16,6 +32,9 @@ suspend fun RequestsExecutor.setWebhookInfo(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this method to send information about webhook (like [url] and [certificate])
|
||||||
|
*/
|
||||||
suspend fun RequestsExecutor.setWebhookInfo(
|
suspend fun RequestsExecutor.setWebhookInfo(
|
||||||
url: String,
|
url: String,
|
||||||
certificate: MultipartFile,
|
certificate: MultipartFile,
|
||||||
263
TelegramBotAPI-extensions-utils/README.md
Normal file
263
TelegramBotAPI-extensions-utils/README.md
Normal file
@@ -0,0 +1,263 @@
|
|||||||
|
# TelegramBotAPI Util Extensions
|
||||||
|
|
||||||
|
- [TelegramBotAPI Util Extensions](#telegrambotapi-util--extensions)
|
||||||
|
* [What is it?](#what-is-it-)
|
||||||
|
* [How to implement library?](#how-to-implement-library-)
|
||||||
|
+ [Maven](#maven)
|
||||||
|
+ [Gradle](#gradle)
|
||||||
|
* [How to use?](#how-to-use-)
|
||||||
|
+ [Updates](#updates)
|
||||||
|
- [Long polling](#long-polling)
|
||||||
|
- [WebHooks (currently JVM-only)](#webhooks--currently-jvm-only-)
|
||||||
|
+ [Filters](#filters)
|
||||||
|
- [Sent messages](#sent-messages)
|
||||||
|
* [Common messages](#common-messages)
|
||||||
|
* [Chat actions](#chat-actions)
|
||||||
|
+ [Shortcuts](#shortcuts)
|
||||||
|
- [ScheduledCloseInfo](#scheduledcloseinfo)
|
||||||
|
|
||||||
|
<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
|
||||||
|
|
||||||
|
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-utils/_latestVersion)
|
||||||
|
[](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-utils)
|
||||||
|
|
||||||
|
## What is it?
|
||||||
|
|
||||||
|
It is wrapper library for [TelegramBotAPI](../TelegramBotAPI/README.md). Currently, this library contains some usefull filters for commands, updates types and different others.
|
||||||
|
|
||||||
|
## 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-extensions-utils_version`, which must be set up by developer. Available versions are presented on
|
||||||
|
[bintray](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-utils), next version is last published:
|
||||||
|
|
||||||
|
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-utils/_latestVersion)
|
||||||
|
|
||||||
|
### Maven
|
||||||
|
|
||||||
|
Dependency config presented here:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.insanusmokrassar</groupId>
|
||||||
|
<artifactId>TelegramBotAPI-extensions-utils</artifactId>
|
||||||
|
<version>${telegrambotapi-extensions-utils_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-extensions-utils:$telegrambotapi-extensions-utils_version"
|
||||||
|
```
|
||||||
|
|
||||||
|
or for old gradle:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
compile "com.github.insanusmokrassar:TelegramBotAPI-extensions-utils:$telegrambotapi-extensions-utils_version"
|
||||||
|
```
|
||||||
|
|
||||||
|
## How to use?
|
||||||
|
|
||||||
|
Here will be presented several examples of usage. In all cases it is expected that you have created your bot and filter:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val bot: RequestsExecutor = KtorRequestsExecutor(
|
||||||
|
TelegramAPIUrlsKeeper(BOT_TOKEN)
|
||||||
|
)
|
||||||
|
val filter = FlowsUpdatesFilter(64)
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternative way to use the things below:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val filter = bot.startGettingFlowsUpdatesByLongPolling(
|
||||||
|
scope = CoroutineScope(Dispatchers.Default)
|
||||||
|
) {
|
||||||
|
// place code from examples here with replacing of `filter` by `this`
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Updates
|
||||||
|
|
||||||
|
As mentioned in [Telegram Bot API reference](https://core.telegram.org/bots/api#getting-updates), there are two ways for
|
||||||
|
updates retrieving:
|
||||||
|
|
||||||
|
* Webhooks
|
||||||
|
* Long Polling
|
||||||
|
|
||||||
|
Both of them you could use in your project using [TelegramBotAPI](../TelegramBotAPI/README.md), but here there are
|
||||||
|
several useful extensions for both of them.
|
||||||
|
|
||||||
|
Anyway, in both of ways it will be useful to know that it is possible to create `UpdateReceiver` object using function
|
||||||
|
`flowsUpdatesFilter`:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val internalChannelsSizes = 128
|
||||||
|
flowsUpdatesFilter(internalChannelsSizes/* default is 64 */) {
|
||||||
|
/* ... */
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Long polling
|
||||||
|
|
||||||
|
The most simple way is Long Polling and one of the usages was mentioned above:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val filter = bot.startGettingFlowsUpdatesByLongPolling(
|
||||||
|
scope = CoroutineScope(Dispatchers.Default)
|
||||||
|
) {
|
||||||
|
// place code from examples here with replacing of `filter` by `this`
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Extension `startGettingFlowsUpdatesByLongPolling` was used in this example, but there are a lot of variations of
|
||||||
|
`startGettingOfUpdatesByLongPolling` and others for getting the same result. Usually, it is supposed that you already
|
||||||
|
have created `filter` object (or something like this) and will pass it into extension:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val filter = FlowsUpdatesFilter(64)
|
||||||
|
bot.startGettingOfUpdatesByLongPolling(
|
||||||
|
filter
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
But also there are extensions which allow to pass lambdas directly:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
bot.startGettingOfUpdatesByLongPolling(
|
||||||
|
{
|
||||||
|
println("Received message update: $it")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Anyway, it is strictly recommended to pass your `CoroutineScope` object to this method at least for more comfortable
|
||||||
|
management of updates.
|
||||||
|
|
||||||
|
#### WebHooks (currently JVM-only)
|
||||||
|
|
||||||
|
For webhooks there are less number of functions and extensions than for Long Polling (but it is still fully automated):
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
startListenWebhooks(
|
||||||
|
8081,
|
||||||
|
CIO // require to implement this engine dependency
|
||||||
|
) {
|
||||||
|
// here will be all updates one by one in $it
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Besides, there are two additional opportunities:
|
||||||
|
|
||||||
|
* Extension `Route#includeWebhookHandlingInRoute`, which allow you to include webhook processing inside your ktor
|
||||||
|
application without creating of new one server (as it is happening in `startListenWebhooks`)
|
||||||
|
* Extension `RequestsExecutor#setWebhookInfoAndStartListenWebhooks`. It is allow to set up full server (in fact, with
|
||||||
|
`startListenWebhooks`), but also send `SetWebhook` request before and check that it was successful
|
||||||
|
|
||||||
|
### Filters
|
||||||
|
|
||||||
|
There are several filters for flows.
|
||||||
|
|
||||||
|
#### Sent messages
|
||||||
|
|
||||||
|
All sent messages can be filtered for three types:
|
||||||
|
|
||||||
|
| Type | Description | Flow extension |
|
||||||
|
|:---- |:----------- |:-------------- |
|
||||||
|
| Common messages | Simple messages with text, media, location, etc. | `asContentMessagesFlow` |
|
||||||
|
| Chat actions | New chat member, rename of chat, etc. | `asChatEventsFlow` |
|
||||||
|
| Unknown events | Any other messages, that contain unsupported data | `asUnknownMessagesFlow` |
|
||||||
|
|
||||||
|
##### Common messages
|
||||||
|
|
||||||
|
Unfortunately, due to the erasing of generic types, when you are using `asContentMessagesFlow` you will retrieve
|
||||||
|
data with type `ContentMessage<*>`. For correct filtering of content type for retrieved objects, was created special
|
||||||
|
filters:
|
||||||
|
|
||||||
|
| Content type | Result type | Flow extension |
|
||||||
|
|:---- |:----------- |:-------------- |
|
||||||
|
| Animation | `ContentMessage<AnimationContent>`| `onlyAnimationContentMessages` |
|
||||||
|
| Audio | `ContentMessage<AudioContent>` | `onlyAudioContentMessages` |
|
||||||
|
| Contact | `ContentMessage<ContactContent>` | `onlyContactContentMessages` |
|
||||||
|
| Dice | `ContentMessage<DiceContent>` | `onlyDiceContentMessages` |
|
||||||
|
| Document | `ContentMessage<DocumentContent>` | `onlyDocumentContentMessages` |
|
||||||
|
| Game | `ContentMessage<GameContent>` | `onlyGameContentMessages` |
|
||||||
|
| Invoice | `ContentMessage<InvoiceContent>` | `onlyInvoiceContentMessages` |
|
||||||
|
| Location | `ContentMessage<LocationContent>` | `onlyLocationContentMessages` |
|
||||||
|
| Photo | `ContentMessage<PhotoContent>` | `onlyPhotoContentMessages` |
|
||||||
|
| Poll | `ContentMessage<PollContent>` | `onlyPollContentMessages` |
|
||||||
|
| Sticker | `ContentMessage<StickerContent>` | `onlyStickerContentMessages` |
|
||||||
|
| Text | `ContentMessage<TextContent>` | `onlyTextContentMessages` |
|
||||||
|
| Venue | `ContentMessage<VenueContent>` | `onlyVenueContentMessages` |
|
||||||
|
| Video | `ContentMessage<VideoContent>` | `onlyVideoContentMessages` |
|
||||||
|
| VideoNote | `ContentMessage<VideoNoteContent>` | `onlyVideoNoteContentMessages` |
|
||||||
|
| Voice | `ContentMessage<VoiceContent>` | `onlyVoiceContentMessages` |
|
||||||
|
|
||||||
|
For example, if you wish to get only photo messages from private chats of groups, you should call next code:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
filter.messageFlow.asContentMessagesFlow().onlyPhotoContentMessages().onEach {
|
||||||
|
println(it.content)
|
||||||
|
}.launchIn(
|
||||||
|
CoroutineScope(Dispatchers.Default)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Chat actions
|
||||||
|
|
||||||
|
Chat actions can be divided for three types of events source:
|
||||||
|
|
||||||
|
| Type | Flow extension |
|
||||||
|
|:---- |:-------------- |
|
||||||
|
| Channel events | `onlyChannelEvents` |
|
||||||
|
| Group events | `onlyGroupEvents` |
|
||||||
|
| Supergroup events | `onlySupergroupEvents` |
|
||||||
|
|
||||||
|
According to this table, if you want to add filtering by supergroup events, you will use code like this:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
filter.messageFlow.asChatEventsFlow().onlySupergroupEvents().onEach {
|
||||||
|
println(it.chatEvent)
|
||||||
|
}.launchIn(
|
||||||
|
CoroutineScope(Dispatchers.Default)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Shortcuts
|
||||||
|
|
||||||
|
With shortcuts you are able to use simple factories for several things.
|
||||||
|
|
||||||
|
#### ScheduledCloseInfo
|
||||||
|
|
||||||
|
In case if you are creating some poll, you able to use next shortcuts.
|
||||||
|
|
||||||
|
Next sample will use info with closing at the 10 seconds after now:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
closePollExactAt(DateTime.now() + TimeSpan(10000.0))
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example we will do the same, but in another way:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
closePollExactAfter(10)
|
||||||
|
```
|
||||||
|
|
||||||
|
Here we have passed `10` seconds and will get the same result object.
|
||||||
|
|
||||||
|
In opposite to previous shortcuts, the next one will create `approximate` closing schedule:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
closePollAfter(10)
|
||||||
|
```
|
||||||
|
|
||||||
|
The main difference here is that the last one will be closed after 10 seconds since the sending. With first samples
|
||||||
|
will be created **exact** time for closing of poll
|
||||||
48
TelegramBotAPI-extensions-utils/build.gradle
Normal file
48
TelegramBotAPI-extensions-utils/build.gradle
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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" version "$kotlin_version"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
|
||||||
|
api "${project.group}:TelegramBotAPI:$library_version"
|
||||||
|
} else {
|
||||||
|
api project(":TelegramBotAPI")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
57
TelegramBotAPI-extensions-utils/maven.publish.gradle
Normal file
57
TelegramBotAPI-extensions-utils/maven.publish.gradle
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
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.withXml {
|
||||||
|
asNode().children().last() + {
|
||||||
|
resolveStrategy = Closure.DELEGATE_FIRST
|
||||||
|
|
||||||
|
description "Util extensions for more useful work with updates and other things"
|
||||||
|
name "Telegram Bot API Utility Extensions"
|
||||||
|
url "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-utils"
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"bintrayConfig":{"repo":"StandardRepository","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI"},"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 Utility Extensions","description":"Util extensions for more useful work with updates and other things","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-utils","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"}
|
||||||
55
TelegramBotAPI-extensions-utils/publish.gradle
Normal file
55
TelegramBotAPI-extensions-utils/publish.gradle
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
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(".", "/")
|
||||||
|
}
|
||||||
|
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
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.CallbackQuery.*
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
|
|
||||||
|
fun <T : CallbackQuery> Flow<T>.onlyMessageDataCallbackQueries() = mapNotNull {
|
||||||
|
it as? MessageDataCallbackQuery
|
||||||
|
}
|
||||||
|
fun <T : CallbackQuery> Flow<T>.onlyInlineMessageIdDataCallbackQueries() = mapNotNull {
|
||||||
|
it as? InlineMessageIdDataCallbackQuery
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.InvoiceContent
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
fun <T : MessageContent> Flow<ContentMessage<*>>.withContentType(contentType: KClass<T>) = mapNotNull {
|
||||||
|
if (contentType.isInstance(it.content)) {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
it as ContentMessage<T>
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Flow<ContentMessage<*>>.onlyAnimationContentMessages() = withContentType(AnimationContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyAudioContentMessages() = withContentType(AudioContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyContactContentMessages() = withContentType(ContactContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyDiceContentMessages() = withContentType(DiceContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyDocumentContentMessages() = withContentType(DocumentContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyGameContentMessages() = withContentType(GameContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyInvoiceContentMessages() = withContentType(InvoiceContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyLocationContentMessages() = withContentType(LocationContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyPhotoContentMessages() = withContentType(PhotoContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyPollContentMessages() = withContentType(PollContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyStickerContentMessages() = withContentType(StickerContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyTextContentMessages() = withContentType(TextContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyVenueContentMessages() = withContentType(VenueContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyVideoContentMessages() = withContentType(VideoContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyVideoNoteContentMessages() = withContentType(VideoNoteContent::class)
|
||||||
|
fun Flow<ContentMessage<*>>.onlyVoiceContentMessages() = withContentType(VoiceContent::class)
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils
|
||||||
|
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
|
@Suppress("EXPERIMENTAL_API_USAGE")
|
||||||
|
internal val nonstrictJsonFormat = Json {
|
||||||
|
isLenient = true
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
serializeSpecialFloatingPointValues = true
|
||||||
|
useArrayPolymorphism = true
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.chat_events
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
|
||||||
|
fun <T : ChatEventMessage> Flow<ChatEventMessage>.divideBySource(contentType: KClass<T>) = mapNotNull {
|
||||||
|
if (contentType.isInstance(it)) {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
it as T
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Flow<ChatEventMessage>.onlyChannelEvents() = divideBySource(ChannelEventMessage::class)
|
||||||
|
fun Flow<ChatEventMessage>.onlyGroupEvents() = divideBySource(GroupEventMessage::class)
|
||||||
|
fun Flow<ChatEventMessage>.onlySupergroupEvents() = divideBySource(SupergroupEventMessage::class)
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.shortcuts
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.LongSeconds
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.Seconds
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.ApproximateScheduledCloseInfo
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.ExactScheduledCloseInfo
|
||||||
|
import com.soywiz.klock.DateTime
|
||||||
|
import com.soywiz.klock.TimeSpan
|
||||||
|
|
||||||
|
fun closePollExactAt(
|
||||||
|
dateTime: DateTime
|
||||||
|
) = ExactScheduledCloseInfo(
|
||||||
|
dateTime
|
||||||
|
)
|
||||||
|
|
||||||
|
fun closePollExactAfter(
|
||||||
|
seconds: LongSeconds
|
||||||
|
) = closePollExactAt(
|
||||||
|
DateTime.now() + TimeSpan(seconds.toDouble() * 1000L)
|
||||||
|
)
|
||||||
|
fun closePollExactAfter(
|
||||||
|
seconds: Seconds
|
||||||
|
) = closePollExactAfter(
|
||||||
|
seconds.toLong()
|
||||||
|
)
|
||||||
|
|
||||||
|
fun closePollAfter(
|
||||||
|
seconds: LongSeconds
|
||||||
|
) = ApproximateScheduledCloseInfo(
|
||||||
|
TimeSpan(seconds.toDouble() * 1000L)
|
||||||
|
)
|
||||||
|
|
||||||
|
fun closePollAfter(
|
||||||
|
seconds: Seconds
|
||||||
|
) = closePollAfter(seconds.toLong())
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.CallbackQuery.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.CallbackQueryUpdate
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return New [Flow] with [DataCallbackQuery] type, got from [CallbackQueryUpdate.data] field
|
||||||
|
*/
|
||||||
|
fun Flow<CallbackQueryUpdate>.asDataCallbackQueryFlow() = mapNotNull {
|
||||||
|
it.data as? DataCallbackQuery
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return New [Flow] with [GameShortNameCallbackQuery] type, got from [CallbackQueryUpdate.data] field
|
||||||
|
*/
|
||||||
|
fun Flow<CallbackQueryUpdate>.asGameShortNameCallbackQueryFlow() = mapNotNull {
|
||||||
|
it.data as? GameShortNameCallbackQuery
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return New [Flow] with [UnknownCallbackQueryType] type, got from [CallbackQueryUpdate.data] field
|
||||||
|
*/
|
||||||
|
fun Flow<CallbackQueryUpdate>.asUnknownCallbackQueryFlow() = mapNotNull {
|
||||||
|
it.data as? UnknownCallbackQueryType
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.onlyTextContentMessages
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.BotCommandTextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.RegularTextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.fullEntitiesList
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseSentMessageUpdate
|
||||||
|
import kotlinx.coroutines.flow.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert incoming [com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage.content] of
|
||||||
|
* messages with [fullEntitiesList] and check that incoming message contains ONLY ONE [TextSource] and that is
|
||||||
|
* [BotCommandTextSource]. Besides, it is checking that [BotCommandTextSource.command] [Regex.matches] with incoming
|
||||||
|
* [commandRegex]
|
||||||
|
*
|
||||||
|
* @return The same message in case if it contains only [BotCommandTextSource] with [Regex.matches]
|
||||||
|
* [BotCommandTextSource.command]
|
||||||
|
*
|
||||||
|
* @see fullEntitiesList
|
||||||
|
* @see asContentMessagesFlow
|
||||||
|
* @see onlyTextContentMessages
|
||||||
|
*/
|
||||||
|
fun <T : BaseSentMessageUpdate> Flow<T>.filterExactCommands(
|
||||||
|
commandRegex: Regex
|
||||||
|
) = asContentMessagesFlow().onlyTextContentMessages().filter { contentMessage ->
|
||||||
|
(contentMessage.content.fullEntitiesList().singleOrNull() as? BotCommandTextSource) ?.let { commandRegex.matches(it.command) } == true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert incoming [com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage.content] of
|
||||||
|
* messages with [fullEntitiesList] and check that incoming message contains [BotCommandTextSource]. Besides, it is
|
||||||
|
* checking that [BotCommandTextSource.command] [Regex.matches] with incoming [commandRegex]
|
||||||
|
*
|
||||||
|
* @return The same message in case if it contains somewhere in text [BotCommandTextSource] with [Regex.matches]
|
||||||
|
* [BotCommandTextSource.command]
|
||||||
|
*
|
||||||
|
* @see fullEntitiesList
|
||||||
|
* @see asContentMessagesFlow
|
||||||
|
* @see onlyTextContentMessages
|
||||||
|
*/
|
||||||
|
fun <T : BaseSentMessageUpdate> Flow<T>.filterCommandsInsideTextMessages(
|
||||||
|
commandRegex: Regex
|
||||||
|
) = asContentMessagesFlow().onlyTextContentMessages().filter { contentMessage ->
|
||||||
|
contentMessage.content.fullEntitiesList().any {
|
||||||
|
(it as? BotCommandTextSource) ?.let { commandRegex.matches(it.command) } == true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert incoming [com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage.content] of
|
||||||
|
* messages with [fullEntitiesList] and check that incoming message contains first [TextSource] as
|
||||||
|
* [BotCommandTextSource]. Besides, it is checking that [BotCommandTextSource.command] [Regex.matches] with incoming
|
||||||
|
* [commandRegex] and for other [TextSource] objects used next rules: all incoming text sources will be passed as is,
|
||||||
|
* [RegularTextSource] will be split by " " for several [RegularTextSource] which will contains not empty args without
|
||||||
|
* spaces.
|
||||||
|
*
|
||||||
|
* @return Converted list with first entity [BotCommandTextSource] and than all others according to rules in description
|
||||||
|
*
|
||||||
|
* @see fullEntitiesList
|
||||||
|
* @see asContentMessagesFlow
|
||||||
|
* @see onlyTextContentMessages
|
||||||
|
*/
|
||||||
|
fun <T : BaseSentMessageUpdate> Flow<T>.filterCommandsWithArgs(
|
||||||
|
commandRegex: Regex
|
||||||
|
): Flow<List<TextSource>> = asContentMessagesFlow().onlyTextContentMessages().mapNotNull { contentMessage ->
|
||||||
|
val allEntities = contentMessage.content.fullEntitiesList()
|
||||||
|
(allEntities.firstOrNull() as? BotCommandTextSource) ?.let {
|
||||||
|
if (commandRegex.matches(it.command)) {
|
||||||
|
allEntities.flatMap {
|
||||||
|
when (it) {
|
||||||
|
is RegularTextSource -> it.source.split(" ").mapNotNull { regularTextSourcePart ->
|
||||||
|
if (regularTextSourcePart.isNotBlank()) {
|
||||||
|
RegularTextSource(regularTextSourcePart)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> listOf(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.FlowsUpdatesFilter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non-suspendable function for easy-to-use creating of [FlowsUpdatesFilter] and applying the block to it
|
||||||
|
*
|
||||||
|
* @see flowsUpdatesFilter
|
||||||
|
*/
|
||||||
|
inline fun flowsUpdatesFilter(
|
||||||
|
internalChannelsSizes: Int = 64,
|
||||||
|
block: FlowsUpdatesFilter.() -> Unit
|
||||||
|
): FlowsUpdatesFilter {
|
||||||
|
val filter = FlowsUpdatesFilter(internalChannelsSizes)
|
||||||
|
filter.block()
|
||||||
|
return filter
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseSentMessageUpdate
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will map incoming [BaseSentMessageUpdate]s to [ContentMessage] from [BaseSentMessageUpdate.data]
|
||||||
|
*/
|
||||||
|
fun <T : BaseSentMessageUpdate> Flow<T>.asContentMessagesFlow() = mapNotNull {
|
||||||
|
it.data as? ContentMessage<*>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will map incoming [BaseSentMessageUpdate]s to [ChatEventMessage] from [BaseSentMessageUpdate.data]
|
||||||
|
*/
|
||||||
|
fun <T : BaseSentMessageUpdate> Flow<T>.asChatEventsFlow() = mapNotNull {
|
||||||
|
it.data as? ChatEventMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will map incoming [BaseSentMessageUpdate]s to [UnknownMessageType] from [BaseSentMessageUpdate.data]
|
||||||
|
*/
|
||||||
|
fun <T : BaseSentMessageUpdate> Flow<T>.asUnknownMessagesFlow() = mapNotNull {
|
||||||
|
it.data as? UnknownMessageType
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.nonstrictJsonFormat
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateDeserializationStrategy
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Deserialize [source] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]
|
||||||
|
*/
|
||||||
|
fun Json.toTelegramUpdate(source: String) = parse(UpdateDeserializationStrategy, source)
|
||||||
|
/**
|
||||||
|
* @return Deserialize [source] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]
|
||||||
|
*/
|
||||||
|
fun Json.toTelegramUpdate(source: JsonElement) = fromJson(UpdateDeserializationStrategy, source)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Deserialize [this] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]. In fact,
|
||||||
|
* it is must be JSON
|
||||||
|
*
|
||||||
|
* @see Json.toTelegramUpdate
|
||||||
|
*/
|
||||||
|
fun String.toTelegramUpdate() = nonstrictJsonFormat.toTelegramUpdate(this)
|
||||||
|
/**
|
||||||
|
* @return Deserialize [this] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]
|
||||||
|
*
|
||||||
|
* @see Json.toTelegramUpdate
|
||||||
|
*/
|
||||||
|
fun JsonElement.toTelegramUpdate() = nonstrictJsonFormat.toTelegramUpdate(this)
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.SentMediaGroupUpdate
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId]
|
||||||
|
*/
|
||||||
|
fun <T : BaseMessageUpdate> Flow<T>.filterBaseMessageUpdates(chatId: ChatId): Flow<T> = filter {
|
||||||
|
it.data.chat.id == chatId
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] using [Chat.id] of [chat]
|
||||||
|
*/
|
||||||
|
fun <T : BaseMessageUpdate> Flow<T>.filterBaseMessageUpdates(chat: Chat): Flow<T> = filterBaseMessageUpdates(chat.id)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId]
|
||||||
|
*/
|
||||||
|
fun <T : SentMediaGroupUpdate> Flow<T>.filterSentMediaGroupUpdates(chatId: ChatId): Flow<T> = filter {
|
||||||
|
it.data.first().chat.id == chatId
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] using [Chat.id] of [chat]
|
||||||
|
*/
|
||||||
|
fun <T : SentMediaGroupUpdate> Flow<T>.filterSentMediaGroupUpdates(chat: Chat): Flow<T> = filterSentMediaGroupUpdates(chat.id)
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return If [this] is [SentMediaGroupUpdate] - [Update.updateId] of [last] element, or its own [Update.updateId]
|
||||||
|
*/
|
||||||
|
fun Update.lastUpdateIdentifier(): UpdateIdentifier {
|
||||||
|
return if (this is SentMediaGroupUpdate) {
|
||||||
|
origins.last().updateId
|
||||||
|
} else {
|
||||||
|
updateId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The biggest [UpdateIdentifier] OR null
|
||||||
|
*
|
||||||
|
* @see [Update.lastUpdateIdentifier]
|
||||||
|
*/
|
||||||
|
fun List<Update>.lastUpdateIdentifier(): UpdateIdentifier? {
|
||||||
|
return maxBy { it.updateId } ?.lastUpdateIdentifier()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will convert incoming list of updates to list with [MediaGroupUpdate]s
|
||||||
|
*/
|
||||||
|
fun List<Update>.convertWithMediaGroupUpdates(): List<Update> {
|
||||||
|
val resultUpdates = mutableListOf<Update>()
|
||||||
|
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<BaseSentMessageUpdate>>()
|
||||||
|
for (update in this) {
|
||||||
|
val data = (update.data as? MediaGroupMessage)
|
||||||
|
if (data == null) {
|
||||||
|
resultUpdates.add(update)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
when (update) {
|
||||||
|
is BaseEditMessageUpdate -> resultUpdates.add(
|
||||||
|
update.toEditMediaGroupUpdate()
|
||||||
|
)
|
||||||
|
is BaseSentMessageUpdate -> {
|
||||||
|
mediaGroups.getOrPut(data.mediaGroupId) {
|
||||||
|
mutableListOf()
|
||||||
|
}.add(update)
|
||||||
|
}
|
||||||
|
else -> resultUpdates.add(update)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mediaGroups.values.map {
|
||||||
|
it.toSentMediaGroupUpdate() ?.let { mediaGroupUpdate ->
|
||||||
|
resultUpdates.add(mediaGroupUpdate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultUpdates.sortBy { it.updateId }
|
||||||
|
return resultUpdates
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @receiver List of [BaseSentMessageUpdate] where [BaseSentMessageUpdate.data] is [MediaGroupMessage] and all messages
|
||||||
|
* have the same [MediaGroupMessage.mediaGroupId]
|
||||||
|
* @return [MessageMediaGroupUpdate] in case if [first] object of [this] is [MessageUpdate]. When [first] object is
|
||||||
|
* [ChannelPostUpdate] instance - will return [ChannelPostMediaGroupUpdate]. Otherwise will be returned null
|
||||||
|
*/
|
||||||
|
fun List<BaseSentMessageUpdate>.toSentMediaGroupUpdate(): SentMediaGroupUpdate? = (this as? SentMediaGroupUpdate) ?: let {
|
||||||
|
if (isEmpty()) {
|
||||||
|
return@let null
|
||||||
|
}
|
||||||
|
val resultList = sortedBy { it.updateId }
|
||||||
|
when (first()) {
|
||||||
|
is MessageUpdate -> MessageMediaGroupUpdate(resultList)
|
||||||
|
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return [EditMessageMediaGroupUpdate] in case if [this] is [EditMessageUpdate]. When [this] object is
|
||||||
|
* [EditChannelPostUpdate] instance - will return [EditChannelPostMediaGroupUpdate]
|
||||||
|
*
|
||||||
|
* @throws IllegalStateException
|
||||||
|
*/
|
||||||
|
fun BaseEditMessageUpdate.toEditMediaGroupUpdate(): EditMediaGroupUpdate = (this as? EditMediaGroupUpdate) ?: let {
|
||||||
|
when (this) {
|
||||||
|
is EditMessageUpdate -> EditMessageMediaGroupUpdate(this)
|
||||||
|
is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(this)
|
||||||
|
else -> error("Unsupported type of ${BaseEditMessageUpdate::class.simpleName}")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates.retrieving
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates.convertWithMediaGroupUpdates
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates.lastUpdateIdentifier
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.GetUpdates
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
|
||||||
|
timeoutSeconds: Seconds = 30,
|
||||||
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||||
|
exceptionsHandler: (ExceptionHandler<Unit>)? = null,
|
||||||
|
allowedUpdates: List<String>? = null,
|
||||||
|
updatesReceiver: UpdateReceiver<Update>
|
||||||
|
): Job = scope.launch {
|
||||||
|
var lastUpdateIdentifier: UpdateIdentifier? = null
|
||||||
|
|
||||||
|
while (isActive) {
|
||||||
|
handleSafely(
|
||||||
|
{ e ->
|
||||||
|
exceptionsHandler ?.invoke(e)
|
||||||
|
if (e is RequestException) {
|
||||||
|
delay(1000L)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
val updates = execute(
|
||||||
|
GetUpdates(
|
||||||
|
offset = lastUpdateIdentifier?.plus(1),
|
||||||
|
timeout = timeoutSeconds,
|
||||||
|
allowed_updates = allowedUpdates
|
||||||
|
)
|
||||||
|
).let { originalUpdates ->
|
||||||
|
val converted = originalUpdates.convertWithMediaGroupUpdates()
|
||||||
|
/**
|
||||||
|
* Dirty hack for cases when the media group was retrieved not fully:
|
||||||
|
*
|
||||||
|
* We are throw out the last media group and will reretrieve it again in the next get updates
|
||||||
|
* and it will guarantee that it is full
|
||||||
|
*/
|
||||||
|
if (originalUpdates.size == getUpdatesLimit.last && converted.last() is SentMediaGroupUpdate) {
|
||||||
|
converted - converted.last()
|
||||||
|
} else {
|
||||||
|
converted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSafely {
|
||||||
|
for (update in updates) {
|
||||||
|
updatesReceiver(update)
|
||||||
|
|
||||||
|
lastUpdateIdentifier = update.lastUpdateIdentifier()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will create a new one [FlowsUpdatesFilter]. This method could be unsafe due to the fact that it will start
|
||||||
|
* getting updates IMMEDIATELY. That means that your bot will be able to skip some of them until you will call
|
||||||
|
* [kotlinx.coroutines.flow.Flow.collect] on one of [FlowsUpdatesFilter] flows. To avoid it, you can pass
|
||||||
|
* [flowUpdatesPreset] lambda - it will be called BEFORE starting updates getting
|
||||||
|
*/
|
||||||
|
@FlowPreview
|
||||||
|
@PreviewFeature
|
||||||
|
@Suppress("unused")
|
||||||
|
fun RequestsExecutor.startGettingFlowsUpdatesByLongPolling(
|
||||||
|
timeoutSeconds: Seconds = 30,
|
||||||
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||||
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||||
|
flowsUpdatesFilterUpdatesKeeperCount: Int = 64,
|
||||||
|
flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit = {}
|
||||||
|
): FlowsUpdatesFilter = FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply {
|
||||||
|
flowUpdatesPreset()
|
||||||
|
startGettingOfUpdatesByLongPolling(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
|
||||||
|
updatesFilter: UpdatesFilter,
|
||||||
|
timeoutSeconds: Seconds = 30,
|
||||||
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||||
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||||
|
): Job = startGettingOfUpdatesByLongPolling(
|
||||||
|
timeoutSeconds,
|
||||||
|
scope,
|
||||||
|
exceptionsHandler,
|
||||||
|
updatesFilter.allowedUpdates,
|
||||||
|
updatesFilter.asUpdateReceiver
|
||||||
|
)
|
||||||
|
|
||||||
|
fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
|
||||||
|
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
||||||
|
messageMediaGroupCallback: UpdateReceiver<MessageMediaGroupUpdate>? = null,
|
||||||
|
editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
||||||
|
editedMessageMediaGroupCallback: UpdateReceiver<EditMessageMediaGroupUpdate>? = null,
|
||||||
|
channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
||||||
|
channelPostMediaGroupCallback: UpdateReceiver<ChannelPostMediaGroupUpdate>? = null,
|
||||||
|
editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
||||||
|
editedChannelPostMediaGroupCallback: UpdateReceiver<EditChannelPostMediaGroupUpdate>? = null,
|
||||||
|
chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
||||||
|
inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
||||||
|
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
||||||
|
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
|
||||||
|
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
||||||
|
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
||||||
|
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||||
|
timeoutSeconds: Seconds = 30,
|
||||||
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||||
|
scope: CoroutineScope = GlobalScope
|
||||||
|
): Job {
|
||||||
|
return startGettingOfUpdatesByLongPolling(
|
||||||
|
SimpleUpdatesFilter(
|
||||||
|
messageCallback,
|
||||||
|
messageMediaGroupCallback,
|
||||||
|
editedMessageCallback,
|
||||||
|
editedMessageMediaGroupCallback,
|
||||||
|
channelPostCallback,
|
||||||
|
channelPostMediaGroupCallback,
|
||||||
|
editedChannelPostCallback,
|
||||||
|
editedChannelPostMediaGroupCallback,
|
||||||
|
chosenInlineResultCallback,
|
||||||
|
inlineQueryCallback,
|
||||||
|
callbackQueryCallback,
|
||||||
|
shippingQueryCallback,
|
||||||
|
preCheckoutQueryCallback,
|
||||||
|
pollCallback,
|
||||||
|
pollAnswerCallback
|
||||||
|
),
|
||||||
|
timeoutSeconds,
|
||||||
|
exceptionsHandler,
|
||||||
|
scope
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
|
||||||
|
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
||||||
|
mediaGroupCallback: UpdateReceiver<MediaGroupUpdate>? = null,
|
||||||
|
editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
||||||
|
channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
||||||
|
editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
||||||
|
chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
||||||
|
inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
||||||
|
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
||||||
|
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
|
||||||
|
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
||||||
|
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
||||||
|
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||||
|
timeoutSeconds: Seconds = 30,
|
||||||
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||||
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||||
|
): Job = startGettingOfUpdatesByLongPolling(
|
||||||
|
messageCallback = messageCallback,
|
||||||
|
messageMediaGroupCallback = mediaGroupCallback,
|
||||||
|
editedMessageCallback = editedMessageCallback,
|
||||||
|
editedMessageMediaGroupCallback = mediaGroupCallback,
|
||||||
|
channelPostCallback = channelPostCallback,
|
||||||
|
channelPostMediaGroupCallback = mediaGroupCallback,
|
||||||
|
editedChannelPostCallback = editedChannelPostCallback,
|
||||||
|
editedChannelPostMediaGroupCallback = mediaGroupCallback,
|
||||||
|
chosenInlineResultCallback = chosenInlineResultCallback,
|
||||||
|
inlineQueryCallback = inlineQueryCallback,
|
||||||
|
callbackQueryCallback = callbackQueryCallback,
|
||||||
|
shippingQueryCallback = shippingQueryCallback,
|
||||||
|
preCheckoutQueryCallback = preCheckoutQueryCallback,
|
||||||
|
pollCallback = pollCallback,
|
||||||
|
pollAnswerCallback = pollAnswerCallback,
|
||||||
|
timeoutSeconds = timeoutSeconds,
|
||||||
|
exceptionsHandler = exceptionsHandler,
|
||||||
|
scope = scope
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates.retrieving
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates.convertWithMediaGroupUpdates
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdateReceiver
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.accumulateByKey
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.channels.Channel
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create [UpdateReceiver] object which will correctly accumulate updates and send into output updates which INCLUDE
|
||||||
|
* [com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.MediaGroupUpdate]s.
|
||||||
|
*
|
||||||
|
* @see UpdateReceiver
|
||||||
|
*/
|
||||||
|
fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation(
|
||||||
|
output: UpdateReceiver<Update>,
|
||||||
|
debounceTimeMillis: Long = 1000L
|
||||||
|
): UpdateReceiver<Update> {
|
||||||
|
val updatesChannel = Channel<Update>(Channel.UNLIMITED)
|
||||||
|
val mediaGroupChannel = Channel<Pair<String, BaseMessageUpdate>>(Channel.UNLIMITED)
|
||||||
|
val mediaGroupAccumulatedChannel = mediaGroupChannel.accumulateByKey(
|
||||||
|
debounceTimeMillis,
|
||||||
|
scope = this
|
||||||
|
)
|
||||||
|
|
||||||
|
launch {
|
||||||
|
launch {
|
||||||
|
for (update in updatesChannel) {
|
||||||
|
when (val data = update.data) {
|
||||||
|
is MediaGroupMessage -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
|
||||||
|
else -> output(update)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
launch {
|
||||||
|
for ((_, mediaGroup) in mediaGroupAccumulatedChannel) {
|
||||||
|
mediaGroup.convertWithMediaGroupUpdates().forEach {
|
||||||
|
output(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { updatesChannel.send(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create [UpdateReceiver] object which will correctly accumulate updates and send into output updates which INCLUDE
|
||||||
|
* [com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.MediaGroupUpdate]s.
|
||||||
|
*
|
||||||
|
* @see UpdateReceiver
|
||||||
|
*/
|
||||||
|
fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation(
|
||||||
|
output: UpdateReceiver<Update>
|
||||||
|
) = updateHandlerWithMediaGroupsAdaptation(output, 1000L)
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates.retrieving
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.nonstrictJsonFormat
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.MultipartRequestImpl
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.webhook.SetWebhook
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateDeserializationStrategy
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdateReceiver
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.webhook.WebhookPrivateKeyConfig
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.ExceptionHandler
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.handleSafely
|
||||||
|
import io.ktor.application.call
|
||||||
|
import io.ktor.request.receiveText
|
||||||
|
import io.ktor.response.respond
|
||||||
|
import io.ktor.routing.*
|
||||||
|
import io.ktor.server.engine.*
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to include webhook in custom route everywhere in your server
|
||||||
|
*
|
||||||
|
* @param [scope] Will be used for mapping of media groups
|
||||||
|
* @param [exceptionsHandler] Pass this parameter to set custom exception handler for getting updates
|
||||||
|
* @param [block] Some receiver block like [com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.FlowsUpdatesFilter]
|
||||||
|
*
|
||||||
|
* @see com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.FlowsUpdatesFilter
|
||||||
|
* @see UpdatesFilter
|
||||||
|
* @see UpdatesFilter.asUpdateReceiver
|
||||||
|
*/
|
||||||
|
fun Route.includeWebhookHandlingInRoute(
|
||||||
|
scope: CoroutineScope,
|
||||||
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||||
|
block: UpdateReceiver<Update>
|
||||||
|
) {
|
||||||
|
val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block)
|
||||||
|
post {
|
||||||
|
handleSafely(
|
||||||
|
exceptionsHandler ?: {}
|
||||||
|
) {
|
||||||
|
val asJson =
|
||||||
|
nonstrictJsonFormat.parseJson(call.receiveText())
|
||||||
|
val update = nonstrictJsonFormat.fromJson(
|
||||||
|
UpdateDeserializationStrategy,
|
||||||
|
asJson
|
||||||
|
)
|
||||||
|
transformer(update)
|
||||||
|
}
|
||||||
|
call.respond("Ok")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting up ktor server, set webhook info via [SetWebhook] request.
|
||||||
|
*
|
||||||
|
* @param listenPort port which will be listen by bot
|
||||||
|
* @param listenRoute address to listen by bot. If null - will be set up in root of host
|
||||||
|
* @param scope Scope which will be used for
|
||||||
|
* @param privateKeyConfig If configured - server will be created with [sslConnector]. [connector] will be used otherwise
|
||||||
|
*
|
||||||
|
* @see com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.FlowsUpdatesFilter
|
||||||
|
* @see UpdatesFilter
|
||||||
|
* @see UpdatesFilter.asUpdateReceiver
|
||||||
|
*/
|
||||||
|
fun startListenWebhooks(
|
||||||
|
listenPort: Int,
|
||||||
|
engineFactory: ApplicationEngineFactory<*, *>,
|
||||||
|
exceptionsHandler: ExceptionHandler<Unit>,
|
||||||
|
listenHost: String = "0.0.0.0",
|
||||||
|
listenRoute: String? = null,
|
||||||
|
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||||
|
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||||
|
block: UpdateReceiver<Update>
|
||||||
|
): ApplicationEngine {
|
||||||
|
lateinit var engine: ApplicationEngine
|
||||||
|
val env = applicationEngineEnvironment {
|
||||||
|
|
||||||
|
module {
|
||||||
|
routing {
|
||||||
|
listenRoute ?.also {
|
||||||
|
createRouteFromPath(it).includeWebhookHandlingInRoute(scope, exceptionsHandler, block)
|
||||||
|
} ?: includeWebhookHandlingInRoute(scope, exceptionsHandler, block)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
privateKeyConfig ?.let {
|
||||||
|
sslConnector(
|
||||||
|
privateKeyConfig.keyStore,
|
||||||
|
privateKeyConfig.aliasName,
|
||||||
|
privateKeyConfig::keyStorePassword,
|
||||||
|
privateKeyConfig::aliasPassword
|
||||||
|
) {
|
||||||
|
host = listenHost
|
||||||
|
port = listenPort
|
||||||
|
}
|
||||||
|
} ?: connector {
|
||||||
|
host = listenHost
|
||||||
|
port = listenPort
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
engine = embeddedServer(engineFactory, env)
|
||||||
|
engine.start(false)
|
||||||
|
|
||||||
|
return engine
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun RequestsExecutor.internalSetWebhookInfoAndStartListenWebhooks(
|
||||||
|
listenPort: Int,
|
||||||
|
engineFactory: ApplicationEngineFactory<*, *>,
|
||||||
|
setWebhookRequest: Request<Boolean>,
|
||||||
|
exceptionsHandler: ExceptionHandler<Unit> = {},
|
||||||
|
listenHost: String = "0.0.0.0",
|
||||||
|
listenRoute: String? = null,
|
||||||
|
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||||
|
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||||
|
block: UpdateReceiver<Update>
|
||||||
|
): Job {
|
||||||
|
return try {
|
||||||
|
execute(setWebhookRequest)
|
||||||
|
val engine = startListenWebhooks(listenPort, engineFactory, exceptionsHandler, listenHost, listenRoute, privateKeyConfig, scope, block)
|
||||||
|
scope.launch {
|
||||||
|
engine.environment.parentCoroutineContext[Job] ?.join()
|
||||||
|
engine.stop(1000, 5000)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting up ktor server, set webhook info via [SetWebhook] request.
|
||||||
|
*
|
||||||
|
* @param listenPort port which will be listen by bot
|
||||||
|
* @param listenRoute address to listen by bot
|
||||||
|
* @param scope Scope which will be used for
|
||||||
|
*
|
||||||
|
* @see com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.FlowsUpdatesFilter
|
||||||
|
* @see UpdatesFilter
|
||||||
|
* @see UpdatesFilter.asUpdateReceiver
|
||||||
|
*/
|
||||||
|
@Suppress("unused")
|
||||||
|
suspend fun RequestsExecutor.setWebhookInfoAndStartListenWebhooks(
|
||||||
|
listenPort: Int,
|
||||||
|
engineFactory: ApplicationEngineFactory<*, *>,
|
||||||
|
setWebhookRequest: SetWebhook,
|
||||||
|
exceptionsHandler: ExceptionHandler<Unit> = {},
|
||||||
|
listenHost: String = "0.0.0.0",
|
||||||
|
listenRoute: String = "/",
|
||||||
|
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||||
|
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||||
|
block: UpdateReceiver<Update>
|
||||||
|
): Job = internalSetWebhookInfoAndStartListenWebhooks(
|
||||||
|
listenPort,
|
||||||
|
engineFactory,
|
||||||
|
setWebhookRequest as Request<Boolean>,
|
||||||
|
exceptionsHandler,
|
||||||
|
listenHost,
|
||||||
|
listenRoute,
|
||||||
|
privateKeyConfig,
|
||||||
|
scope,
|
||||||
|
block
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting up ktor server, set webhook info via [SetWebhook] request.
|
||||||
|
*
|
||||||
|
* @param listenPort port which will be listen by bot
|
||||||
|
* @param listenRoute address to listen by bot
|
||||||
|
* @param scope Scope which will be used for
|
||||||
|
*
|
||||||
|
* @see com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.FlowsUpdatesFilter
|
||||||
|
* @see UpdatesFilter
|
||||||
|
* @see UpdatesFilter.asUpdateReceiver
|
||||||
|
*/
|
||||||
|
@Suppress("unused")
|
||||||
|
suspend fun RequestsExecutor.setWebhookInfoAndStartListenWebhooks(
|
||||||
|
listenPort: Int,
|
||||||
|
engineFactory: ApplicationEngineFactory<*, *>,
|
||||||
|
setWebhookRequest: MultipartRequestImpl<SetWebhook, Map<String, MultipartFile>, Boolean>,
|
||||||
|
exceptionsHandler: ExceptionHandler<Unit> = {},
|
||||||
|
listenHost: String = "0.0.0.0",
|
||||||
|
listenRoute: String? = null,
|
||||||
|
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||||
|
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||||
|
block: UpdateReceiver<Update>
|
||||||
|
): Job = internalSetWebhookInfoAndStartListenWebhooks(
|
||||||
|
listenPort,
|
||||||
|
engineFactory,
|
||||||
|
setWebhookRequest as Request<Boolean>,
|
||||||
|
exceptionsHandler,
|
||||||
|
listenHost,
|
||||||
|
listenRoute,
|
||||||
|
privateKeyConfig,
|
||||||
|
scope,
|
||||||
|
block
|
||||||
|
)
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
# TelegramBotAPI
|
# TelegramBotAPI
|
||||||
|
|
||||||
[](https://github.com/KotlinBy/awesome-kotlin)
|
|
||||||
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion)
|
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion)
|
||||||
[](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI)
|
[](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI)
|
||||||
[](https://jenkins.insanusmokrassar.com/job/TelegramBotAPI_master__publishing/)
|
|
||||||
|
|
||||||
## What is it?
|
## What is it?
|
||||||
|
|
||||||
@@ -12,11 +10,10 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/
|
|||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
|
|
||||||
This version compatible with [23th of January 2020 update of TelegramBotAPI (version 4.6)](https://core.telegram.org/bots/api#january-23-2020).
|
This version compatible with [24th of April 2020 update of TelegramBotAPI (version 4.8)](https://core.telegram.org/bots/api#april-24-2020).
|
||||||
There is Telegram Passport API exception of implemented functionality, which was presented in
|
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
|
[August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api-changelog#august-27-2018) update. It will be implemented
|
||||||
as soon as possible. All APIs that are not included are presented
|
as soon as possible.
|
||||||
[wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Not-included-API).
|
|
||||||
|
|
||||||
## How to implement library?
|
## How to implement library?
|
||||||
|
|
||||||
@@ -152,53 +149,3 @@ 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)
|
available on ktor.io site for [client](https://ktor.io/clients/http-client/engines.html) and [server](https://ktor.io/quickstart/artifacts.html)
|
||||||
engines.
|
engines.
|
||||||
|
|
||||||
## Getting updates
|
|
||||||
|
|
||||||
In this library currently realised two ways to get updates from telegram:
|
|
||||||
|
|
||||||
* Polling - in this case bot will request updates from time to time (you can set up delay between requests)
|
|
||||||
* Webhook via reverse proxy or something like this
|
|
||||||
|
|
||||||
### Updates filters
|
|
||||||
|
|
||||||
Currently webhook method contains `UpdatesFilter` as necessary argument for getting updates.
|
|
||||||
`UpdatesFilter` will sort updates and throw their into different callbacks. Currently supporting
|
|
||||||
separate getting updates for media groups - they are accumulating with debounce in one second
|
|
||||||
(for being sure that all objects of media group was received).
|
|
||||||
|
|
||||||
Updates polling also support `UpdatesFilter` but it is not required to use it and you can get updates directly
|
|
||||||
in `UpdateReceiver`, which you will provide to `startGettingOfUpdates` method
|
|
||||||
|
|
||||||
### Webhook set up
|
|
||||||
|
|
||||||
If you wish to use webhook method, you will need:
|
|
||||||
|
|
||||||
* White IP - your IP address or host, which available for calling. [TelegramBotAPI](https://core.telegram.org/bots/api#setwebhook)
|
|
||||||
recommend to use some unique address for each bot which you are using
|
|
||||||
* SSL certificate. Usually you can obtain the certificate using your domain provider, [Let'sEncrypt](https://letsencrypt.org/) or [create it](https://core.telegram.org/bots/self-signed)
|
|
||||||
* Nginx or something like this
|
|
||||||
|
|
||||||
Template for Nginx server config you can find in [this gist](https://gist.github.com/InsanusMokrassar/fcc6e09cebd07e46e8f0fdec234750c4#file-nginxssl-conf).
|
|
||||||
|
|
||||||
For webhook you can provide `File` with public part of certificate, `URL` where bot will be available and inner `PORT` which
|
|
||||||
will be used to start receiving of updates. Actually, you can skip passing of `File` when you have something like
|
|
||||||
nginx for proxy forwarding.
|
|
||||||
|
|
||||||
In case of using `nginx` with reverse-proxy config, setting up of Webhook will look like:
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
requestsExecutor.setWebhook(
|
|
||||||
WEBHOOK_URL,
|
|
||||||
INTERNAL_PORT,
|
|
||||||
filter,
|
|
||||||
ENGINE_FACTORY
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
Here:
|
|
||||||
|
|
||||||
* `WEBHOOK_URL` - the url which will be used by Telegram system to send updates
|
|
||||||
* `INTERNAL_PORT` - the port which will be used in bot for listening of updates
|
|
||||||
* `filter` - instance of [UpdatesFilter](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/UpdatesFilter.kt),
|
|
||||||
which will be used to filter incoming updates
|
|
||||||
* `ENGINE_FACTORY` - used factory name, for example, `CIO` in case of usage `io.ktor:ktor-server-cio` as server engine
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ kotlin {
|
|||||||
implementation kotlin('stdlib')
|
implementation kotlin('stdlib')
|
||||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version"
|
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version"
|
||||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
||||||
|
api "org.jetbrains.kotlinx:kotlinx-serialization-properties-common:$kotlin_serialisation_runtime_version"
|
||||||
|
|
||||||
api "com.soywiz.korlibs.klock:klock:$klock_version"
|
api "com.soywiz.korlibs.klock:klock:$klock_version"
|
||||||
api "com.benasher44:uuid:$uuid_version"
|
api "com.benasher44:uuid:$uuid_version"
|
||||||
@@ -56,12 +57,15 @@ kotlin {
|
|||||||
jvmMain {
|
jvmMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
||||||
|
api "org.jetbrains.kotlinx:kotlinx-serialization-properties:$kotlin_serialisation_runtime_version"
|
||||||
|
|
||||||
api "io.ktor:ktor-client:$ktor_version"
|
api "io.ktor:ktor-client:$ktor_version"
|
||||||
api "io.ktor:ktor-server:$ktor_version"
|
api "io.ktor:ktor-server:$ktor_version"
|
||||||
|
|
||||||
api "io.ktor:ktor-server-host-common:$ktor_version"
|
api "io.ktor:ktor-server-host-common:$ktor_version"
|
||||||
api "io.ktor:ktor-client-cio:$ktor_version"
|
api "io.ktor:ktor-client-cio:$ktor_version"
|
||||||
|
|
||||||
|
api "javax.activation:activation:$javax_activation_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jvmTest {
|
jvmTest {
|
||||||
@@ -73,6 +77,7 @@ kotlin {
|
|||||||
jsMain {
|
jsMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version"
|
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version"
|
||||||
|
api "org.jetbrains.kotlinx:kotlinx-serialization-properties-js:$kotlin_serialisation_runtime_version"
|
||||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version"
|
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version"
|
||||||
api "io.ktor:ktor-client-js:$ktor_version"
|
api "io.ktor:ktor-client-js:$ktor_version"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,15 @@ interface CaptionedOutput : Captioned {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface CaptionedInput : 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>
|
val captionEntities: List<TextPart>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun CaptionedInput.fullEntitiesList() = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList()
|
/**
|
||||||
|
* 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()
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.fullListOfSubSource
|
||||||
|
|
||||||
|
interface Explained {
|
||||||
|
val explanation: String?
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ExplainedOutput : Explained {
|
||||||
|
val parseMode: ParseMode?
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||||
|
|
||||||
interface MimeTyped {
|
interface MimeTyped {
|
||||||
val mimeType: String? // TODO::replace by something like enum or interface
|
val mimeType: MimeType?
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||||
|
|
||||||
|
typealias FullTextSourcesList = List<TextSource>
|
||||||
|
typealias FullTextPartsList = List<TextPart>
|
||||||
|
|
||||||
interface TextSource {
|
interface TextSource {
|
||||||
val asMarkdownSource: String
|
val asMarkdownSource: String
|
||||||
val asMarkdownV2Source: String
|
val asMarkdownV2Source: String
|
||||||
val asHtmlSource: String
|
val asHtmlSource: String
|
||||||
|
val source: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -15,3 +19,5 @@ data class TextPart(
|
|||||||
val range: IntRange,
|
val range: IntRange,
|
||||||
val source: TextSource
|
val source: TextSource
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun List<TextPart>.justTextSources() = map { it.source }
|
||||||
|
|||||||
@@ -9,15 +9,13 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.RequestL
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
|
import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.call.receive
|
import io.ktor.client.call.receive
|
||||||
import io.ktor.client.features.ClientRequestException
|
import io.ktor.client.features.*
|
||||||
import io.ktor.client.features.HttpTimeout
|
|
||||||
import io.ktor.client.statement.HttpStatement
|
import io.ktor.client.statement.HttpStatement
|
||||||
import io.ktor.client.statement.readText
|
import io.ktor.client.statement.readText
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.supervisorScope
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
class KtorRequestsExecutor(
|
class KtorRequestsExecutor(
|
||||||
@@ -26,7 +24,7 @@ class KtorRequestsExecutor(
|
|||||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||||
excludeDefaultFactories: Boolean = false,
|
excludeDefaultFactories: Boolean = false,
|
||||||
private val requestsLimiter: RequestLimiter = EmptyLimiter,
|
private val requestsLimiter: RequestLimiter = EmptyLimiter,
|
||||||
private val jsonFormatter: Json = Json.nonstrict
|
private val jsonFormatter: Json = nonstrictJsonFormat
|
||||||
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
||||||
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
||||||
if (!excludeDefaultFactories) {
|
if (!excludeDefaultFactories) {
|
||||||
@@ -37,12 +35,27 @@ class KtorRequestsExecutor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val client = client.config {
|
private val client = client.config {
|
||||||
|
if (client.feature(HttpTimeout) == null) {
|
||||||
install(HttpTimeout)
|
install(HttpTimeout)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun <T : Any> execute(request: Request<T>): T {
|
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||||
return try {
|
return handleSafely(
|
||||||
supervisorScope {
|
{ e ->
|
||||||
|
throw if (e is ClientRequestException) {
|
||||||
|
val content = e.response.readText()
|
||||||
|
val responseObject = jsonFormatter.parse(Response.serializer(), content)
|
||||||
|
newRequestException(
|
||||||
|
responseObject,
|
||||||
|
content,
|
||||||
|
"Can't get result object from $content"
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
requestsLimiter.limit {
|
requestsLimiter.limit {
|
||||||
var statement: HttpStatement? = null
|
var statement: HttpStatement? = null
|
||||||
for (factory in callsFactories) {
|
for (factory in callsFactories) {
|
||||||
@@ -79,17 +92,6 @@ class KtorRequestsExecutor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: ClientRequestException) {
|
|
||||||
val content = e.response.readText()
|
|
||||||
val responseObject = jsonFormatter.parse(Response.serializer(), content)
|
|
||||||
throw newRequestException(
|
|
||||||
responseObject,
|
|
||||||
content,
|
|
||||||
"Can't get result object from $content"
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
|
|||||||
if (customTimeoutMillis > 0) {
|
if (customTimeoutMillis > 0) {
|
||||||
timeout {
|
timeout {
|
||||||
requestTimeoutMillis = customTimeoutMillis
|
requestTimeoutMillis = customTimeoutMillis
|
||||||
|
socketTimeoutMillis = customTimeoutMillis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,20 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import io.ktor.utils.io.core.Closeable
|
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 {
|
interface RequestsExecutor : Closeable {
|
||||||
/**
|
/**
|
||||||
* @throws com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
|
* Unsafe execution of incoming [request]. Can throw almost any exception. So, it is better to use
|
||||||
|
* something like [com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.executeAsync] or
|
||||||
|
* [com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.executeUnsafe]
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
suspend fun <T : Any> execute(request: Request<T>): T
|
suspend fun <T : Any> execute(request: Request<T>): T
|
||||||
}
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
|
||||||
|
|
||||||
import io.ktor.utils.io.core.Closeable
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to more simple way to get updates using TelegramBotAPI-extensions-api")
|
|
||||||
interface UpdatesPoller : Closeable {
|
|
||||||
fun start(scope: CoroutineScope = CoroutineScope(Dispatchers.Default))
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions
|
package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||||
import kotlinx.io.IOException
|
import io.ktor.utils.io.errors.IOException
|
||||||
|
|
||||||
fun newRequestException(
|
fun newRequestException(
|
||||||
response: Response,
|
response: Response,
|
||||||
@@ -14,6 +14,7 @@ fun newRequestException(
|
|||||||
description == "Bad Request: message to edit not found" -> MessageToEditNotFoundException(response, plainAnswer, message, cause)
|
description == "Bad Request: message to edit not found" -> MessageToEditNotFoundException(response, plainAnswer, message, cause)
|
||||||
description.contains("Bad Request: message is not modified") -> MessageIsNotModifiedException(response, plainAnswer, message, cause)
|
description.contains("Bad Request: message is not modified") -> MessageIsNotModifiedException(response, plainAnswer, message, cause)
|
||||||
description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
|
description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
|
||||||
|
description.contains("PHOTO_INVALID_DIMENSIONS") -> InvalidPhotoDimensionsException(response, plainAnswer, message, cause)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
} ?: CommonRequestException(response, plainAnswer, message, cause)
|
} ?: CommonRequestException(response, plainAnswer, message, cause)
|
||||||
@@ -41,3 +42,6 @@ class MessageIsNotModifiedException(response: Response, plainAnswer: String, mes
|
|||||||
|
|
||||||
class MessageToEditNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
class MessageToEditNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||||
RequestException(response, plainAnswer, message, cause)
|
RequestException(response, plainAnswer, message, cause)
|
||||||
|
|
||||||
|
class InvalidPhotoDimensionsException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||||
|
RequestException(response, plainAnswer, message, cause)
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class DeleteMessage(
|
data class DeleteMessage(
|
||||||
@@ -19,7 +16,7 @@ data class DeleteMessage(
|
|||||||
override fun method(): String = "deleteMessage"
|
override fun method(): String = "deleteMessage"
|
||||||
|
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.PossiblyForwardedMessage
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
private val AbleToBeForwardedMessageDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<PossiblyForwardedMessage>()
|
private val AbleToBeForwardedMessageDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<PossiblyForwardedMessage>()
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ExtendedBot
|
|
||||||
import kotlinx.serialization.*
|
|
||||||
|
|
||||||
@Serializable
|
@Deprecated(
|
||||||
class GetMe : SimpleRequest<ExtendedBot> {
|
"Replaced",
|
||||||
override fun method(): String = "getMe"
|
ReplaceWith(
|
||||||
override val resultDeserializer: DeserializationStrategy<ExtendedBot>
|
"GetMe", "com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe"
|
||||||
get() = ExtendedBot.serializer()
|
)
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
)
|
||||||
get() = serializer()
|
typealias GetMe = GetMe
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,18 +3,27 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateSerializerWithoutDeserialization
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateSerializerWithoutSerialization
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.ArrayListSerializer
|
import kotlinx.serialization.builtins.ListSerializer
|
||||||
|
|
||||||
private val updatesListSerializer = ArrayListSerializer(
|
private val updatesListSerializer = ListSerializer(
|
||||||
UpdateSerializerWithoutDeserialization
|
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
|
@Serializable
|
||||||
data class GetUpdates(
|
data class GetUpdates(
|
||||||
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
|
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
|
||||||
val limit: Int? = null,
|
val limit: Int = getUpdatesLimit.last,
|
||||||
val timeout: Seconds? = null,
|
val timeout: Seconds? = null,
|
||||||
val allowed_updates: List<String>? = ALL_UPDATES_LIST
|
val allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||||
): SimpleRequest<List<Update>> {
|
): SimpleRequest<List<Update>> {
|
||||||
@@ -25,4 +34,10 @@ data class GetUpdates(
|
|||||||
|
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (limit !in getUpdatesLimit) {
|
||||||
|
error("GetUpdates request can be called only with limit in range $getUpdatesLimit (actual value is $limit)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
|
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.StringDescriptor
|
|
||||||
|
|
||||||
@Serializable(InputFileSerializer::class)
|
@Serializable(InputFileSerializer::class)
|
||||||
sealed class InputFile {
|
sealed class InputFile {
|
||||||
@@ -22,8 +21,8 @@ fun String.toInputFile() = FileId(this)
|
|||||||
|
|
||||||
@Serializer(InputFile::class)
|
@Serializer(InputFile::class)
|
||||||
internal object InputFileSerializer : KSerializer<InputFile> {
|
internal object InputFileSerializer : KSerializer<InputFile> {
|
||||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(FileId::class.toString())
|
override val descriptor: SerialDescriptor = PrimitiveDescriptor(FileId::class.toString(), PrimitiveKind.STRING)
|
||||||
override fun serialize(encoder: Encoder, obj: InputFile) = encoder.encodeString(obj.fileId)
|
override fun serialize(encoder: Encoder, value: InputFile) = encoder.encodeString(value.fileId)
|
||||||
override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString())
|
override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,8 +33,8 @@ internal object InputFileSerializer : KSerializer<InputFile> {
|
|||||||
@Serializable(InputFileSerializer::class)
|
@Serializable(InputFileSerializer::class)
|
||||||
data class MultipartFile (
|
data class MultipartFile (
|
||||||
val file: StorageFile,
|
val file: StorageFile,
|
||||||
val mimeType: String = file.contentType,
|
val mimeType: String = file.storageFileInfo.contentType,
|
||||||
val filename: String = file.fileName
|
val filename: String = file.storageFileInfo.fileName
|
||||||
) : InputFile() {
|
) : InputFile() {
|
||||||
override val fileId: String = file.generateCustomName()
|
override val fileId: String = file.storageFileInfo.generateCustomName()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,4 @@ interface SimpleRequest<T: Any> : Request<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
inline fun <T: Any, K: SimpleRequest<T>> K.json(): JsonObject = toJsonWithoutNulls(requestSerializer as SerializationStrategy<K>)
|
internal fun <T: Any, K: SimpleRequest<T>> K.json(): JsonObject = toJsonWithoutNulls(requestSerializer as SerializationStrategy<K>)
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.CallbackQuery.CallbackQuery
|
import com.github.insanusmokrassar.TelegramBotAPI.types.CallbackQuery.CallbackQuery
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class AnswerCallbackQuery(
|
data class AnswerCallbackQuery(
|
||||||
@@ -22,7 +21,7 @@ data class AnswerCallbackQuery(
|
|||||||
) : SimpleRequest<Boolean> {
|
) : SimpleRequest<Boolean> {
|
||||||
override fun method(): String = "answerCallbackQuery"
|
override fun method(): String = "answerCallbackQuery"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.serializers.InlineQueryResultSerializer
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.serializers.InlineQueryResultSerializer
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.abstracts.InlineQuery
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.abstracts.InlineQuery
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.ArrayListSerializer
|
import kotlinx.serialization.builtins.ListSerializer
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class AnswerInlineQuery(
|
data class AnswerInlineQuery(
|
||||||
@@ -30,7 +29,7 @@ data class AnswerInlineQuery(
|
|||||||
): SimpleRequest<Boolean> {
|
): SimpleRequest<Boolean> {
|
||||||
override fun method(): String = "answerInlineQuery"
|
override fun method(): String = "answerInlineQuery"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
@@ -52,6 +51,6 @@ fun InlineQuery.createAnswer(
|
|||||||
switchPmParameter
|
switchPmParameter
|
||||||
)
|
)
|
||||||
|
|
||||||
internal object InlineQueryAnswersResultsSerializer: KSerializer<List<InlineQueryResult>> by ArrayListSerializer(
|
internal object InlineQueryAnswersResultsSerializer: KSerializer<List<InlineQueryResult>> by ListSerializer(
|
||||||
InlineQueryResultSerializer
|
InlineQueryResultSerializer
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerPreCheckoutQuery
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerPreCheckoutQuery
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuery
|
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuery
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerShippingQuery
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerShippingQuery
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingOption
|
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingOption
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingQuery
|
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingQuery
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.ArrayListSerializer
|
import kotlinx.serialization.builtins.ListSerializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class AnswerShippingQueryOk(
|
data class AnswerShippingQueryOk(
|
||||||
@@ -22,7 +21,7 @@ data class AnswerShippingQueryOk(
|
|||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ArrayListSerializer(
|
internal object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ListSerializer(
|
||||||
ShippingOption.serializer()
|
ShippingOption.serializer()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abs
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.PreCheckoutQueryId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.PreCheckoutQueryId
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
interface AnswerPreCheckoutQuery : SimpleRequest<Boolean> {
|
interface AnswerPreCheckoutQuery : SimpleRequest<Boolean> {
|
||||||
override fun method(): String = "answerPreCheckoutQuery"
|
override fun method(): String = "answerPreCheckoutQuery"
|
||||||
override val resultDeserializer: KSerializer<Boolean>
|
override val resultDeserializer: KSerializer<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
|
|
||||||
val preCheckoutQueryId: PreCheckoutQueryId
|
val preCheckoutQueryId: PreCheckoutQueryId
|
||||||
val isOk: Boolean
|
val isOk: Boolean
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abs
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ShippingQueryIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ShippingQueryIdentifier
|
||||||
import kotlinx.serialization.DeserializationStrategy
|
import kotlinx.serialization.DeserializationStrategy
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
interface AnswerShippingQuery : SimpleRequest<Boolean> {
|
interface AnswerShippingQuery : SimpleRequest<Boolean> {
|
||||||
override fun method(): String = "answerShippingQuery"
|
override fun method(): String = "answerShippingQuery"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
|
|
||||||
val shippingQueryId: ShippingQueryIdentifier
|
val shippingQueryId: ShippingQueryIdentifier
|
||||||
val isOk: Boolean
|
val isOk: Boolean
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.bot
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ExtendedBot
|
||||||
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
object GetMe : SimpleRequest<ExtendedBot> {
|
||||||
|
override fun method(): String = "getMe"
|
||||||
|
override val resultDeserializer: DeserializationStrategy<ExtendedBot>
|
||||||
|
get() = ExtendedBot.serializer()
|
||||||
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
|
get() = serializer()
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.bot
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.BotCommand
|
||||||
|
import kotlinx.serialization.*
|
||||||
|
import kotlinx.serialization.builtins.ListSerializer
|
||||||
|
|
||||||
|
private val getMyCommandsSerializer = ListSerializer(BotCommand.serializer())
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
object GetMyCommands : SimpleRequest<List<BotCommand>> {
|
||||||
|
override fun method(): String = "getMyCommands"
|
||||||
|
override val resultDeserializer: DeserializationStrategy<List<BotCommand>>
|
||||||
|
get() = getMyCommandsSerializer
|
||||||
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
|
get() = serializer()
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.bot
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
|
import kotlinx.serialization.*
|
||||||
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class SetMyCommands(
|
||||||
|
@SerialName(botCommandsField)
|
||||||
|
val commands: List<BotCommand>
|
||||||
|
) : SimpleRequest<Boolean> {
|
||||||
|
override fun method(): String = "setMyCommands"
|
||||||
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
|
get() = Boolean.serializer()
|
||||||
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
|
get() = serializer()
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (commands.size !in botCommandsLimit) {
|
||||||
|
error("Bot commands list size able to be in range $botCommandsLimit, but incoming size is ${commands.size}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.StringSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ExportChatInviteLink(
|
data class ExportChatInviteLink(
|
||||||
@@ -16,7 +14,7 @@ data class ExportChatInviteLink(
|
|||||||
): ChatRequest, SimpleRequest<String> {
|
): ChatRequest, SimpleRequest<String> {
|
||||||
override fun method(): String = "exportChatInviteLink"
|
override fun method(): String = "exportChatInviteLink"
|
||||||
override val resultDeserializer: DeserializationStrategy<String>
|
override val resultDeserializer: DeserializationStrategy<String>
|
||||||
get() = StringSerializer
|
get() = String.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class LeaveChat(
|
data class LeaveChat(
|
||||||
@@ -16,7 +14,7 @@ data class LeaveChat(
|
|||||||
): ChatRequest, SimpleRequest<Boolean> {
|
): ChatRequest, SimpleRequest<Boolean> {
|
||||||
override fun method(): String = "leaveChat"
|
override fun method(): String = "leaveChat"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ExtendedChatSerializer
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ExtendedChatSerializer
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
@@ -21,13 +19,3 @@ data class GetChat(
|
|||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.getChat(
|
|
||||||
chatId: ChatIdentifier
|
|
||||||
) = execute(GetChat(chatId))
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.getChat(
|
|
||||||
chat: Chat
|
|
||||||
) = getChat(chat.id)
|
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMemberSerializerWithoutDeserialization
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMemberSerializerWithoutDeserialization
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.ArrayListSerializer
|
import kotlinx.serialization.builtins.ListSerializer
|
||||||
|
|
||||||
private val chatMembersListSerializer = ArrayListSerializer(
|
private val chatMembersListSerializer = ListSerializer(
|
||||||
AdministratorChatMemberSerializerWithoutDeserialization
|
AdministratorChatMemberSerializerWithoutDeserialization
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,13 +24,3 @@ data class GetChatAdministrators(
|
|||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.getChatAdministrators(
|
|
||||||
chatId: ChatIdentifier
|
|
||||||
) = execute(GetChatAdministrators(chatId))
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.getChatAdministrators(
|
|
||||||
chat: PublicChat
|
|
||||||
) = getChatAdministrators(chat.id)
|
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.IntSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GetChatMembersCount(
|
data class GetChatMembersCount(
|
||||||
@@ -16,17 +14,7 @@ data class GetChatMembersCount(
|
|||||||
): ChatRequest, SimpleRequest<Int> {
|
): ChatRequest, SimpleRequest<Int> {
|
||||||
override fun method(): String = "getChatMembersCount"
|
override fun method(): String = "getChatMembersCount"
|
||||||
override val resultDeserializer: DeserializationStrategy<Int>
|
override val resultDeserializer: DeserializationStrategy<Int>
|
||||||
get() = IntSerializer
|
get() = Int.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.getChatMembersCount(
|
|
||||||
chatId: ChatIdentifier
|
|
||||||
) = execute(GetChatMembersCount(chatId))
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.getChatMembersCount(
|
|
||||||
chat: PublicChat
|
|
||||||
) = getChatMembersCount(chat.id)
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMemberDeserializationStrategy
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMemberDeserializationStrategy
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -21,27 +19,3 @@ data class GetChatMember(
|
|||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.getChatMember(
|
|
||||||
chatId: ChatIdentifier,
|
|
||||||
userId: UserId
|
|
||||||
) = execute(GetChatMember(chatId, userId))
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.getChatMember(
|
|
||||||
chat: PublicChat,
|
|
||||||
userId: UserId
|
|
||||||
) = getChatMember(chat.id, userId)
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.getChatMember(
|
|
||||||
chatId: ChatId,
|
|
||||||
user: User
|
|
||||||
) = getChatMember(chatId, user.id)
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.getChatMember(
|
|
||||||
chat: PublicChat,
|
|
||||||
user: User
|
|
||||||
) = getChatMember(chat.id, user.id)
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class KickChatMember(
|
data class KickChatMember(
|
||||||
@@ -19,7 +17,7 @@ data class KickChatMember(
|
|||||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||||
override fun method(): String = "kickChatMember"
|
override fun method(): String = "kickChatMember"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class PromoteChatMember(
|
data class PromoteChatMember(
|
||||||
@@ -35,7 +33,7 @@ data class PromoteChatMember(
|
|||||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||||
override fun method(): String = "promoteChatMember"
|
override fun method(): String = "promoteChatMember"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class RestrictChatMember(
|
data class RestrictChatMember(
|
||||||
@@ -22,40 +20,7 @@ data class RestrictChatMember(
|
|||||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||||
override fun method(): String = "restrictChatMember"
|
override fun method(): String = "restrictChatMember"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.restrictChatMember(
|
|
||||||
chatId: ChatIdentifier,
|
|
||||||
userId: UserId,
|
|
||||||
untilDate: TelegramDate? = null,
|
|
||||||
permissions: ChatPermissions = ChatPermissions()
|
|
||||||
) = execute(RestrictChatMember(chatId, userId, untilDate, permissions))
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.restrictChatMember(
|
|
||||||
chat: PublicChat,
|
|
||||||
userId: UserId,
|
|
||||||
untilDate: TelegramDate? = null,
|
|
||||||
permissions: ChatPermissions = ChatPermissions()
|
|
||||||
) = restrictChatMember(chat.id, userId, untilDate, permissions)
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.restrictChatMember(
|
|
||||||
chatId: ChatId,
|
|
||||||
user: User,
|
|
||||||
untilDate: TelegramDate? = null,
|
|
||||||
permissions: ChatPermissions = ChatPermissions()
|
|
||||||
) = restrictChatMember(chatId, user.id, untilDate, permissions)
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.restrictChatMember(
|
|
||||||
chat: PublicChat,
|
|
||||||
user: User,
|
|
||||||
untilDate: TelegramDate? = null,
|
|
||||||
permissions: ChatPermissions = ChatPermissions()
|
|
||||||
) = restrictChatMember(chat.id, user.id, untilDate, permissions)
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
/**
|
|
||||||
* Representation of https://core.telegram.org/bots/api#setchatadministratorcustomtitle
|
|
||||||
*
|
|
||||||
* Please, remember about restrictions for characters in custom title
|
|
||||||
*/
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class SetChatAdministratorCustomTitle(
|
data class SetChatAdministratorCustomTitle(
|
||||||
@SerialName(chatIdField)
|
@SerialName(chatIdField)
|
||||||
@@ -23,7 +16,7 @@ data class SetChatAdministratorCustomTitle(
|
|||||||
) : ChatMemberRequest<Boolean> {
|
) : ChatMemberRequest<Boolean> {
|
||||||
override fun method(): String = "setChatAdministratorCustomTitle"
|
override fun method(): String = "setChatAdministratorCustomTitle"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = RestrictChatMember.serializer()
|
get() = RestrictChatMember.serializer()
|
||||||
|
|
||||||
@@ -33,31 +26,3 @@ data class SetChatAdministratorCustomTitle(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.setChatAdministratorCustomTitle(
|
|
||||||
chatId: ChatId,
|
|
||||||
userId: UserId,
|
|
||||||
customTitle: String
|
|
||||||
) = execute(SetChatAdministratorCustomTitle(chatId, userId, customTitle))
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.setChatAdministratorCustomTitle(
|
|
||||||
chat: PublicChat,
|
|
||||||
userId: UserId,
|
|
||||||
customTitle: String
|
|
||||||
) = setChatAdministratorCustomTitle(chat.id, userId, customTitle)
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.setChatAdministratorCustomTitle(
|
|
||||||
chatId: ChatId,
|
|
||||||
user: User,
|
|
||||||
customTitle: String
|
|
||||||
) = setChatAdministratorCustomTitle(chatId, user.id, customTitle)
|
|
||||||
|
|
||||||
@Deprecated("Deprecated due to extracting into separated library")
|
|
||||||
suspend fun RequestsExecutor.setChatAdministratorCustomTitle(
|
|
||||||
chat: PublicChat,
|
|
||||||
user: User,
|
|
||||||
customTitle: String
|
|
||||||
) = setChatAdministratorCustomTitle(chat.id, user.id, customTitle)
|
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.BooleanSerializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class UnbanChatMember(
|
data class UnbanChatMember(
|
||||||
@@ -16,7 +14,7 @@ data class UnbanChatMember(
|
|||||||
) : ChatMemberRequest<Boolean> {
|
) : ChatMemberRequest<Boolean> {
|
||||||
override fun method(): String = "unbanChatMember"
|
override fun method(): String = "unbanChatMember"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = BooleanSerializer
|
get() = Boolean.serializer()
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user