mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-02 22:59:48 +00:00
replace TelegramBotAPI to the separated subproject
This commit is contained in:
580
TelegramBotAPI/CHANGELOG.md
Normal file
580
TelegramBotAPI/CHANGELOG.md
Normal file
@@ -0,0 +1,580 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 0.23.0 TelegramBotAPI 4.6
|
||||
|
||||
* `Poll` now is sealed class
|
||||
* `RegularPoll` type was added to represent polls with type `regular`
|
||||
* `QuizPoll` type was added to represent polls with type `quiz`
|
||||
* `UnknownPollType` type was added to represent polls which are unknown in current version
|
||||
* `AnonymousPollOption` was renamed to `SimplePollOption`
|
||||
* `SendPoll` was rewritten as sealed class
|
||||
* `SendRegularPoll` was created and represent `sendPoll` method with type `regular`
|
||||
* `SendQuizPoll` was created and represent `sendPoll` method with type `quiz`
|
||||
* `Poll#createRequest` extension was added
|
||||
* `PollAnswerUpdate` type of update was added
|
||||
* `PollAnswer` type was added
|
||||
* `UpdatesFilter` now support work with `PollAnswerUpdate`
|
||||
* `language` field in PreTextSource now correctly passed from telegram MessageEntities
|
||||
* `KeyboardButton` now is sealed class
|
||||
* Fixed problem of incorrect representation of this class (any type of request can be created separately)
|
||||
* Added new types of `KeyboardButton`:
|
||||
* `UnknownKeyboardButton`
|
||||
* `SimpleKeyboardButton`
|
||||
* `RequestContactKeyboardButton`
|
||||
* `RequestLocationKeyboardButton`
|
||||
* `RequestPollKeyboardButton`
|
||||
* Added new type `KeyboardButtonPollType`:
|
||||
* `UnknownKeyboardButtonPollType`
|
||||
* `RegularKeyboardButtonPollType`
|
||||
* `QuizKeyboardButtonPollType`
|
||||
* `User` now is sealed class
|
||||
* `CommonUser` was added as representation of default `User`
|
||||
* `Bot` was added as representation of bot user (it is sealed class)
|
||||
* `ExtendedBot` with additional info
|
||||
* `CommonBot` with simple info
|
||||
* `GetMe` now return `ExtendedBot` object
|
||||
* Now extension `javaLocale` is extension for `CommonUser`
|
||||
|
||||
### 0.23.1
|
||||
|
||||
* Versions updates:
|
||||
* Klock `1.8.6` -> `1.8.7`
|
||||
* Ktor `1.3.0` -> `1.3.1`
|
||||
* Now it is possible to get updates by polling with custom executor engine
|
||||
* `CommonMultipartFileRequest` now is internal
|
||||
* Added `LiveLocation` class for more useful tracking live locations
|
||||
* `InvoiceOfPayment` is renamed to `InvoiceContent` and now is `MessageContent` instead of `PaymentInfo`
|
||||
* `SendInvoice` now return `ContentMessage<InvoiceContent>`
|
||||
* `paymentInfo` inside of `CommonMessageImpl` now can be set only to `SuccessfulPaymentInfo`
|
||||
* Added `RecordVideoNoteAction` and `UploadVideoNoteAction` for `record_video_note` and `upload_video_note` actions
|
||||
* For most part of messages was added `RequestsExecutor` extensions for more useful way of usage
|
||||
* `toInputFile` extensions now will return more exact types
|
||||
* Now it is possible to send broadcast channels size for `FlowsUpdatesFilter`
|
||||
|
||||
### 0.23.2
|
||||
|
||||
* Fixes in `InputMedia` - `media` field was not included to serialization
|
||||
|
||||
## 0.22.0
|
||||
|
||||
* **`KtorCallFactory` must return `HttpStatement` instead of `HttpClientCall`**
|
||||
* `SendMessage` was renamed to `SendTextMessage` and previous `SendMessage` is deprecated
|
||||
* All `AbleToBe*` interfaces was renamed to `Possibly*`
|
||||
* `AbleToBeEditedMessage` -> `PossiblyEditedMessage`
|
||||
* `AbleToBeForwardedMessage` -> `PossiblyForwardedMessage`
|
||||
* `AbleToBeMarkedUp` -> `PossiblyMarkedUp`
|
||||
* `AbleToBeEditedMessage` -> `PossiblyEditedMessage`
|
||||
* `ForwardedMessage` type was renamed to `ForwardInfo`
|
||||
* `AnonymousForwardedMessage` -> `AnonymousForwardInfo`
|
||||
* `UserForwardedMessage` -> `UserForwardInfo`
|
||||
* `ForwardedFromChannelMessage` -> `ForwardFromChannelInfo`
|
||||
* `PossiblyForwardedMessage#forwarded` field now renamed to `forwardInfo`
|
||||
* All serializers in library now are `internal`. **If you have used some of them or I have marked as internal by a
|
||||
mistake - don't hesitate to say this.**
|
||||
* `EditChatMessage` now have generic type and extends `SimpleRequest<ContentMessage<GenericType>>`
|
||||
* `ResendableContent` now extends `Request<out Message>` instead of `Request<Message>`
|
||||
* Most part of requests have changed return type. They are listed below:
|
||||
<details>
|
||||
|
||||
* `ForwardMessage`
|
||||
* `GetChatAdministrators`
|
||||
* `EditChatMessageLiveLocation`
|
||||
* `StopChatMessageLiveLocation`
|
||||
* `EditChatMessageText`
|
||||
* `EditChatMessageCaption`
|
||||
* `EditChatMessageMedia`
|
||||
* `EditChatMessageReplyMarkup`
|
||||
* `SendAnimation`
|
||||
* `SendAudio`
|
||||
* `SendContact`
|
||||
* `SendLocation`
|
||||
* `SendTextMessage`
|
||||
* `SendPoll`
|
||||
* `SendVenue`
|
||||
* `SendGame`
|
||||
* `SendDocument`
|
||||
* `SendMediaGroup`
|
||||
* `SendPhoto`
|
||||
* `SendVideo`
|
||||
* `SendVideoNote`
|
||||
* `SendVoice`
|
||||
* `SendSticker`
|
||||
|
||||
</details>
|
||||
* Changed type of `createResend`
|
||||
<details>
|
||||
|
||||
* `GameContent`
|
||||
* `LocationContent`
|
||||
* `PollContent`
|
||||
* `TextContent`
|
||||
* `VenueContent`
|
||||
* `AnimationContent`
|
||||
* `AudioContent`
|
||||
* `DocumentContent`
|
||||
* `ContactContent`
|
||||
* `PhotoContent`
|
||||
* `VideoContent`
|
||||
* `VideoNoteContent`
|
||||
* `VoiceContent`
|
||||
* `StickerContent`
|
||||
|
||||
</details>
|
||||
* Version updates:
|
||||
* Ktor `1.2.6` -> `1.3.0`
|
||||
|
||||
### 0.22.1 MediaContent#asInputMedia
|
||||
|
||||
* All `MediaContent` instances now can create their `InputMedia` analog
|
||||
* New annotation `PreviewFeature` was added to mark new thing as preview for the time
|
||||
while they can work incorrectly
|
||||
* Added links utils:
|
||||
* `makeLinkToMessage` have two signatures - for direct creating using username and for abstract creating using
|
||||
chat id
|
||||
|
||||
### 0.22.2 CashTag and independent updates handling
|
||||
|
||||
* `cashtag` entity type was added
|
||||
* Several `Unknown*` realizations was added:
|
||||
* `UnknownUpdateType`
|
||||
* `UnknownMessageType`
|
||||
* `UnknownChatType`
|
||||
* `UnknownCallbackQueryType`
|
||||
* `UpdatesFilter` now have one additional income callback: `unknownUpdateTypeCallback`
|
||||
* `createSimpleUpdateFilter` can receive one more callback: `unknownCallback` (for `unknownUpdateTypeCallback`)
|
||||
|
||||
## 0.21.0 TelegramBotAPI 4.5
|
||||
|
||||
* _**All `MessageEntity`'es now are replaced with `TextPart`**_
|
||||
* Added support of strikethrough and underline
|
||||
* Added `UnderlineTextSource`
|
||||
* Added `StrikethroughTextSource`
|
||||
* Added support in `RawMessageEntity`
|
||||
* Added support of `MarkdownV2`
|
||||
* Now will not be thrown exception when there is income unknown type of `RawMessageEntity`. Instead of this will be
|
||||
created `RegularTextSource` with the same text
|
||||
* Fixed problem that usually string formatting did not trigger escaping of control characters
|
||||
* Actualized work with `pre` type of text - now it is possible to use `language` for formatting of text
|
||||
* Removed constructor of `TextMentionTextSource`, which was deprecated previously
|
||||
* All `TelegramMediaFile` instances now have field `fileUniqueId`, which represents `file_unique_id` field from API
|
||||
* Now `ChatPhoto` have two additional fields: `smallFileUniqueId` and `bigFileUniqueId`
|
||||
* Now any administrator object instance have `customTitle` nullable field
|
||||
* Added the new request `SetChatAdministratorCustomTitle` to manage the custom titles of administrators promoted by the
|
||||
bot.
|
||||
* Added the field `slowModeDelay` to the `ExtendedSupergroupChat` objects.
|
||||
|
||||
* `CaptionedInput` now have extension `fullEntitiesList` which will return list of `TextPart` with `RegularSource`'s
|
||||
* `TextPart` added - it will be used as part of some text and can be not related to telegram bot
|
||||
* `MultilevelTextSource` was added - it is type of `TextSource`, which can have subsources as parts of this text
|
||||
* In all `TextSource`s all fields now are lazy for avoiding of potential risk for performance issues
|
||||
|
||||
* Updates in versions:
|
||||
* Coroutines `1.3.2` -> `1.3.3`
|
||||
* Klock `1.8.0` -> `1.8.6`
|
||||
* UUID `0.0.6` -> `0.0.7`
|
||||
|
||||
## 0.20.0 MPP Migration
|
||||
|
||||
* Time library change: `joda-time` -> `com.soywiz.korlibs.klock:klock`
|
||||
* `Currencied` now using as `currency` value with type `String`
|
||||
* For `Java` there is `Currencied#javaCurrency` extension function, which will give an old currency work way
|
||||
* `User` now have no field `userLocale`
|
||||
* For `Java` there is `User#javaLocale` extension function, which will give an old locale work way
|
||||
|
||||
### 0.20.1
|
||||
|
||||
* `User` now implement `PrivateChat`
|
||||
* `TextMentionMessageEntity` now accept `PrivateChat` instead of `User` in main constructor
|
||||
* `TextMentionMessageEntity` now contains not user, but contains `PrivateChat`
|
||||
* Fixed: `TextMentionMessageEntity#asHtmlSource` previously worked incorrect
|
||||
* Abstraction `TextSource`
|
||||
* `MessageEntity` now extends `TextSource`
|
||||
* `createFormattedText` method now accept `List<TextSource>`
|
||||
* `createHtmlText` method now accept `List<TextSource>`
|
||||
* `createMarkdownText` method now accept `List<TextSource>`
|
||||
* A lot of `TextSource` implementors was added. More info [here](src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/)
|
||||
* All `MessageEntity` implementations now are using new `TextSource` analogues as delegates
|
||||
|
||||
### 0.20.2
|
||||
|
||||
* New exception type `MessageIsNotModifierException` was added
|
||||
* New exception type `MessageToEditNotFoundException` was added
|
||||
* Now exceptions in requests will be caught correctly
|
||||
|
||||
### 0.20.3
|
||||
|
||||
* Now `LeftChatMamber` is a `CommonEvent`
|
||||
|
||||
### 0.20.4
|
||||
|
||||
* Now `setWebhook` supports setting up of path for listening
|
||||
* Now `setWebhook` supports custom listen address even if certificate was not provided
|
||||
|
||||
## 0.19.0 ImplicitReflection removing
|
||||
|
||||
* Total rework of serialization for requests. Now all `SimpleRequest` children have:
|
||||
* `requestSerializer` - field, which must provide serializer of current type
|
||||
* `resultDeserializer` - field, which must provide opportunity to deserializer result. Previously it was a function
|
||||
* Removed deprecations:
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.WebhookPrivateKeyConfig`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.UpdatesFilter`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.createSimpleUpdateFilter`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.createMarkdownText`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaption`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownText`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.KtorUpdatesPoller`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.message.CommonForwardedMessage`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.CaptionedInputMedia`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.games.Game#text`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.games.Game#textEntities`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.files.PathedFileKt.makeFileUrl`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.files.PathedFileKt.downloadingFilesBaseUrl`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.Data`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByInlineMessageId`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByMessageId`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.RequestException`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.ReplyMessageNotFound`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.BaseRequestsExecutor#baseUrl`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.BaseRequestsExecutor#constructor(token, hostUrl)`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorRequestsExecutor#constructor(token, client, hostUrl, callsFactories, excludeDefaultFactories, requestsLimiter, jsonFormatter)`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorRequestsExecutor#constructor(token, engine, hostUrl)`
|
||||
|
||||
## 0.18.0 Raws cleaning
|
||||
|
||||
* Made internal and not available outside of library:
|
||||
* `RawMessage`
|
||||
* `RawUpdate`
|
||||
* `RawChatMember`
|
||||
* `RawMessageEntity`
|
||||
* `RawInlineQuery`
|
||||
* `RawCallbackQuery`
|
||||
* `RawChosenInlineResult`
|
||||
|
||||
* All `RawMessage` usages was replaced with `Message` interface (with some of other raw classes was made the same things)
|
||||
* `TelegramBotAPIMessageDeserializationStrategy` was created. It was used for deserialization of Telegram Bot API
|
||||
incoming messages
|
||||
* `TelegramBotAPIMessageDeserializeOnlySerializer` was created. It **MUST NOT** be used to serialize messages
|
||||
* Update of description
|
||||
* Make `Game` object a little bit more standartizated
|
||||
* `Game` now is not serializable and have no additional trash, related to serialization
|
||||
* `TelegramFile` was removed
|
||||
|
||||
### 0.18.1 Libraries update
|
||||
|
||||
* Update libraries:
|
||||
* `kotlin`: 1.3.41 -> 1.3.61
|
||||
* `kotlin coroutines`: 1.2.2 -> 1.3.2
|
||||
* `kotlin serialization`: 0.11.1 -> 0.14.0
|
||||
* `joda time`: 2.10.3 -> 2.10.5
|
||||
* `ktor`: 1.2.3 -> 1.2.6
|
||||
* `BotAction` now will be deserialized in a little bit other way
|
||||
* `BotActionSerializer` now is internal
|
||||
* Most part of serializers now are objects (instead of classes as was previously)
|
||||
|
||||
## 0.17.0 July 29, 2019 API Update
|
||||
|
||||
Libraries updates:
|
||||
|
||||
* Kotlin version `1.3.31` -> `1.3.41`
|
||||
* Kotlin Coroutines version `1.2.1` -> `1.2.2`
|
||||
* Kotlin Serialization version `0.11.0` -> `0.11.1`
|
||||
* Joda Time version `2.10.1` -> `2.10.3`
|
||||
* ktor version `1.1.4` -> `1.2.3`
|
||||
|
||||
Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegram.org/bots/api#july-29-2019):
|
||||
|
||||
* `Sticker` and `StickerSet` now have field `isAnimated`
|
||||
* `ChatPermissions` object was added, `GroupChat` interface got `permissions` field, request `SetChatPermissions` was added
|
||||
* `GroupChat` object now have no field `allMembersAreAdmins`
|
||||
* `SpecialRightsChatMember` was added for administrators and restricted members rights union, chat members abstractions
|
||||
was replaced into `abstracts` package and available permissions was updated
|
||||
* `RestrictChatMember` request now accept `permissions` object instead of separated permissions
|
||||
* All `GroupChat` instances have description
|
||||
|
||||
Other important changes:
|
||||
|
||||
* Totally reworked chats hierarchy. `Extended` abstractions was added for cases when called `GetChat` request
|
||||
* `RawChat` boilerplate was removed and replaced by serializers
|
||||
* `BotCommandMessageEntity#command` will not contain `/`/`!` parts and also will cut outside of command begin token (`/`
|
||||
or `!`) and username token (`@`) or end of command (any space character)
|
||||
* `RequestsExecutor` now is `Closeable`
|
||||
* `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things
|
||||
like this
|
||||
|
||||
## 0.16.0 Bot API 4.3
|
||||
|
||||
* `LoginURL` and `LoginURLInlineKeyboardButton` has been added
|
||||
* `replyMarkup` field was added to the `CommonMessage` objects via `AbleToBeMarkedUp` interface
|
||||
* `SwitchInlineQueryCurrentChatInlineKeyboardButton#switchInlineQueryCurrentChat` field fixed
|
||||
* `InlineKeyboardButton` now is sealed class and all its possible realisations are inside of its class file
|
||||
* `String#asUsername` method renamed to `String#toUsername`
|
||||
* Several `toChatId` extensions added
|
||||
|
||||
### 0.16.1
|
||||
|
||||
* Now old uncommon `CaptionedMediaContent` and `CaptionedInputMedia` are replaced by almost the same
|
||||
interfaces `CaptionedInput` and `CaptionedOutput`. They are both implementing `Captioned` interface
|
||||
* `AnimationContent` now is `CaptionedInput`
|
||||
|
||||
## 0.15.0
|
||||
|
||||
* Old `UpdatesPoller` removed (was deprecated)
|
||||
* `UpdatesPoller` renamed to `KtorUpdatesPoller`
|
||||
* Now `KtorUpdatesPoller` do not use additional delay between requests and await answer from Telegram all timeout time
|
||||
* Added abstraction `UpdatesPoller`
|
||||
* Changed signature of the most count of `startGettingOfUpdates`:
|
||||
* They are not `suspend` for now
|
||||
* They are return `UpdatesPoller`
|
||||
* They are using `timeoutMillis` instead of `requestsDelayMillis`
|
||||
* Added `CIO` ktor client engine as lightweight default engine for long-polling
|
||||
|
||||
## 0.14.0
|
||||
|
||||
* Now library have no default engine for both webhooks and requests executor. It is required for clients to set
|
||||
some default library
|
||||
* All proxy help methods was removed . They are will be replaced in separated project
|
||||
* `Ktor` version `1.1.3` -> `1.1.4`
|
||||
* Requests results now always decoding as `UTF-8`
|
||||
* `AbstractRequestCallFactory` was added with cache of methods urls to avoid memory leaks
|
||||
* Small refactoring of work with response in `KtorRequestsExecutor`
|
||||
* Kotlin version `1.3.30` -> `1.3.31`
|
||||
* Kotlin coroutines `1.2.0` -> `1.2.1`
|
||||
* `CommonForwardedMessage` was renamed to `UserForwardedMessage`
|
||||
* All forwarded messages are now just childs of `ForwardedMessage`:
|
||||
* `AnonymousForwardedMessage` - for messages without forwarded info
|
||||
* `UserForwardedMessage` - for messages from users and groups (contains not message id)
|
||||
* `ForwardedFromChannelMessage` - for messages from channels
|
||||
* Changed logic of forwarded messages preparing
|
||||
|
||||
### 0.14.1
|
||||
|
||||
* Replace `UpdatesFilter` and `UpdatesPoller` into another package
|
||||
* Replace `WebhookPrivateKeyConfig`
|
||||
* Added `FlowsUpdatesFilter`
|
||||
* `UpdatesFilter` now have additional callback for polls
|
||||
* `StopPoll#replyMarkup` now is optional
|
||||
|
||||
### 0.14.2 MediaGroups edit hotfixes
|
||||
|
||||
* `convertWithMediaGroupUpdates` extension added
|
||||
* All media group converting extensions are internal for now
|
||||
* Fixes according to updates in converting of updates to media group updates
|
||||
|
||||
## 0.13.0 Telegram Polls
|
||||
|
||||
* Type `PollOption` and `AnonymousPollOption` added
|
||||
* Type `Poll` added
|
||||
* Type `PollUpdate` added and implemented in `RawUpdate`. Now `PollUpdate` can be retrieved from `RawUpdate`
|
||||
* Type `PollContent` added - now it can be a value of `ContentMessage#content`
|
||||
* Request `SendPoll` added and `PollContent#createResend` now use it
|
||||
* `ByInlineMessageId` is deprecated (use `InlineMessageAction` instead)
|
||||
* `ByMessageId` is deprecated (use `MessageAction` instead)
|
||||
* Most part of requests which are working with identifiers of messages now implement `MessageAction` directly or
|
||||
by their parents
|
||||
* `StopPoll` implemented
|
||||
* All current `Chat` abstractions are deprecated and rewritten as typealiases. Use `Chat` abstractions from
|
||||
`com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts` package
|
||||
* Common Groups now may have pinned message
|
||||
* `is_member` field added into `RestrictedChatMember`
|
||||
* **BREAK CHANGES** Now `ForwardedMessages` can be `AnonymousForwardedMessage` and `PublicForwardedMessage`. Old
|
||||
implementations now extend `PublicForwardedMessage`
|
||||
|
||||
## 0.12.0 Webhooks
|
||||
|
||||
* Added `DataRequest` interface which replace `Data` interface
|
||||
* `MultipartRequestImpl` now use `DataRequest`
|
||||
* All requests which implements `Data` now implement `DataRequest`
|
||||
* Added class `SetWebhook` and its factory
|
||||
* Added class `UpdatesFilter` which can help to filter updates by categories
|
||||
* Added function `accumulateByKey` which work as debounce for keys and send list of received values
|
||||
* Added webhooks functions and workaround for `Reverse Proxy` mode
|
||||
* Added new type of updates `MediaGroupUpdate`, which can be received only from filters
|
||||
* `UpdatesFilter` now use new type of updates for mediagroups
|
||||
* Add `GetWebhookInfo` request and `WebhookInfo` type
|
||||
* Replace updates types into separated place in types
|
||||
* Now default `RequestException` will contain plain answer from telegram
|
||||
* Added `UnauthorizedException`
|
||||
* `RequestException` now is sealed
|
||||
* Rename `ReplyMessageNotFound` to `ReplyMessageNotFoundException`
|
||||
* Added `List<BaseMessageUpdate>#mediaGroupId` extension
|
||||
* Added utility `T#asReference(): WeakReference(T)` extension
|
||||
* Added `UpdatesPoller` class which can be instantiated for manage updates polling
|
||||
* Separated execute extensions (now they are in file `Executes`) and poller creating extensions
|
||||
* `BaseMessageUpdate#toMediaGroupUpdate()` will also check condition when update-receiver already is `MediaGroupUpdate`
|
||||
|
||||
### 0.12.1 Hotfix for media groups
|
||||
|
||||
* Added additional media group types (like `MessageMediaGroupUpdate`)
|
||||
* Fixed handling of media group updates in `UpdatesFilter`
|
||||
|
||||
### 0.12.2
|
||||
|
||||
* New in `MediaGroupUpdate`:
|
||||
* It is subtype of `Update` and can be use as regular update with list of messages
|
||||
* Data now is list with `MediaGroupMessage`
|
||||
* Added field `origins` which represent origin updates for `MediaGroupMessage`
|
||||
* `updateId` now represent LAST id of origins updates
|
||||
* `UpdatesFilter` and other objects now work with `UpdateReceiver<Update>` as common supertype
|
||||
for receivers.
|
||||
|
||||
### 0.12.3 Cleaning
|
||||
|
||||
* Refactor, optimizing and cleaning of code
|
||||
* Removed deprecated method `T#toJsonWithoutNulls()`
|
||||
* Renamed instances of `MediaGroupMessage`s and refactored their interfaces. `ChannelMediaGroupMessage`
|
||||
will not contain `user` field (but `CommonMediaGroupMessage` will have)
|
||||
* Now `MediaCollectionContent` is `MediaContent` (classes of this interface must choose best
|
||||
media for present out)
|
||||
* `PhotoContent` now choose biggest photo size from its collection as `media`
|
||||
* Fix in order of media group messages which was received by webhooks
|
||||
|
||||
### 0.12.4
|
||||
|
||||
* Optimized preparing of media group in `UpdatesPoller`
|
||||
* Add `CommonLimiter`
|
||||
* Add `MessageEntity#asHtmlSource` and `String#toHtml`
|
||||
* Add tools for work with html captions and texts
|
||||
* `MessageContent` which using captions or text now have default parse mode `HTMLParseMode` due to issue with escaping
|
||||
of `]` in links titles
|
||||
* Added `Markdown` and `HTML` type aliases which actually means `MarkdownParseMode` and `HTMLParseMode`
|
||||
* `ChatId` now have extension `link` which will automatically create link like `tg://user?id=<chatId>`
|
||||
* Created a few of methods for all supported formats of text like bold, italic, links and others
|
||||
* Rewritten `MessageEntities` to use new formatting options
|
||||
|
||||
### 0.12.5 `MediaContent` improvements
|
||||
|
||||
* Now `MediaGroupContent` is `MediaContent`
|
||||
* All `MedaContent` now have no generics and have basic `TelegramMediaFile` media field
|
||||
|
||||
### 0.12.6 Libraries updates
|
||||
|
||||
* `kotlin` version `1.3.21` -> `1.3.30`
|
||||
* `kotlin coroutines` version `1.1.1` -> `1.2.0`
|
||||
* `kotlin serialization` version `0.10.0` -> `0.11.0`
|
||||
* `ktor` version `1.1.2` -> `1.1.3`
|
||||
* Added `DeleteWebhook` request
|
||||
* All default `startGettingOfUpdates` (in fact - method `start` of `UpdatesPoller`) are suspend and
|
||||
will try to delete webhook
|
||||
|
||||
### 0.12.7 Hotfix version
|
||||
|
||||
* Now temporary all requests of input media will contains `file` field
|
||||
|
||||
## 0.11.0
|
||||
|
||||
* Kotlin `1.3.11` -> `1.3.21`
|
||||
* Kotlin coroutines `1.1.0` -> `1.1.1`
|
||||
* Kotlin serialization `0.9.1` -> `0.10.0`
|
||||
* Ktor `1.1.1` -> `1.1.2`
|
||||
|
||||
## 0.10.0
|
||||
|
||||
* Most part of abstractions was replaced from `requests` and `types` on more high level
|
||||
* Added abstraction `CommonVenueData`
|
||||
* Added abstraction `CommonContactData`
|
||||
* Added `InputMessageContent`
|
||||
* Update some types and requests according to abstractions replacing
|
||||
* Add all `InlineQueryResult`, `InputMessageContent` and other inline mode types
|
||||
* Fixes in edition of inline messages and their result types
|
||||
* Replace basic exception and add `ReplyMessageNotFound` exception
|
||||
|
||||
### 0.10.1
|
||||
|
||||
* Change algorithm of `executeUnsafe`: now it use loop instead of recursive calling
|
||||
* Add additional `startGettingUpdates` with better management of received updates for media groups
|
||||
* Now `MediaGroupMessage` is `CommonMessage` with `MediaGroupContent` content
|
||||
* Added extensions `replyTo`, `forwarded` and `chat` for `List<BaseMessageUpdated>` for comfortable
|
||||
work with media groups lists
|
||||
* Fix `parseMode` of `InputTextMessageContent`
|
||||
|
||||
### 0.10.2
|
||||
|
||||
* Fixes in `Username`
|
||||
* Now you can create username object using string which is not starting with `@`
|
||||
* Now `Username` correctly comparing with strings, which are not starting with `@`
|
||||
* Now most part of usernames in library have type `Username`
|
||||
* Fix `replyMarkup` in `InlineQueryResultArticle`
|
||||
|
||||
### 0.10.3
|
||||
|
||||
* Hotfix for username data class
|
||||
|
||||
## 0.9.0
|
||||
|
||||
* Old extension `OkHttpClient.Builder#useWith` now deprecated and must be replaced by the same in
|
||||
`com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor` package
|
||||
* Replace `ProxySettings` data class in `settings` package, deprecate old link
|
||||
* `BaseRequestsExecutor` now have no it's own scope
|
||||
* Add `RequestLimiter` and base realisations
|
||||
* Now `KtorRequestsExecutor` can receive as one of parameters `RequestLimiter` (by default - `EmptyLimiter`)
|
||||
|
||||
### 0.9.1
|
||||
|
||||
* Updated built-in lengths restrictions
|
||||
* Apply restrictions of text limit for sending messages
|
||||
* Add `RegularTextMessageEntity` which is useful for representing regular text message entity
|
||||
* Add `convertToFullMessageEntityList` which create list of entities with `RegularTextMessageEntity` on places where
|
||||
must be regular text
|
||||
* Change signature of `createMarkdownText`: now it will return list of strings
|
||||
* Deprecate old signatures of `createMarkdownText`, `toMarkdownCaption`, `toMarkdownText`
|
||||
* Add `ResendableContent#createResends` which create adapted list of resends for content
|
||||
* Add `TextContent` own `createResends` realisation
|
||||
|
||||
### 0.9.2
|
||||
|
||||
* `RequestsExecutor#executeAsync(Request, CoroutineScope)` now will return `Deferred` for cases when you need result
|
||||
* `RequestsExecutor#executeUnsafe` will automatically retry request if it was unsuccessful and retries > 0
|
||||
|
||||
### 0.9.3
|
||||
|
||||
* `KtorRequestsExecutor` now can use custom `JSON` string formatter (by default - non strict)
|
||||
* `ResponseParameters` renamed to `Response`
|
||||
* Add `RequestError` sealed class and described in documentation known errors
|
||||
* Add `ResponseParametersRaw` which can create error based on input parameters
|
||||
* Add `parameters` field in `Response` and remove useless fields from `Response`
|
||||
* Add `leftToRetry` parameter in `RetryAfterError`
|
||||
* Add handling of `RetryAfterError` in `KtorRequestsExecutor`
|
||||
|
||||
### 0.8.5
|
||||
|
||||
* Add extension `String#toMarkdown`
|
||||
* Fix of inserting of text when create Markdown-adapted text from text and text entities
|
||||
* Fix default realisation of MessageEntity#asMarkdownSource
|
||||
|
||||
### 0.8.4
|
||||
|
||||
* Added `createMarkdownText` and extensions for `CaptionedMediaContent` and `TextContent`
|
||||
* Added `ResendableContent` and realize in different contents
|
||||
* Animation
|
||||
* Audio
|
||||
* Document
|
||||
* Photo
|
||||
* Sticker
|
||||
* Video
|
||||
* VideoNote
|
||||
* Voice
|
||||
* `MessageContent` now is `ResendableContent`
|
||||
* Now all media sending factories which contains `thumb` have default `null` value
|
||||
* `ChatIdentifier` classes now are `data` classes
|
||||
* Now `MediaGroupContent` interface contains `toMediaGroupMemberInputMedia` method for easily creating mirror input media
|
||||
* Change signature of `Update`
|
||||
* Now `Update` is untyped and data is `Any`
|
||||
* Media groups now are separated type of updates and you can subscribe on that receiving directly
|
||||
* Now `AdministratorChatMember` is interface and `CreatorChatMember` implement it
|
||||
|
||||
### 0.8.3
|
||||
|
||||
* Now `ForwardedMessage` contains nullable `from`
|
||||
|
||||
### 0.8.2
|
||||
|
||||
* Add `FromUserMessage` which must be implemented in all messages realisations which have `user` field
|
||||
* Add `CommonMediaGroupMessage` which in fact extension of `MediaGroupMessage` with implementation of `FromUserMessage`
|
||||
* `CommonMessageImpl` now implementing `FromUserMessage`
|
||||
|
||||
### 0.8.1
|
||||
|
||||
* Update `MediaGroupMessage` interface
|
||||
* Add implementation of `MediaGroupMessage`
|
||||
* Add generating of `MediaGroupMessage` in `RawMessage`
|
208
TelegramBotAPI/README.md
Normal file
208
TelegramBotAPI/README.md
Normal file
@@ -0,0 +1,208 @@
|
||||
# TelegramBotAPI
|
||||
|
||||
[](https://github.com/KotlinBy/awesome-kotlin)
|
||||
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion)
|
||||
[](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI)
|
||||
[](https://jenkins.insanusmokrassar.com/job/TelegramBotAPI_master__publishing/)
|
||||
|
||||
## What is it?
|
||||
|
||||
Library for Object-Oriented and type-safe work with Telegram Bot API. Most part of some specific solves or unuseful
|
||||
moments are describing by official [Telegram Bot API](https://core.telegram.org/bots/api).
|
||||
|
||||
## Compatibility
|
||||
|
||||
This version compatible with [23th of January 2020 update of TelegramBotAPI (version 4.6)](https://core.telegram.org/bots/api#january-23-2020).
|
||||
There is Telegram Passport API exception of implemented functionality, which was presented in
|
||||
[August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api-changelog#august-27-2018) update. It will be implemented
|
||||
as soon as possible. All APIs that are not included are presented
|
||||
[wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Not-included-API).
|
||||
|
||||
## How to implement library?
|
||||
|
||||
Common ways to implement this library are presented here. In some cases it will require additional steps
|
||||
like inserting of additional libraries (like `kotlin stdlib`). In the examples will be used variable
|
||||
`telegrambotapi.version`, which must be set up by developer. Available versions are presented on
|
||||
[bintray](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI), next version is last published:
|
||||
|
||||
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion)
|
||||
|
||||
Currently, last versions of library can be available from the Maven repository with errors (for the reason difficult in publishing
|
||||
of signed artifacts in Bintray). You can:
|
||||
|
||||
* Use earlier version (available version you can find
|
||||
[here](https://mvnrepository.com/artifact/com.github.insanusmokrassar/TelegramBotAPI))
|
||||
* Add `jCenter` repository in build config
|
||||
|
||||
### Maven
|
||||
|
||||
Dependency config presented here:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.insanusmokrassar</groupId>
|
||||
<artifactId>TelegramBotAPI</artifactId>
|
||||
<version>${telegrambotapi.version}</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle
|
||||
|
||||
To use last versions you will need to add one line in repositories block of your `build.gradle`:
|
||||
|
||||
`jcenter()` or `mavenCentral()`
|
||||
|
||||
And add next line to your dependencies block:
|
||||
|
||||
```groovy
|
||||
implementation "com.github.insanusmokrassar:TelegramBotAPI:$telegrambotapi_version"
|
||||
```
|
||||
|
||||
or for old gradle:
|
||||
|
||||
```groovy
|
||||
compile "com.github.insanusmokrassar:TelegramBotAPI:$telegrambotapi_version"
|
||||
```
|
||||
|
||||
## How to work with library?
|
||||
|
||||
For now, this library have no some API god-object. Instead of this, this library has several
|
||||
important objects:
|
||||
|
||||
* [RequestsExecutor](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt)
|
||||
* [Requests](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests)
|
||||
* [Types](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types)
|
||||
|
||||
### Types
|
||||
|
||||
Types declare different objects representation. For example, `Chat` for now represented as
|
||||
interface and has several realisations:
|
||||
|
||||
* `PrivateChat`
|
||||
* `GroupChat`
|
||||
* `SupergroupChat`
|
||||
* `ChannelChat`
|
||||
|
||||
Instead of common garbage with all information as in original [Chat](https://core.telegram.org/bots/api#chat),
|
||||
here it was separated for more obvious difference between chats types and their possible content.
|
||||
|
||||
The same principle work with a lot of others things in this Telegram bot API.
|
||||
|
||||
### Requests
|
||||
|
||||
Requests usually are very simple objects, but some of them are using their own
|
||||
build factories. For example, the next code show, how to get information about bot:
|
||||
|
||||
```kotlin
|
||||
val requestsExecutor: RequestsExecutor = ...
|
||||
requestsExecutor.execute(GetMe())
|
||||
```
|
||||
|
||||
Or you can use new syntax:
|
||||
|
||||
```kotlin
|
||||
val bot: RequestsExecutor = ...
|
||||
bot.getMe()
|
||||
```
|
||||
|
||||
The result type of [GetMe (and getMe extension)](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt)
|
||||
request is
|
||||
[ExtendedBot](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt).
|
||||
|
||||
### RequestsExecutor
|
||||
|
||||
It is base object which can be used to execute requests in API. For now by default included Ktor
|
||||
realisation of `RequestsExecutor`, but it is possible, that in future it will be extracted in separated
|
||||
project. How to create `RequestsExecutor`:
|
||||
|
||||
```kotlin
|
||||
val requestsExecutor = KtorRequestsExecutor(
|
||||
TelegramAPIUrlsKeeper(TOKEN)
|
||||
)
|
||||
```
|
||||
|
||||
Here:
|
||||
|
||||
* `KtorRequestsExecutor` - default realisation with [ktor](https://ktor.io)
|
||||
* `TelegramAPIUrlsKeeper` - special keeper, which you can save and use for getting files full urls (`resolveFileURL`
|
||||
extension inside of `PathedFile.kt`)
|
||||
* `TOKEN` is just a token of bot which was retrieved according to
|
||||
[instruction](https://core.telegram.org/bots#3-how-do-i-create-a-bot).
|
||||
|
||||
By default, for JVM there is implemented `CIO` client engine, but there is not server engine. Both can be changed like
|
||||
here:
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
// ...
|
||||
implementation "io.ktor:ktor-server-cio:$ktor_version" // for implementing of server engine
|
||||
implementation "io.ktor:ktor-client-okhttp:$ktor_version" // for implementing of additional client engine
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
You can avoid using of `server` dependency in case if you will not use `Webhook`s. In this case,
|
||||
dependencies list will be simplify:
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
// ...
|
||||
implementation "io.ktor:ktor-client-okhttp:$ktor_version" // for implementing of additional client engine
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Here was used `okhttp` realisation of client, but there are several others engines for Ktor. More information
|
||||
available on ktor.io site for [client](https://ktor.io/clients/http-client/engines.html) and [server](https://ktor.io/quickstart/artifacts.html)
|
||||
engines.
|
||||
|
||||
## 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/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
|
81
TelegramBotAPI/build.gradle
Normal file
81
TelegramBotAPI/build.gradle
Normal file
@@ -0,0 +1,81 @@
|
||||
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 = "com.github.insanusmokrassar"
|
||||
|
||||
apply from: "publish.gradle"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js()
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
||||
|
||||
api "com.soywiz.korlibs.klock:klock:$klock_version"
|
||||
api "com.benasher44:uuid:$uuid_version"
|
||||
|
||||
api "io.ktor:ktor-client-core:$ktor_version"
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-common')
|
||||
implementation kotlin('test-annotations-common')
|
||||
}
|
||||
}
|
||||
|
||||
jvmMain {
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
||||
|
||||
api "io.ktor:ktor-client:$ktor_version"
|
||||
api "io.ktor:ktor-server:$ktor_version"
|
||||
|
||||
api "io.ktor:ktor-server-host-common:$ktor_version"
|
||||
api "io.ktor:ktor-client-cio:$ktor_version"
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
|
||||
jsMain {
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version"
|
||||
api "io.ktor:ktor-client-js:$ktor_version"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
TelegramBotAPI/maven.publish.gradle
Normal file
57
TelegramBotAPI/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 "Library for Object-Oriented and type-safe work with Telegram Bot API"
|
||||
name "Telegram Bot API"
|
||||
url "https://insanusmokrassar.github.io/TelegramBotAPI"
|
||||
|
||||
scm {
|
||||
developerConnection "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
|
||||
url "https://github.com/insanusmokrassar/TelegramBotAPI.git"
|
||||
}
|
||||
|
||||
developers {
|
||||
|
||||
developer {
|
||||
id "InsanusMokrassar"
|
||||
name "Ovsiannikov Aleksei"
|
||||
email "ovsyannikov.alexey95@gmail.com"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
licenses {
|
||||
|
||||
license {
|
||||
name "Apache Software License 2.0"
|
||||
url "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
TelegramBotAPI/mpp_publish_template.json
Normal file
1
TelegramBotAPI/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","description":"Library for Object-Oriented and type-safe work with Telegram Bot API","url":"https://insanusmokrassar.github.io/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}
|
55
TelegramBotAPI/publish.gradle
Normal file
55
TelegramBotAPI/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,18 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.fullListOfSubSource
|
||||
|
||||
interface Captioned {
|
||||
val caption: String?
|
||||
}
|
||||
|
||||
interface CaptionedOutput : Captioned {
|
||||
val parseMode: ParseMode?
|
||||
}
|
||||
|
||||
interface CaptionedInput : Captioned {
|
||||
val captionEntities: List<TextPart>
|
||||
}
|
||||
|
||||
fun CaptionedInput.fullEntitiesList() = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList()
|
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
interface CommonContactData {
|
||||
val phoneNumber: String
|
||||
val firstName: String
|
||||
val lastName: String?
|
||||
val vcard: String? // TODO:: Replace by some vCard abstraction
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
interface CommonVenueData : Titled {
|
||||
override val title: String
|
||||
val address: String
|
||||
val foursquareId: String?
|
||||
val foursquareType: String? // TODO:: Rewrite with enum or interface
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
interface Livable {
|
||||
/**
|
||||
* Period in SECONDS
|
||||
*/
|
||||
val livePeriod: Int?
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
interface Locationed {
|
||||
val latitude: Double
|
||||
val longitude: Double
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
interface MimeTyped {
|
||||
val mimeType: String? // TODO::replace by something like enum or interface
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
interface Performerable {
|
||||
val performer: String?
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
interface TextSource {
|
||||
val asMarkdownSource: String
|
||||
val asMarkdownV2Source: String
|
||||
val asHtmlSource: String
|
||||
}
|
||||
|
||||
|
||||
interface MultilevelTextSource : TextSource {
|
||||
val textParts: List<TextPart>
|
||||
}
|
||||
|
||||
data class TextPart(
|
||||
val range: IntRange,
|
||||
val source: TextSource
|
||||
)
|
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
interface Titled {
|
||||
val title: String?
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
|
||||
interface ChatRequest {
|
||||
val chatId: ChatIdentifier
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
|
||||
|
||||
interface DisableNotification {
|
||||
val disableNotification: Boolean
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
|
||||
|
||||
interface DisableWebPagePreview {
|
||||
val disableWebPagePreview: Boolean?
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier
|
||||
|
||||
interface InlineMessageAction {
|
||||
val inlineMessageId: InlineMessageIdentifier
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
|
||||
interface MessageAction: ChatRequest {
|
||||
val messageId: MessageIdentifier
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
|
||||
interface ReplyMarkup {
|
||||
val replyMarkup: KeyboardMarkup?
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
|
||||
interface ReplyMessageId {
|
||||
val replyToMessageId: MessageIdentifier?
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.TelegramDate
|
||||
|
||||
interface UntilDate {
|
||||
val untilDate: TelegramDate?
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
|
||||
abstract class BaseRequestsExecutor(
|
||||
protected val telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
||||
) : RequestsExecutor
|
@@ -0,0 +1,13 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.statement.HttpStatement
|
||||
|
||||
interface KtorCallFactory {
|
||||
suspend fun <T: Any> prepareCall(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
) : HttpStatement?
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.BaseRequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.MultipartRequestCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.SimpleRequestCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.newRequestException
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.EmptyLimiter
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.RequestLimiter
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.receive
|
||||
import io.ktor.client.features.ClientRequestException
|
||||
import io.ktor.client.statement.HttpStatement
|
||||
import io.ktor.client.statement.readText
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class KtorRequestsExecutor(
|
||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||
private val client: HttpClient = HttpClient(),
|
||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||
excludeDefaultFactories: Boolean = false,
|
||||
private val requestsLimiter: RequestLimiter = EmptyLimiter,
|
||||
private val jsonFormatter: Json = Json.nonstrict
|
||||
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
||||
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
||||
if (!excludeDefaultFactories) {
|
||||
asSequence().plus(SimpleRequestCallFactory()).plus(MultipartRequestCallFactory()).toList()
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||
return requestsLimiter.limit {
|
||||
var statement: HttpStatement? = null
|
||||
for (factory in callsFactories) {
|
||||
statement = factory.prepareCall(
|
||||
client,
|
||||
telegramAPIUrlsKeeper.commonAPIUrl,
|
||||
request
|
||||
)
|
||||
if (statement != null) {
|
||||
break
|
||||
}
|
||||
}
|
||||
try {
|
||||
val response = statement ?.execute() ?: throw IllegalArgumentException("Can't execute request: $request")
|
||||
val content = response.receive<String>()
|
||||
val responseObject = jsonFormatter.parse(Response.serializer(), content)
|
||||
|
||||
(responseObject.result?.let {
|
||||
jsonFormatter.fromJson(request.resultDeserializer, it)
|
||||
} ?: responseObject.parameters?.let {
|
||||
val error = it.error
|
||||
if (error is RetryAfterError) {
|
||||
delay(error.leftToRetry)
|
||||
execute(request)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?: response.let {
|
||||
throw newRequestException(
|
||||
responseObject,
|
||||
content,
|
||||
"Can't get result object from $content"
|
||||
)
|
||||
})
|
||||
} 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"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
client.close()
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.HttpStatement
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.HttpMethod
|
||||
import kotlin.collections.set
|
||||
|
||||
abstract class AbstractRequestCallFactory : KtorCallFactory {
|
||||
private val methodsCache: MutableMap<String, String> = mutableMapOf()
|
||||
override suspend fun <T : Any> prepareCall(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
): HttpStatement? {
|
||||
val preparedBody = prepareCallBody(client, baseUrl, request) ?: return null
|
||||
|
||||
return HttpStatement(
|
||||
HttpRequestBuilder().apply {
|
||||
url(
|
||||
methodsCache[request.method()] ?: "$baseUrl/${request.method()}".also {
|
||||
methodsCache[request.method()] = it
|
||||
}
|
||||
)
|
||||
method = HttpMethod.Post
|
||||
accept(ContentType.Application.Json)
|
||||
|
||||
body = preparedBody
|
||||
},
|
||||
client
|
||||
)
|
||||
}
|
||||
|
||||
protected abstract fun <T : Any> prepareCallBody(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
): Any?
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapWithCommonValues
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
import io.ktor.client.request.forms.formData
|
||||
import io.ktor.http.Headers
|
||||
import io.ktor.http.HttpHeaders
|
||||
|
||||
class MultipartRequestCallFactory : AbstractRequestCallFactory() {
|
||||
|
||||
override fun <T : Any> prepareCallBody(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
): Any? = (request as? MultipartRequest) ?.let { castedRequest ->
|
||||
MultiPartFormDataContent(
|
||||
formData {
|
||||
val params = castedRequest.paramsJson.mapWithCommonValues()
|
||||
for ((key, value) in castedRequest.mediaMap + params) {
|
||||
when (value) {
|
||||
is MultipartFile -> appendInput(
|
||||
key,
|
||||
Headers.build {
|
||||
append(HttpHeaders.ContentType, value.mimeType)
|
||||
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
|
||||
}
|
||||
) {
|
||||
value.file.asInput()
|
||||
}
|
||||
is FileId -> append(key, value.fileId)
|
||||
else -> append(key, value.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.content.TextContent
|
||||
|
||||
class SimpleRequestCallFactory : AbstractRequestCallFactory() {
|
||||
override fun <T : Any> prepareCallBody(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
): Any? = (request as? SimpleRequest<T>) ?.let { _ ->
|
||||
val content = request.json().toString()
|
||||
|
||||
TextContent(
|
||||
content,
|
||||
ContentType.Application.Json
|
||||
)
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import io.ktor.utils.io.core.Closeable
|
||||
|
||||
interface RequestsExecutor : Closeable {
|
||||
/**
|
||||
* @throws com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
|
||||
*/
|
||||
suspend fun <T : Any> execute(request: Request<T>): T
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import io.ktor.utils.io.core.Closeable
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
interface UpdatesPoller : Closeable {
|
||||
fun start(scope: CoroutineScope = CoroutineScope(Dispatchers.Default))
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||
import kotlinx.io.IOException
|
||||
|
||||
fun newRequestException(
|
||||
response: Response,
|
||||
plainAnswer: String,
|
||||
message: String? = null,
|
||||
cause: Throwable? = null
|
||||
) = response.description ?.let { description ->
|
||||
when {
|
||||
description == "Bad Request: reply message not found" -> ReplyMessageNotFoundException(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 == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
|
||||
else -> null
|
||||
}
|
||||
} ?: CommonRequestException(response, plainAnswer, message, cause)
|
||||
|
||||
sealed class RequestException constructor(
|
||||
val response: Response,
|
||||
val plainAnswer: String,
|
||||
message: String? = null,
|
||||
override val cause: Throwable? = null
|
||||
) : IOException(
|
||||
message ?: "Something went wrong"
|
||||
)
|
||||
|
||||
class CommonRequestException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
class UnauthorizedException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
class ReplyMessageNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
class MessageIsNotModifiedException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
class MessageToEditNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
@@ -0,0 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.settings
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ProxySettings(
|
||||
val host: String = "localhost",
|
||||
val port: Int = 1080,
|
||||
val username: String? = null,
|
||||
val password: String? = null
|
||||
)
|
@@ -0,0 +1,67 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
|
||||
private fun now(): Long = DateTime.nowUnixLong()
|
||||
|
||||
class CommonLimiter(
|
||||
private val lockCount: Int = 10,
|
||||
private val regenTime: Long = 20 * 1000L // 20 seconds for full regen of opportunity to send message
|
||||
) : RequestLimiter {
|
||||
private var doLimit: Boolean = false
|
||||
|
||||
private val counterChannel = Channel<Unit>(Channel.UNLIMITED)
|
||||
private val scope = CoroutineScope(Dispatchers.Default)
|
||||
private val counterJob = scope.launch {
|
||||
var wasLastSecond = 0
|
||||
var lastCountTime = now()
|
||||
var limitManagementJob: Job? = null
|
||||
var removeLimitTime: Long = lastCountTime
|
||||
for (counter in counterChannel) {
|
||||
val now = now()
|
||||
if (now - lastCountTime > 1000) {
|
||||
lastCountTime = now
|
||||
wasLastSecond = 1
|
||||
} else {
|
||||
wasLastSecond++
|
||||
}
|
||||
if (wasLastSecond >= lockCount) {
|
||||
removeLimitTime = now + regenTime
|
||||
if (limitManagementJob == null) {
|
||||
limitManagementJob = launch {
|
||||
doLimit = true
|
||||
var internalNow = now()
|
||||
while (internalNow < removeLimitTime) {
|
||||
delay(removeLimitTime - internalNow)
|
||||
internalNow = now()
|
||||
}
|
||||
doLimit = false
|
||||
}
|
||||
}
|
||||
}
|
||||
if (now > removeLimitTime) {
|
||||
limitManagementJob = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val quoterChannel = Channel<Unit>(Channel.CONFLATED)
|
||||
private val tickerJob = scope.launch {
|
||||
while (isActive) {
|
||||
quoterChannel.send(Unit)
|
||||
delay(1000L)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T> limit(block: suspend () -> T): T {
|
||||
counterChannel.send(Unit)
|
||||
return if (!doLimit) {
|
||||
block()
|
||||
} else {
|
||||
quoterChannel.receive()
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters
|
||||
|
||||
object EmptyLimiter : RequestLimiter {
|
||||
override suspend fun <T> limit(block: suspend () -> T): T = block()
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.math.pow
|
||||
|
||||
private sealed class RequestEvent
|
||||
private class AddRequest(
|
||||
val continuation: Continuation<Long>
|
||||
) : RequestEvent()
|
||||
private object CompleteRequest : RequestEvent()
|
||||
|
||||
@Serializable
|
||||
data class PowLimiter(
|
||||
private val minAwaitTime: Long = 0L,
|
||||
private val maxAwaitTime: Long = 10000L,
|
||||
private val powValue: Double = 4.0,
|
||||
private val powK: Double = 0.0016
|
||||
) : RequestLimiter {
|
||||
@Transient
|
||||
private val scope = CoroutineScope(Dispatchers.Default)
|
||||
@Transient
|
||||
private val eventsChannel = Channel<RequestEvent>(Channel.UNLIMITED)
|
||||
@Transient
|
||||
private val awaitTimeRange = minAwaitTime .. maxAwaitTime
|
||||
|
||||
init {
|
||||
scope.launch {
|
||||
var requestsInWork: Double = 0.0
|
||||
for (event in eventsChannel) {
|
||||
when (event) {
|
||||
is AddRequest -> {
|
||||
val awaitTime = (((requestsInWork.pow(powValue) * powK) * 1000L).toLong())
|
||||
requestsInWork++
|
||||
|
||||
event.continuation.resume(
|
||||
if (awaitTime in awaitTimeRange) {
|
||||
awaitTime
|
||||
} else {
|
||||
if (awaitTime < minAwaitTime) {
|
||||
minAwaitTime
|
||||
} else {
|
||||
maxAwaitTime
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
is CompleteRequest -> requestsInWork--
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T> limit(
|
||||
block: suspend () -> T
|
||||
): T {
|
||||
val delayMillis = suspendCoroutine<Long> {
|
||||
scope.launch { eventsChannel.send(AddRequest(it)) }
|
||||
}
|
||||
delay(delayMillis)
|
||||
return try {
|
||||
block()
|
||||
} finally {
|
||||
eventsChannel.send(CompleteRequest)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters
|
||||
|
||||
interface RequestLimiter {
|
||||
/**
|
||||
* Use limit for working of block (like delay between or after, for example)
|
||||
*/
|
||||
suspend fun <T> limit(block: suspend () -> T): T
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
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.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.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class DeleteMessage(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier
|
||||
) : SimpleRequest<Boolean>, MessageAction {
|
||||
override fun method(): String = "deleteMessage"
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.deleteMessage(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier
|
||||
) = execute(
|
||||
DeleteMessage(chatId, messageId)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.deleteMessage(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier
|
||||
) = deleteMessage(chat.id, messageId)
|
||||
|
||||
suspend fun RequestsExecutor.deleteMessage(
|
||||
message: Message
|
||||
) = deleteMessage(message.chat, message.messageId)
|
||||
|
||||
suspend fun Message.delete(
|
||||
requestsExecutor: RequestsExecutor
|
||||
) = requestsExecutor.deleteMessage(this)
|
@@ -0,0 +1,75 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
private val AbleToBeForwardedMessageDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<PossiblyForwardedMessage>()
|
||||
|
||||
@Serializable
|
||||
data class ForwardMessage(
|
||||
@SerialName(fromChatIdField)
|
||||
val fromChatId: ChatIdentifier,
|
||||
@SerialName(chatIdField)
|
||||
val toChatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(disableNotificationField)
|
||||
val disableNotification: Boolean = false
|
||||
): SimpleRequest<PossiblyForwardedMessage>, MessageAction {
|
||||
override val chatId: ChatIdentifier
|
||||
get() = fromChatId
|
||||
|
||||
override fun method(): String = "forwardMessage"
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<PossiblyForwardedMessage>
|
||||
get() = AbleToBeForwardedMessageDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.forwardMessage(
|
||||
fromChatId: ChatIdentifier,
|
||||
toChatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
disableNotification: Boolean = false
|
||||
) = execute(
|
||||
ForwardMessage(fromChatId, toChatId, messageId, disableNotification)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.forwardMessage(
|
||||
fromChat: Chat,
|
||||
toChatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
disableNotification: Boolean = false
|
||||
) = forwardMessage(fromChat.id, toChatId, messageId, disableNotification)
|
||||
|
||||
suspend fun RequestsExecutor.forwardMessage(
|
||||
fromChatId: ChatIdentifier,
|
||||
toChat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
disableNotification: Boolean = false
|
||||
) = forwardMessage(fromChatId, toChat.id, messageId, disableNotification)
|
||||
|
||||
suspend fun RequestsExecutor.forwardMessage(
|
||||
fromChat: Chat,
|
||||
toChat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
disableNotification: Boolean = false
|
||||
) = forwardMessage(fromChat.id, toChat.id, messageId, disableNotification)
|
||||
|
||||
suspend fun RequestsExecutor.forwardMessage(
|
||||
toChatId: ChatIdentifier,
|
||||
message: Message,
|
||||
disableNotification: Boolean = false
|
||||
) = forwardMessage(message.chat, toChatId, message.messageId, disableNotification)
|
||||
|
||||
suspend fun RequestsExecutor.forwardMessage(
|
||||
toChat: Chat,
|
||||
message: Message,
|
||||
disableNotification: Boolean = false
|
||||
) = forwardMessage(message.chat, toChat, message.messageId, disableNotification)
|
@@ -0,0 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ExtendedBot
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
class GetMe : SimpleRequest<ExtendedBot> {
|
||||
override fun method(): String = "getMe"
|
||||
override val resultDeserializer: DeserializationStrategy<ExtendedBot>
|
||||
get() = ExtendedBot.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.getMe() = execute(GetMe())
|
@@ -0,0 +1,50 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateSerializerWithoutDeserialization
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
private val updatesListSerializer = ArrayListSerializer(
|
||||
UpdateSerializerWithoutDeserialization
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GetUpdates(
|
||||
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
|
||||
val limit: Int? = null,
|
||||
val timeout: Int? = null,
|
||||
val allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||
): SimpleRequest<List<Update>> {
|
||||
override fun method(): String = "getUpdates"
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<List<Update>>
|
||||
get() = updatesListSerializer
|
||||
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.getUpdates(
|
||||
offset: UpdateIdentifier? = null,
|
||||
limit: Int? = null,
|
||||
timeout: Int? = null,
|
||||
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||
) = execute(
|
||||
GetUpdates(
|
||||
offset, limit, timeout, allowed_updates
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.getUpdates(
|
||||
lastUpdate: Update,
|
||||
limit: Int? = null,
|
||||
timeout: Int? = null,
|
||||
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||
) = getUpdates(
|
||||
lastUpdate.updateId + 1, limit, timeout, allowed_updates
|
||||
)
|
@@ -0,0 +1,135 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.editLiveLocation
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.stopLiveLocation
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendLocation
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
|
||||
import com.soywiz.klock.DateTime
|
||||
import com.soywiz.klock.TimeSpan
|
||||
import io.ktor.utils.io.core.Closeable
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.ceil
|
||||
|
||||
private val livePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L
|
||||
class LiveLocation internal constructor(
|
||||
private val requestsExecutor: RequestsExecutor,
|
||||
scope: CoroutineScope,
|
||||
autoCloseTimeDelay: Double,
|
||||
initMessage: ContentMessage<LocationContent>
|
||||
) : Closeable {
|
||||
private val doWhenClose = {
|
||||
scope.launch {
|
||||
requestsExecutor.stopLiveLocation(message)
|
||||
}
|
||||
}
|
||||
private val autoCloseTime = DateTime.now() + TimeSpan(autoCloseTimeDelay)
|
||||
val leftUntilCloseMillis: TimeSpan
|
||||
get() = autoCloseTime - DateTime.now()
|
||||
|
||||
var isClosed: Boolean = false
|
||||
private set
|
||||
get() = field || leftUntilCloseMillis.millisecondsLong < 0L
|
||||
|
||||
private var message: ContentMessage<LocationContent> = initMessage
|
||||
val lastLocation: Location
|
||||
get() = message.content.location
|
||||
|
||||
suspend fun updateLocation(
|
||||
location: Location,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
): Location {
|
||||
if (!isClosed) {
|
||||
message = requestsExecutor.editLiveLocation(
|
||||
message,
|
||||
location,
|
||||
replyMarkup
|
||||
)
|
||||
return lastLocation
|
||||
} else {
|
||||
error("LiveLocation is closed")
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
if (isClosed) {
|
||||
return
|
||||
}
|
||||
isClosed = true
|
||||
doWhenClose()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.startLiveLocation(
|
||||
scope: CoroutineScope,
|
||||
chatId: ChatIdentifier,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
liveTimeMillis: Long = livePeriodDelayMillis,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): LiveLocation {
|
||||
val liveTimeAsDouble = liveTimeMillis.toDouble()
|
||||
val locationMessage = execute(
|
||||
SendLocation(
|
||||
chatId,
|
||||
latitude,
|
||||
longitude,
|
||||
ceil(liveTimeAsDouble / 1000).toLong(),
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
)
|
||||
|
||||
return LiveLocation(
|
||||
this,
|
||||
scope,
|
||||
liveTimeAsDouble,
|
||||
locationMessage
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.startLiveLocation(
|
||||
scope: CoroutineScope,
|
||||
chat: Chat,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
liveTimeMillis: Long = livePeriodDelayMillis,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): LiveLocation = startLiveLocation(
|
||||
scope, chat.id, latitude, longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.startLiveLocation(
|
||||
scope: CoroutineScope,
|
||||
chatId: ChatId,
|
||||
location: Location,
|
||||
liveTimeMillis: Long = livePeriodDelayMillis,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): LiveLocation = startLiveLocation(
|
||||
scope, chatId, location.latitude, location.longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.startLiveLocation(
|
||||
scope: CoroutineScope,
|
||||
chat: Chat,
|
||||
location: Location,
|
||||
liveTimeMillis: Long = livePeriodDelayMillis,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): LiveLocation = startLiveLocation(
|
||||
scope, chat.id, location.latitude, location.longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup
|
||||
)
|
@@ -0,0 +1,54 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||
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.types.*
|
||||
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 kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class StopPoll(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : MessageAction, SimpleRequest<Poll>, ReplyMarkup {
|
||||
override fun method(): String = "stopPoll"
|
||||
override val resultDeserializer: DeserializationStrategy<Poll>
|
||||
get() = Poll.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.stopPoll(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
StopPoll(chatId, messageId, replyMarkup)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.stopPoll(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = stopPoll(chat.id, messageId, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.stopPoll(
|
||||
chatId: ChatId,
|
||||
message: Message,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = stopPoll(chatId, message.messageId, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.stopPoll(
|
||||
chat: Chat,
|
||||
message: Message,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = stopPoll(chat.id, message.messageId, replyMarkup)
|
@@ -0,0 +1,41 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
|
||||
@Serializable(InputFileSerializer::class)
|
||||
sealed class InputFile {
|
||||
abstract val fileId: String
|
||||
}
|
||||
|
||||
// TODO:: add checks for file url/file id regex
|
||||
/**
|
||||
* Contains file id or file url
|
||||
*/
|
||||
@Serializable(InputFileSerializer::class)
|
||||
data class FileId(
|
||||
override val fileId: String
|
||||
) : InputFile()
|
||||
|
||||
fun String.toInputFile() = FileId(this)
|
||||
|
||||
@Serializer(InputFile::class)
|
||||
internal object InputFileSerializer : KSerializer<InputFile> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(FileId::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: InputFile) = encoder.encodeString(obj.fileId)
|
||||
override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString())
|
||||
}
|
||||
|
||||
// TODO:: add checks for files size
|
||||
/**
|
||||
* Contains info about file for sending
|
||||
*/
|
||||
@Serializable(InputFileSerializer::class)
|
||||
data class MultipartFile (
|
||||
val file: StorageFile,
|
||||
val mimeType: String = file.contentType,
|
||||
val filename: String = file.fileName
|
||||
) : InputFile() {
|
||||
override val fileId: String = file.generateCustomName()
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
interface MultipartRequest<T: Any> : Request<T> {
|
||||
val paramsJson: JsonObject
|
||||
val mediaMap: Map<String, MultipartFile>
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
|
||||
interface Request<T: Any> {
|
||||
fun method(): String
|
||||
val resultDeserializer: DeserializationStrategy<T>
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
interface SimpleRequest<T: Any> : Request<T> {
|
||||
val requestSerializer: SerializationStrategy<*>
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <T: Any, K: SimpleRequest<T>> K.json(): JsonObject = toJsonWithoutNulls(requestSerializer as SerializationStrategy<K>)
|
@@ -0,0 +1,51 @@
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.CallbackQuery.CallbackQuery
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class AnswerCallbackQuery(
|
||||
@SerialName(callbackQueryIdField)
|
||||
val callbackQueryId: CallbackQueryIdentifier,
|
||||
@SerialName(textField)
|
||||
val text: String? = null,
|
||||
@SerialName(showAlertField)
|
||||
val showAlert: Boolean? = null,
|
||||
@SerialName(urlField)
|
||||
val url: String? = null,
|
||||
@SerialName(cachedTimeField)
|
||||
val cachedTimeSeconds: Int? = null
|
||||
) : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerCallbackQuery"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
fun CallbackQuery.createAnswer(
|
||||
text: String? = null,
|
||||
showAlert: Boolean? = null,
|
||||
url: String? = null,
|
||||
cachedTimeSeconds: Int? = null
|
||||
): AnswerCallbackQuery = AnswerCallbackQuery(id, text, showAlert, url, cachedTimeSeconds)
|
||||
|
||||
suspend fun RequestsExecutor.answerCallbackQuery(
|
||||
callbackQueryId: CallbackQueryIdentifier,
|
||||
text: String? = null,
|
||||
showAlert: Boolean? = null,
|
||||
url: String? = null,
|
||||
cachedTimeSeconds: Int? = null
|
||||
) = execute(AnswerCallbackQuery(callbackQueryId, text, showAlert, url, cachedTimeSeconds))
|
||||
|
||||
suspend fun RequestsExecutor.answerCallbackQuery(
|
||||
callbackQuery: CallbackQuery,
|
||||
text: String? = null,
|
||||
showAlert: Boolean? = null,
|
||||
url: String? = null,
|
||||
cachedTimeSeconds: Int? = null
|
||||
) = answerCallbackQuery(callbackQuery.id, text, showAlert, url, cachedTimeSeconds)
|
@@ -0,0 +1,79 @@
|
||||
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.types.*
|
||||
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.abstracts.InlineQuery
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class AnswerInlineQuery(
|
||||
@SerialName(inlineQueryIdField)
|
||||
val inlineQueryID: InlineQueryIdentifier,
|
||||
@Serializable(InlineQueryAnswersResultsSerializer::class)
|
||||
@SerialName(resultsField)
|
||||
val results: List<InlineQueryResult> = emptyList(),
|
||||
@SerialName(cachedTimeField)
|
||||
val cachedTime: Int? = null,
|
||||
@SerialName(isPersonalField)
|
||||
val isPersonal: Boolean? = null,
|
||||
@SerialName(nextOffsetField)
|
||||
val nextOffset: String? = null,
|
||||
@SerialName(switchPmTextField)
|
||||
val switchPmText: String? = null,
|
||||
@SerialName(switchPmParameterField)
|
||||
val switchPmParameter: String? = null
|
||||
): SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerInlineQuery"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
fun InlineQuery.createAnswer(
|
||||
results: List<InlineQueryResult> = emptyList(),
|
||||
cachedTime: Int? = null,
|
||||
isPersonal: Boolean? = null,
|
||||
nextOffset: String? = null,
|
||||
switchPmText: String? = null,
|
||||
switchPmParameter: String? = null
|
||||
) = AnswerInlineQuery(
|
||||
id,
|
||||
results,
|
||||
cachedTime,
|
||||
isPersonal,
|
||||
nextOffset,
|
||||
switchPmText,
|
||||
switchPmParameter
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.answerInlineQuery(
|
||||
inlineQueryID: InlineQueryIdentifier,
|
||||
results: List<InlineQueryResult> = emptyList(),
|
||||
cachedTime: Int? = null,
|
||||
isPersonal: Boolean? = null,
|
||||
nextOffset: String? = null,
|
||||
switchPmText: String? = null,
|
||||
switchPmParameter: String? = null
|
||||
) = execute(
|
||||
AnswerInlineQuery(inlineQueryID, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.answerInlineQuery(
|
||||
inlineQuery: InlineQuery,
|
||||
results: List<InlineQueryResult> = emptyList(),
|
||||
cachedTime: Int? = null,
|
||||
isPersonal: Boolean? = null,
|
||||
nextOffset: String? = null,
|
||||
switchPmText: String? = null,
|
||||
switchPmParameter: String? = null
|
||||
) = answerInlineQuery(inlineQuery.id, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter)
|
||||
|
||||
internal object InlineQueryAnswersResultsSerializer: KSerializer<List<InlineQueryResult>> by ArrayListSerializer(
|
||||
InlineQueryResultSerializer
|
||||
)
|
@@ -0,0 +1,59 @@
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuery
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class AnswerPreCheckoutQueryOk(
|
||||
@SerialName(preCheckoutQueryIdField)
|
||||
override val preCheckoutQueryId: PreCheckoutQueryId
|
||||
) : AnswerPreCheckoutQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = true
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
|
||||
@Serializable
|
||||
data class AnswerPreCheckoutQueryError(
|
||||
@SerialName(preCheckoutQueryIdField)
|
||||
override val preCheckoutQueryId: PreCheckoutQueryId,
|
||||
@SerialName(errorMessageField)
|
||||
val errorMessage: String
|
||||
) : AnswerPreCheckoutQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = false
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
fun PreCheckoutQuery.createAnswerOk(): AnswerPreCheckoutQueryOk = AnswerPreCheckoutQueryOk(
|
||||
id
|
||||
)
|
||||
|
||||
fun PreCheckoutQuery.createAnswerError(
|
||||
error: String
|
||||
): AnswerPreCheckoutQueryError = AnswerPreCheckoutQueryError(
|
||||
id,
|
||||
error
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.answerPreCheckoutQueryOk(
|
||||
id: PreCheckoutQueryId
|
||||
) = execute(AnswerPreCheckoutQueryOk(id))
|
||||
suspend fun RequestsExecutor.answerPreCheckoutQueryOk(
|
||||
preCheckoutQuery: PreCheckoutQuery
|
||||
) = answerPreCheckoutQueryOk(preCheckoutQuery.id)
|
||||
|
||||
suspend fun RequestsExecutor.answerPreCheckoutQueryError(
|
||||
id: PreCheckoutQueryId,
|
||||
error: String
|
||||
) = execute(AnswerPreCheckoutQueryError(id, error))
|
||||
suspend fun RequestsExecutor.answerPreCheckoutQueryError(
|
||||
preCheckoutQuery: PreCheckoutQuery,
|
||||
error: String
|
||||
) = answerPreCheckoutQueryError(preCheckoutQuery.id, error)
|
@@ -0,0 +1,74 @@
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingOption
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingQuery
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
@Serializable
|
||||
data class AnswerShippingQueryOk(
|
||||
@SerialName(shippingQueryIdField)
|
||||
override val shippingQueryId: ShippingQueryIdentifier,
|
||||
@Serializable(ShippingOptionsSerializer::class)
|
||||
@SerialName(shippingOptionsField)
|
||||
val shippingOptions: List<ShippingOption>
|
||||
) : AnswerShippingQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = true
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
internal object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ArrayListSerializer(
|
||||
ShippingOption.serializer()
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class AnswerShippingQueryError(
|
||||
@SerialName(shippingQueryIdField)
|
||||
override val shippingQueryId: ShippingQueryIdentifier,
|
||||
@SerialName(errorMessageField)
|
||||
val error: String
|
||||
) : AnswerShippingQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = false
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
fun ShippingQuery.createAnswerOk(
|
||||
shippingOptions: List<ShippingOption>
|
||||
): AnswerShippingQueryOk = AnswerShippingQueryOk(
|
||||
id,
|
||||
shippingOptions
|
||||
)
|
||||
|
||||
fun ShippingQuery.createAnswerError(
|
||||
error: String
|
||||
): AnswerShippingQueryError = AnswerShippingQueryError(
|
||||
id,
|
||||
error
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.answerShippingQueryOk(
|
||||
id: ShippingQueryIdentifier,
|
||||
shippingOptions: List<ShippingOption>
|
||||
) = execute(AnswerShippingQueryOk(id, shippingOptions))
|
||||
suspend fun RequestsExecutor.answerShippingQueryOk(
|
||||
shippingQuery: ShippingQuery,
|
||||
shippingOptions: List<ShippingOption>
|
||||
) = answerShippingQueryOk(shippingQuery.id, shippingOptions)
|
||||
|
||||
suspend fun RequestsExecutor.answerShippingQueryError(
|
||||
id: ShippingQueryIdentifier,
|
||||
error: String
|
||||
) = execute(AnswerShippingQueryError(id, error))
|
||||
suspend fun RequestsExecutor.answerShippingQueryError(
|
||||
shippingQuery: ShippingQuery,
|
||||
error: String
|
||||
) = answerShippingQueryError(shippingQuery.id, error)
|
||||
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.PreCheckoutQueryId
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
interface AnswerPreCheckoutQuery : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerPreCheckoutQuery"
|
||||
override val resultDeserializer: KSerializer<Boolean>
|
||||
get() = BooleanSerializer
|
||||
|
||||
val preCheckoutQueryId: PreCheckoutQueryId
|
||||
val isOk: Boolean
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ShippingQueryIdentifier
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
interface AnswerShippingQuery : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerShippingQuery"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
|
||||
val shippingQueryId: ShippingQueryIdentifier
|
||||
val isOk: Boolean
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat
|
||||
|
||||
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.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringSerializer
|
||||
|
||||
@Serializable
|
||||
data class ExportChatInviteLink(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<String> {
|
||||
override fun method(): String = "exportChatInviteLink"
|
||||
override val resultDeserializer: DeserializationStrategy<String>
|
||||
get() = StringSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.exportChatInviteLink(
|
||||
chatId: ChatIdentifier
|
||||
) = execute(ExportChatInviteLink(chatId))
|
||||
|
||||
suspend fun RequestsExecutor.exportChatInviteLink(
|
||||
chat: PublicChat
|
||||
) = exportChatInviteLink(chat.id)
|
@@ -0,0 +1,30 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat
|
||||
|
||||
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.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class LeaveChat(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "leaveChat"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.leaveChat(
|
||||
chatId: ChatIdentifier
|
||||
) = execute(LeaveChat(chatId))
|
||||
|
||||
suspend fun RequestsExecutor.leaveChat(
|
||||
chat: PublicChat
|
||||
) = leaveChat(chat.id)
|
@@ -0,0 +1,9 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||
|
||||
interface ChatMemberRequest<T: Any> : ChatRequest, SimpleRequest<T> {
|
||||
val userId: UserId
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||
|
||||
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.types.ChatIdentifier
|
||||
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.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class GetChat(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<ExtendedChat> {
|
||||
override fun method(): String = "getChat"
|
||||
override val resultDeserializer: DeserializationStrategy<ExtendedChat>
|
||||
get() = ExtendedChatSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chatId: ChatIdentifier
|
||||
) = execute(GetChat(chatId))
|
||||
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: Chat
|
||||
) = getChat(chat.id)
|
@@ -0,0 +1,36 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||
|
||||
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.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember
|
||||
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 kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
private val chatMembersListSerializer = ArrayListSerializer(
|
||||
AdministratorChatMemberSerializerWithoutDeserialization
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GetChatAdministrators(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<List<AdministratorChatMember>> {
|
||||
override fun method(): String = "getChatAdministrators"
|
||||
override val resultDeserializer: DeserializationStrategy<List<AdministratorChatMember>>
|
||||
get() = chatMembersListSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.getChatAdministrators(
|
||||
chatId: ChatIdentifier
|
||||
) = execute(GetChatAdministrators(chatId))
|
||||
|
||||
suspend fun RequestsExecutor.getChatAdministrators(
|
||||
chat: PublicChat
|
||||
) = getChatAdministrators(chat.id)
|
@@ -0,0 +1,30 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||
|
||||
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.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.IntSerializer
|
||||
|
||||
@Serializable
|
||||
data class GetChatMembersCount(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Int> {
|
||||
override fun method(): String = "getChatMembersCount"
|
||||
override val resultDeserializer: DeserializationStrategy<Int>
|
||||
get() = IntSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.getChatMembersCount(
|
||||
chatId: ChatIdentifier
|
||||
) = execute(GetChatMembersCount(chatId))
|
||||
|
||||
suspend fun RequestsExecutor.getChatMembersCount(
|
||||
chat: PublicChat
|
||||
) = getChatMembersCount(chat.id)
|
@@ -0,0 +1,43 @@
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMemberDeserializationStrategy
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class GetChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId
|
||||
) : ChatMemberRequest<ChatMember> {
|
||||
override fun method(): String = "getChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<ChatMember>
|
||||
get() = ChatMemberDeserializationStrategy
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.getChatMember(
|
||||
chatId: ChatIdentifier,
|
||||
userId: UserId
|
||||
) = execute(GetChatMember(chatId, userId))
|
||||
|
||||
suspend fun RequestsExecutor.getChatMember(
|
||||
chat: PublicChat,
|
||||
userId: UserId
|
||||
) = getChatMember(chat.id, userId)
|
||||
|
||||
suspend fun RequestsExecutor.getChatMember(
|
||||
chatId: ChatId,
|
||||
user: User
|
||||
) = getChatMember(chatId, user.id)
|
||||
|
||||
suspend fun RequestsExecutor.getChatMember(
|
||||
chat: PublicChat,
|
||||
user: User
|
||||
) = getChatMember(chat.id, user.id)
|
@@ -0,0 +1,49 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class KickChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "kickChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.kickChatMember(
|
||||
chatId: ChatIdentifier,
|
||||
userId: UserId,
|
||||
untilDate: TelegramDate? = null
|
||||
) = execute(KickChatMember(chatId, userId, untilDate))
|
||||
|
||||
suspend fun RequestsExecutor.kickChatMember(
|
||||
chat: PublicChat,
|
||||
userId: UserId,
|
||||
untilDate: TelegramDate? = null
|
||||
) = kickChatMember(chat.id, userId, untilDate)
|
||||
|
||||
suspend fun RequestsExecutor.kickChatMember(
|
||||
chatId: ChatId,
|
||||
user: User,
|
||||
untilDate: TelegramDate? = null
|
||||
) = kickChatMember(chatId, user.id, untilDate)
|
||||
|
||||
suspend fun RequestsExecutor.kickChatMember(
|
||||
chat: PublicChat,
|
||||
user: User,
|
||||
untilDate: TelegramDate? = null
|
||||
) = kickChatMember(chat.id, user.id, untilDate)
|
@@ -0,0 +1,147 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class PromoteChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null,
|
||||
@SerialName(canChangeInfoField)
|
||||
private val canChangeInfo: Boolean? = null,
|
||||
@SerialName(canPostMessagesField)
|
||||
private val canPostMessages: Boolean? = null,
|
||||
@SerialName(canEditMessagesField)
|
||||
private val canEditMessages: Boolean? = null,
|
||||
@SerialName(canDeleteMessagesField)
|
||||
private val canDeleteMessages: Boolean? = null,
|
||||
@SerialName(canInviteUsersField)
|
||||
private val canInviteUsers: Boolean? = null,
|
||||
@SerialName(canRestrictMembersField)
|
||||
private val canRestrictMembers: Boolean? = null,
|
||||
@SerialName(canPinMessagesField)
|
||||
private val canPinMessages: Boolean? = null,
|
||||
@SerialName(canPromoteMembersField)
|
||||
private val canPromoteMembers: Boolean? = null
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "promoteChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.promoteChatMember(
|
||||
chatId: ChatIdentifier,
|
||||
userId: UserId,
|
||||
untilDate: TelegramDate? = null,
|
||||
canChangeInfo: Boolean? = null,
|
||||
canPostMessages: Boolean? = null,
|
||||
canEditMessages: Boolean? = null,
|
||||
canDeleteMessages: Boolean? = null,
|
||||
canInviteUsers: Boolean? = null,
|
||||
canRestrictMembers: Boolean? = null,
|
||||
canPinMessages: Boolean? = null,
|
||||
canPromoteMembers: Boolean? = null
|
||||
) = execute(
|
||||
PromoteChatMember(
|
||||
chatId,
|
||||
userId,
|
||||
untilDate,
|
||||
canChangeInfo,
|
||||
canPostMessages,
|
||||
canEditMessages,
|
||||
canDeleteMessages,
|
||||
canInviteUsers,
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.promoteChatMember(
|
||||
chat: PublicChat,
|
||||
userId: UserId,
|
||||
untilDate: TelegramDate? = null,
|
||||
canChangeInfo: Boolean? = null,
|
||||
canPostMessages: Boolean? = null,
|
||||
canEditMessages: Boolean? = null,
|
||||
canDeleteMessages: Boolean? = null,
|
||||
canInviteUsers: Boolean? = null,
|
||||
canRestrictMembers: Boolean? = null,
|
||||
canPinMessages: Boolean? = null,
|
||||
canPromoteMembers: Boolean? = null
|
||||
) = promoteChatMember(
|
||||
chat.id,
|
||||
userId,
|
||||
untilDate,
|
||||
canChangeInfo,
|
||||
canPostMessages,
|
||||
canEditMessages,
|
||||
canDeleteMessages,
|
||||
canInviteUsers,
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.promoteChatMember(
|
||||
chatId: ChatId,
|
||||
user: User,
|
||||
untilDate: TelegramDate? = null,
|
||||
canChangeInfo: Boolean? = null,
|
||||
canPostMessages: Boolean? = null,
|
||||
canEditMessages: Boolean? = null,
|
||||
canDeleteMessages: Boolean? = null,
|
||||
canInviteUsers: Boolean? = null,
|
||||
canRestrictMembers: Boolean? = null,
|
||||
canPinMessages: Boolean? = null,
|
||||
canPromoteMembers: Boolean? = null
|
||||
) = promoteChatMember(
|
||||
chatId,
|
||||
user.id,
|
||||
untilDate,
|
||||
canChangeInfo,
|
||||
canPostMessages,
|
||||
canEditMessages,
|
||||
canDeleteMessages,
|
||||
canInviteUsers,
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.promoteChatMember(
|
||||
chat: PublicChat,
|
||||
user: User,
|
||||
untilDate: TelegramDate? = null,
|
||||
canChangeInfo: Boolean? = null,
|
||||
canPostMessages: Boolean? = null,
|
||||
canEditMessages: Boolean? = null,
|
||||
canDeleteMessages: Boolean? = null,
|
||||
canInviteUsers: Boolean? = null,
|
||||
canRestrictMembers: Boolean? = null,
|
||||
canPinMessages: Boolean? = null,
|
||||
canPromoteMembers: Boolean? = null
|
||||
) = promoteChatMember(
|
||||
chat.id,
|
||||
user.id,
|
||||
untilDate,
|
||||
canChangeInfo,
|
||||
canPostMessages,
|
||||
canEditMessages,
|
||||
canDeleteMessages,
|
||||
canInviteUsers,
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers
|
||||
)
|
@@ -0,0 +1,57 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class RestrictChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null,
|
||||
@SerialName(permissionsField)
|
||||
val permissions: ChatPermissions = ChatPermissions()
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "restrictChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.restrictChatMember(
|
||||
chatId: ChatIdentifier,
|
||||
userId: UserId,
|
||||
untilDate: TelegramDate? = null,
|
||||
permissions: ChatPermissions = ChatPermissions()
|
||||
) = execute(RestrictChatMember(chatId, userId, untilDate, permissions))
|
||||
|
||||
suspend fun RequestsExecutor.restrictChatMember(
|
||||
chat: PublicChat,
|
||||
userId: UserId,
|
||||
untilDate: TelegramDate? = null,
|
||||
permissions: ChatPermissions = ChatPermissions()
|
||||
) = restrictChatMember(chat.id, userId, untilDate, permissions)
|
||||
|
||||
suspend fun RequestsExecutor.restrictChatMember(
|
||||
chatId: ChatId,
|
||||
user: User,
|
||||
untilDate: TelegramDate? = null,
|
||||
permissions: ChatPermissions = ChatPermissions()
|
||||
) = restrictChatMember(chatId, user.id, untilDate, permissions)
|
||||
|
||||
suspend fun RequestsExecutor.restrictChatMember(
|
||||
chat: PublicChat,
|
||||
user: User,
|
||||
untilDate: TelegramDate? = null,
|
||||
permissions: ChatPermissions = ChatPermissions()
|
||||
) = restrictChatMember(chat.id, user.id, untilDate, permissions)
|
||||
|
@@ -0,0 +1,59 @@
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
/**
|
||||
* Representation of https://core.telegram.org/bots/api#setchatadministratorcustomtitle
|
||||
*
|
||||
* Please, remember about restrictions for characters in custom title
|
||||
*/
|
||||
@Serializable
|
||||
data class SetChatAdministratorCustomTitle(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(customTitleField)
|
||||
val customTitle: String
|
||||
) : ChatMemberRequest<Boolean> {
|
||||
override fun method(): String = "setChatAdministratorCustomTitle"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = RestrictChatMember.serializer()
|
||||
|
||||
init {
|
||||
if (customTitle.length !in customTitleLength) {
|
||||
throw IllegalArgumentException("Custom title length must be in range $customTitleLength, but was ${customTitle.length}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.setChatAdministratorCustomTitle(
|
||||
chatId: ChatId,
|
||||
userId: UserId,
|
||||
customTitle: String
|
||||
) = execute(SetChatAdministratorCustomTitle(chatId, userId, customTitle))
|
||||
|
||||
suspend fun RequestsExecutor.setChatAdministratorCustomTitle(
|
||||
chat: PublicChat,
|
||||
userId: UserId,
|
||||
customTitle: String
|
||||
) = setChatAdministratorCustomTitle(chat.id, userId, customTitle)
|
||||
|
||||
suspend fun RequestsExecutor.setChatAdministratorCustomTitle(
|
||||
chatId: ChatId,
|
||||
user: User,
|
||||
customTitle: String
|
||||
) = setChatAdministratorCustomTitle(chatId, user.id, customTitle)
|
||||
|
||||
suspend fun RequestsExecutor.setChatAdministratorCustomTitle(
|
||||
chat: PublicChat,
|
||||
user: User,
|
||||
customTitle: String
|
||||
) = setChatAdministratorCustomTitle(chat.id, user.id, customTitle)
|
@@ -0,0 +1,43 @@
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class UnbanChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId
|
||||
) : ChatMemberRequest<Boolean> {
|
||||
override fun method(): String = "unbanChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.unbanChatMember(
|
||||
chatId: ChatIdentifier,
|
||||
userId: UserId
|
||||
) = execute(UnbanChatMember(chatId, userId))
|
||||
|
||||
suspend fun RequestsExecutor.unbanChatMember(
|
||||
chat: PublicChat,
|
||||
userId: UserId
|
||||
) = unbanChatMember(chat.id, userId)
|
||||
|
||||
suspend fun RequestsExecutor.unbanChatMember(
|
||||
chatId: ChatId,
|
||||
user: User
|
||||
) = unbanChatMember(chatId, user.id)
|
||||
|
||||
suspend fun RequestsExecutor.unbanChatMember(
|
||||
chat: PublicChat,
|
||||
user: User
|
||||
) = unbanChatMember(chat.id, user.id)
|
||||
|
@@ -0,0 +1,30 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
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.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class DeleteChatPhoto(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "deleteChatPhoto"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.deleteChatPhoto(
|
||||
chatId: ChatIdentifier
|
||||
) = execute(DeleteChatPhoto(chatId))
|
||||
|
||||
suspend fun RequestsExecutor.deleteChatPhoto(
|
||||
chat: PublicChat
|
||||
) = deleteChatPhoto(chat.id)
|
@@ -0,0 +1,47 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class PinChatMessage (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false
|
||||
): ChatRequest, SimpleRequest<Boolean>, MessageAction, DisableNotification {
|
||||
override fun method(): String = "pinChatMessage"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.pinChatMessage(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
disableNotification: Boolean = false
|
||||
) = execute(PinChatMessage(chatId, messageId, disableNotification))
|
||||
|
||||
suspend fun RequestsExecutor.pinChatMessage(
|
||||
chat: PublicChat,
|
||||
messageId: MessageIdentifier,
|
||||
disableNotification: Boolean = false
|
||||
) = pinChatMessage(chat.id, messageId, disableNotification)
|
||||
|
||||
suspend fun RequestsExecutor.pinChatMessage(
|
||||
message: Message,
|
||||
disableNotification: Boolean = false
|
||||
) = if (message.chat is PublicChat) {
|
||||
pinChatMessage(message.chat.id, message.messageId, disableNotification)
|
||||
} else {
|
||||
error("It is possible to pin messages only in non one-to-one chats")
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class SetChatDescription (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(descriptionField)
|
||||
val description: String
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
init {
|
||||
if (description.length !in chatDescriptionLength) {
|
||||
throw IllegalArgumentException("Chat description must be in $chatDescriptionLength range")
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "setChatDescription"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.setChatDescription(
|
||||
chatId: ChatIdentifier,
|
||||
description: String
|
||||
) = execute(SetChatDescription(chatId, description))
|
||||
|
||||
suspend fun RequestsExecutor.setChatDescription(
|
||||
chat: PublicChat,
|
||||
description: String
|
||||
) = setChatDescription(chat.id, description)
|
@@ -0,0 +1,34 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class SetChatPermissions (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(permissionsField)
|
||||
val permissions: ChatPermissions
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "setChatPermissions"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.setDefaultChatMembersPermissions(
|
||||
chatId: ChatIdentifier,
|
||||
permissions: ChatPermissions
|
||||
) = execute(SetChatPermissions(chatId, permissions))
|
||||
|
||||
suspend fun RequestsExecutor.setDefaultChatMembersPermissions(
|
||||
chat: PublicChat,
|
||||
permissions: ChatPermissions
|
||||
) = setDefaultChatMembersPermissions(chat.id, permissions)
|
@@ -0,0 +1,35 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJson
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
@Serializable
|
||||
data class SetChatPhoto (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
val photo: MultipartFile = throw IllegalArgumentException("Unfortunately, this type of objects can't be parsed automatically")
|
||||
): ChatRequest, MultipartRequest<Boolean> {
|
||||
override fun method(): String = "setChatPhoto"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
|
||||
override val paramsJson: JsonObject = toJson(serializer())
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.setChatPhoto(
|
||||
chatId: ChatIdentifier,
|
||||
photo: MultipartFile
|
||||
) = execute(SetChatPhoto(chatId, photo))
|
||||
|
||||
suspend fun RequestsExecutor.setChatPhoto(
|
||||
chat: PublicChat,
|
||||
photo: MultipartFile
|
||||
) = setChatPhoto(chat.id, photo)
|
@@ -0,0 +1,39 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class SetChatTitle (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
val title: String
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
init {
|
||||
if (title.length !in chatTitleLength) {
|
||||
throw IllegalArgumentException("Chat title must be in $chatTitleLength range")
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "setChatTitle"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.setChatTitle(
|
||||
chatId: ChatIdentifier,
|
||||
title: String
|
||||
) = execute(SetChatTitle(chatId, title))
|
||||
|
||||
suspend fun RequestsExecutor.setChatTitle(
|
||||
chat: PublicChat,
|
||||
title: String
|
||||
) = setChatTitle(chat.id, title)
|
@@ -0,0 +1,30 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
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.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class UnpinChatMessage(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "unpinChatMessage"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.unpinChatMessage(
|
||||
chatId: ChatIdentifier
|
||||
) = execute(UnpinChatMessage(chatId))
|
||||
|
||||
suspend fun RequestsExecutor.unpinChatMessage(
|
||||
chat: PublicChat
|
||||
) = unpinChatMessage(chat.id)
|
@@ -0,0 +1,30 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.stickers
|
||||
|
||||
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.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class DeleteChatStickerSet(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "deleteChatStickerSet"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.deleteChatStickerSet(
|
||||
chatId: ChatIdentifier
|
||||
) = execute(DeleteChatStickerSet(chatId))
|
||||
|
||||
suspend fun RequestsExecutor.deleteChatStickerSet(
|
||||
chat: SupergroupChat
|
||||
) = deleteChatStickerSet(chat.id)
|
@@ -0,0 +1,33 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.stickers
|
||||
|
||||
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.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class SetChatStickerSet(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(stickerSetNameField)
|
||||
val stickerSetName: StickerSetName
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "setChatStickerSet"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.setChatStickerSet(
|
||||
chatId: ChatIdentifier,
|
||||
stickerSetName: StickerSetName
|
||||
) = execute(SetChatStickerSet(chatId, stickerSetName))
|
||||
|
||||
suspend fun RequestsExecutor.setChatStickerSet(
|
||||
chat: SupergroupChat,
|
||||
stickerSetName: StickerSetName
|
||||
) = setChatStickerSet(chat.id, stickerSetName)
|
@@ -0,0 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.common
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
internal data class CommonMultipartFileRequest<T: Any>(
|
||||
val data: SimpleRequest<T>,
|
||||
override val mediaMap: Map<String, MultipartFile>
|
||||
) : MultipartRequest<T>, Request<T> by data {
|
||||
override val paramsJson: JsonObject = data.json()
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
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.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageLiveLocation(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(latitudeField)
|
||||
override val latitude: Double,
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage<LocationContent>, EditReplyMessage, EditLocationMessage {
|
||||
override fun method(): String = "editMessageLiveLocation"
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
||||
get() = commonResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
EditChatMessageLiveLocation(
|
||||
chatId, messageId, latitude, longitude, replyMarkup
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editLiveLocation(chat.id, messageId, latitude, longitude, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
message: ContentMessage<LocationContent>,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editLiveLocation(message.chat, message.messageId, latitude, longitude, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
location: Location,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
EditChatMessageLiveLocation(
|
||||
chatId, messageId, location.latitude, location.longitude, replyMarkup
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
location: Location,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editLiveLocation(chat.id, messageId, location.latitude, location.longitude, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
message: ContentMessage<LocationContent>,
|
||||
location: Location,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editLiveLocation(message.chat, message.messageId, location.latitude, location.longitude, replyMarkup)
|
@@ -0,0 +1,39 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageLiveLocation(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(latitudeField)
|
||||
override val latitude: Double,
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage, EditLocationMessage {
|
||||
override fun method(): String = "editMessageLiveLocation"
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
EditInlineMessageLiveLocation(
|
||||
inlineMessageId, latitude, longitude, replyMarkup
|
||||
)
|
||||
)
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
location: Location,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editLiveLocation(inlineMessageId, location.latitude, location.longitude, replyMarkup)
|
@@ -0,0 +1,52 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditChatMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
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.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
|
||||
|
||||
@Serializable
|
||||
data class StopChatMessageLiveLocation(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage<LocationContent>, EditReplyMessage {
|
||||
override fun method(): String = "stopMessageLiveLocation"
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
||||
get() = commonResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
|
||||
suspend fun RequestsExecutor.stopLiveLocation(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
StopChatMessageLiveLocation(
|
||||
chatId, messageId, replyMarkup
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.stopLiveLocation(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = stopLiveLocation(chat.id, messageId, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.stopLiveLocation(
|
||||
message: ContentMessage<LocationContent>,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = stopLiveLocation(message.chat, message.messageId, replyMarkup)
|
@@ -0,0 +1,29 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditInlineMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class StopInlineMessageLiveLocation(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage {
|
||||
override fun method(): String = "stopMessageLiveLocation"
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.stopLiveLocation(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
StopInlineMessageLiveLocation(
|
||||
inlineMessageId, replyMarkup
|
||||
)
|
||||
)
|
@@ -0,0 +1,52 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.ReplyMarkup
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditChatMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
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.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageReplyMarkupMethod = "editMessageReplyMarkup"
|
||||
|
||||
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<MessageContent>>()
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageReplyMarkup(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage<MessageContent>, EditReplyMessage {
|
||||
|
||||
override fun method(): String = editMessageReplyMarkupMethod
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<MessageContent>>
|
||||
get() = commonResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editMessageReplyMarkup(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
EditChatMessageReplyMarkup(chatId, messageId, replyMarkup)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.editMessageReplyMarkup(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editMessageReplyMarkup(chat.id, messageId, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.editMessageReplyMarkup(
|
||||
message: Message,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editMessageReplyMarkup(message.chat.id, message.messageId, replyMarkup)
|
||||
|
@@ -0,0 +1,25 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.ReplyMarkup
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditInlineMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageReplyMarkup(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage {
|
||||
override fun method(): String = editMessageReplyMarkupMethod
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editMessageReplyMarkup(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(EditInlineMessageReplyMarkup(inlineMessageId, replyMarkup))
|
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
||||
|
||||
interface EditChatMessage<MT: MessageContent> : SimpleRequest<ContentMessage<MT>>, MessageAction
|
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
interface EditDisableWebPagePreviewMessage {
|
||||
val disableWebPagePreview: Boolean?
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
interface EditInlineMessage : SimpleRequest<Boolean> {
|
||||
val inlineMessageId: InlineMessageIdentifier
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
interface EditLocationMessage {
|
||||
val latitude: Double
|
||||
val longitude: Double
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia
|
||||
|
||||
interface EditMediaMessage {
|
||||
val media: InputMedia
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
|
||||
interface EditReplyMessage : ReplyMarkup {
|
||||
override val replyMarkup: InlineKeyboardMarkup?
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
|
||||
interface EditTextChatMessage {
|
||||
val text: String
|
||||
val parseMode: ParseMode?
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.MediaContentMessageResultDeserializer
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
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.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageCaptionMethod = "editMessageCaption"
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageCaption(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(captionField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage<MediaContent>, EditTextChatMessage, EditReplyMessage {
|
||||
|
||||
override fun method(): String = editMessageCaptionMethod
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<MediaContent>>
|
||||
get() = MediaContentMessageResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editMessageCaption(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
EditChatMessageCaption(chatId, messageId, text, parseMode, replyMarkup)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.editMessageCaption(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editMessageCaption(chat.id, messageId, text, parseMode, replyMarkup)
|
||||
|
||||
suspend fun <T> RequestsExecutor.editMessageCaption(
|
||||
message: ContentMessage<T>,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
): ContentMessage<MediaContent> where T : CaptionedInput, T : MediaContent {
|
||||
return editMessageCaption(message.chat.id, message.messageId, text, parseMode, replyMarkup)
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageCaption(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(captionField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage {
|
||||
override fun method(): String = editMessageCaptionMethod
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editMessageCaption(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(EditInlineMessageCaption(inlineMessageId, text, parseMode, replyMarkup))
|
@@ -0,0 +1,64 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia
|
||||
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.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageMediaMethod = "editMessageMedia"
|
||||
|
||||
internal val MediaContentMessageResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<MediaContent>>()
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageMedia(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(mediaField)
|
||||
override val media: InputMedia,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage<MediaContent>, EditReplyMessage, EditMediaMessage {
|
||||
|
||||
init {
|
||||
if (media.file is MultipartFile) {
|
||||
throw IllegalArgumentException("For editing of media messages you MUST use file id (according to documentation)")
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<MediaContent>>
|
||||
get() = MediaContentMessageResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editMessageMedia(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
media: InputMedia,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
EditChatMessageMedia(chatId, messageId, media, replyMarkup)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.editMessageMedia(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
media: InputMedia,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editMessageMedia(chat.id, messageId, media, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.editMessageMedia(
|
||||
message: ContentMessage<out MediaContent>,
|
||||
media: InputMedia,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editMessageMedia(message.chat.id, message.messageId, media, replyMarkup)
|
@@ -0,0 +1,36 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageMedia(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(mediaField)
|
||||
override val media: InputMedia,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage, EditMediaMessage {
|
||||
|
||||
init {
|
||||
if (media.file is MultipartFile) {
|
||||
throw IllegalArgumentException("For editing of media messages you MUST use file id (according to documentation)")
|
||||
}
|
||||
}
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editMessageCaption(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
media: InputMedia,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(EditInlineMessageMedia(inlineMessageId, media, replyMarkup))
|
@@ -0,0 +1,66 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.TextContentMessageResultDeserializer
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
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.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageTextMethod = "editMessageText"
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageText(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(disableWebPagePreviewField)
|
||||
override val disableWebPagePreview: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage<TextContent>, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
|
||||
override fun method(): String = editMessageTextMethod
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<TextContent>>
|
||||
get() = TextContentMessageResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editMessageText(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
disableWebPagePreview: Boolean? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
EditChatMessageText(chatId, messageId, text, parseMode, disableWebPagePreview, replyMarkup)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.editMessageText(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
disableWebPagePreview: Boolean? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editMessageText(chat.id, messageId, text, parseMode, disableWebPagePreview, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.editMessageText(
|
||||
message: ContentMessage<TextContent>,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
disableWebPagePreview: Boolean? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editMessageText(message.chat.id, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup)
|
@@ -0,0 +1,36 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.editMessageMediaMethod
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageText(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(disableWebPagePreviewField)
|
||||
override val disableWebPagePreview: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editMessageText(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
text: String,
|
||||
parseMode: ParseMode? = null,
|
||||
disableWebPagePreview: Boolean? = null,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(EditInlineMessageText(inlineMessageId, text, parseMode, disableWebPagePreview, replyMarkup))
|
@@ -0,0 +1,70 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.GameContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class GetGameHighScoresByChat (
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatId,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier
|
||||
) : GetGameHighScores, MessageAction {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
|
||||
suspend fun RequestsExecutor.getGameScore(
|
||||
userId: UserId,
|
||||
chatId: ChatId,
|
||||
messageId: MessageIdentifier
|
||||
) = execute(
|
||||
GetGameHighScoresByChat(userId, chatId, messageId)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.getGameScore(
|
||||
user: CommonUser,
|
||||
chatId: ChatId,
|
||||
messageId: MessageIdentifier
|
||||
) = getGameScore(
|
||||
user.id, chatId, messageId
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.getGameScore(
|
||||
userId: UserId,
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier
|
||||
) = getGameScore(
|
||||
userId, chat.id, messageId
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.getGameScore(
|
||||
user: CommonUser,
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier
|
||||
) = getGameScore(
|
||||
user.id, chat.id, messageId
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.getGameScore(
|
||||
userId: UserId,
|
||||
message: ContentMessage<GameContent>
|
||||
) = getGameScore(
|
||||
userId, message.chat.id, message.messageId
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.getGameScore(
|
||||
user: CommonUser,
|
||||
message: ContentMessage<GameContent>
|
||||
) = getGameScore(
|
||||
user.id, message.chat.id, message.messageId
|
||||
)
|
@@ -0,0 +1,32 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class GetGameHighScoresByInlineMessageId (
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier
|
||||
) : GetGameHighScores, InlineMessageAction {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.getGameScore(
|
||||
userId: UserId,
|
||||
inlineMessageId: InlineMessageIdentifier
|
||||
) = execute(
|
||||
GetGameHighScoresByInlineMessageId(
|
||||
userId, inlineMessageId
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.getGameScore(
|
||||
user: CommonUser,
|
||||
inlineMessageId: InlineMessageIdentifier
|
||||
) = getGameScore(user.id, inlineMessageId)
|
@@ -0,0 +1,94 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.GameContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class SetGameScoreByChatId (
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(scoreField)
|
||||
override val score: Long,
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatId,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(forceField)
|
||||
override val force: Boolean = false,
|
||||
@SerialName(disableEditMessageField)
|
||||
override val disableEditMessage: Boolean = false
|
||||
) : SetGameScore, MessageAction {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
|
||||
suspend fun RequestsExecutor.setGameScore(
|
||||
userId: UserId,
|
||||
score: Long,
|
||||
chatId: ChatId,
|
||||
messageId: MessageIdentifier,
|
||||
force: Boolean = false,
|
||||
disableEditMessage: Boolean = false
|
||||
) = execute(
|
||||
SetGameScoreByChatId(userId, score, chatId, messageId, force, disableEditMessage)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.setGameScore(
|
||||
user: CommonUser,
|
||||
score: Long,
|
||||
chatId: ChatId,
|
||||
messageId: MessageIdentifier,
|
||||
force: Boolean = false,
|
||||
disableEditMessage: Boolean = false
|
||||
) = setGameScore(
|
||||
user.id, score, chatId, messageId, force, disableEditMessage
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.setGameScore(
|
||||
userId: UserId,
|
||||
score: Long,
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
force: Boolean = false,
|
||||
disableEditMessage: Boolean = false
|
||||
) = setGameScore(
|
||||
userId, score, chat.id, messageId, force, disableEditMessage
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.setGameScore(
|
||||
user: CommonUser,
|
||||
score: Long,
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
force: Boolean = false,
|
||||
disableEditMessage: Boolean = false
|
||||
) = setGameScore(
|
||||
user.id, score, chat.id, messageId, force, disableEditMessage
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.setGameScore(
|
||||
userId: UserId,
|
||||
score: Long,
|
||||
message: ContentMessage<GameContent>,
|
||||
force: Boolean = false,
|
||||
disableEditMessage: Boolean = false
|
||||
) = setGameScore(
|
||||
userId, score, message.chat.id, message.messageId, force, disableEditMessage
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.setGameScore(
|
||||
user: CommonUser,
|
||||
score: Long,
|
||||
message: ContentMessage<GameContent>,
|
||||
force: Boolean = false,
|
||||
disableEditMessage: Boolean = false
|
||||
) = setGameScore(
|
||||
user.id, score, message.chat.id, message.messageId, force, disableEditMessage
|
||||
)
|
@@ -0,0 +1,44 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class SetGameScoreByInlineMessageId (
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(scoreField)
|
||||
override val score: Long,
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(forceField)
|
||||
override val force: Boolean = false,
|
||||
@SerialName(disableEditMessageField)
|
||||
override val disableEditMessage: Boolean = false
|
||||
) : SetGameScore, InlineMessageAction {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.setGameScore(
|
||||
userId: UserId,
|
||||
score: Long,
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
force: Boolean = false,
|
||||
disableEditMessage: Boolean = false
|
||||
) = execute(
|
||||
SetGameScoreByInlineMessageId(
|
||||
userId, score, inlineMessageId, force, disableEditMessage
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.setGameScore(
|
||||
user: CommonUser,
|
||||
score: Long,
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
force: Boolean = false,
|
||||
disableEditMessage: Boolean = false
|
||||
) = setGameScore(user.id, score, inlineMessageId, force, disableEditMessage)
|
@@ -0,0 +1,18 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.games.GameHighScore
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
interface GetGameHighScores : SimpleRequest<List<GameHighScore>> {
|
||||
val userId: UserId
|
||||
|
||||
override fun method(): String = "getGameHighScores"
|
||||
override val resultDeserializer: DeserializationStrategy<List<GameHighScore>>
|
||||
get() = GameHighScoresSerializer
|
||||
}
|
||||
|
||||
internal object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ArrayListSerializer(GameHighScore.serializer())
|
@@ -0,0 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.serializer
|
||||
|
||||
interface SetGameScore : SimpleRequest<Boolean> {
|
||||
val userId: UserId
|
||||
val score: Long
|
||||
val force: Boolean
|
||||
val disableEditMessage: Boolean
|
||||
|
||||
override fun method(): String = "setGameScore"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user