1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-11-17 20:40:20 +00:00

Compare commits

...

173 Commits

Author SHA1 Message Date
4c08fb7d26 small improvement in #732 solution 2023-03-08 16:41:10 +06:00
d83ff12560 update dependencies 2023-03-08 16:38:24 +06:00
818ef8481d fix of #732 2023-03-08 16:33:41 +06:00
f8cd446133 start 6.1.0 2023-03-08 16:24:31 +06:00
804b991921 update kdocs 2023-03-04 21:18:50 +06:00
817068aa71 Merge pull request #731 from InsanusMokrassar/renovate/dokka
Update dependency org.jetbrains.dokka:dokka-gradle-plugin to v1.8.10
2023-03-04 10:48:42 +06:00
renovate[bot]
0cca343612 Update dependency org.jetbrains.dokka:dokka-gradle-plugin to v1.8.10 2023-03-04 03:54:29 +00:00
6532bf255b Merge pull request #730 from InsanusMokrassar/6.0.3
6.0.3
2023-03-02 23:28:16 +06:00
421d5ae9e3 Update CHANGELOG.md 2023-03-02 21:59:58 +06:00
54f1181a14 Update libs.versions.toml 2023-03-02 21:59:26 +06:00
f616a02f7c hotfixes 2023-03-02 20:33:49 +06:00
f1deb93147 changes in InlineQuery 2023-03-02 19:33:15 +06:00
2300b44aae fix in CallbackQuery 2023-03-02 12:43:39 +06:00
fe88cf037a fixes in deeplinks 2023-03-02 08:32:06 +06:00
89920abe35 start 6.0.3 2023-03-02 08:31:35 +06:00
4c4aa491cb Merge pull request #729 from InsanusMokrassar/6.0.2
6.0.2
2023-03-01 15:33:43 +06:00
f0a4425be9 Update CHANGELOG.md 2023-03-01 15:31:34 +06:00
6c8af4cab3 fixes in media groups collecting and kdocs 2023-03-01 13:14:18 +06:00
017d57e5e5 fixes 2023-03-01 12:38:50 +06:00
5a456bcdbf add opportunity to collect media groups with debounce 2023-03-01 11:55:17 +06:00
4182d8f3fe start 6.0.2 2023-03-01 00:59:08 +06:00
c6e2cba09b Merge pull request #728 from InsanusMokrassar/6.0.1
6.0.1
2023-02-28 20:41:35 +06:00
8dd3eefd15 Update CHANGELOG.md 2023-02-28 19:59:23 +06:00
b72d4da8f0 Update libs.versions.toml 2023-02-28 19:57:11 +06:00
ebd023669d start 6.0.1 2023-02-28 19:55:29 +06:00
f7be4e557e Merge pull request #726 from InsanusMokrassar/6.0.0
6.0.0
2023-02-28 13:27:41 +06:00
ec434c6af4 fill changelog with dependencies updates 2023-02-27 22:42:28 +06:00
0398590de6 update microutils version to release one 2023-02-27 22:40:26 +06:00
9ef1b54ada *.link renames 2023-02-27 22:32:08 +06:00
c30ce5c803 revert gradle wrapper version 2023-02-27 20:10:45 +06:00
c0a50bccb0 update publish.gradle and gradle wrapper version 2023-02-27 18:40:01 +06:00
e0cd7dc512 TelegramBot.resend 2023-02-27 18:27:23 +06:00
6ff621b428 Add triggers and waiters for VisualMediaGroupPartContent 2023-02-27 18:10:33 +06:00
964a61749c update dependencies 2023-02-27 17:57:32 +06:00
17930091ac start 6.0.0 2023-02-27 17:55:49 +06:00
2271beadfb Update README.md 2023-02-24 15:31:33 +06:00
44c48a8462 Add files via upload 2023-02-24 15:30:36 +06:00
4d35f89ad1 Merge pull request #722 from InsanusMokrassar/5.2.1
5.2.1
2023-02-21 21:44:53 +06:00
174706b189 changelog fill and callback query improvements 2023-02-19 18:35:36 +06:00
fe17312bb5 Update LiveFlowLocation.kt 2023-02-17 15:50:49 +06:00
d8b5789cd2 5.2.1 2023-02-17 15:48:02 +06:00
f27d0916db Merge pull request #721 from InsanusMokrassar/5.2.0
hotfix in LiveFlowLocation (5.2.0)
2023-02-17 15:42:17 +06:00
fa0a2818a0 hotfix in LiveFlowLocation 2023-02-17 15:40:49 +06:00
2d3fe45389 Merge pull request #720 from InsanusMokrassar/5.2.0
5.2.0
2023-02-17 15:36:27 +06:00
02b5d282d3 now it is possible to handle send content message in handleLiveLocation 2023-02-17 15:31:40 +06:00
7795bc2b50 LiveLocationProvider#message now is public, but as value instead of variable 2023-02-17 15:28:41 +06:00
a95365a691 update microutils up to 0.16.10 2023-02-17 14:03:00 +06:00
07082bf896 start 5.2.0 2023-02-17 14:02:18 +06:00
6a3fc47f62 Merge pull request #717 from InsanusMokrassar/5.1.1
5.1.1
2023-02-17 14:01:21 +06:00
1c94e86b40 small improvements 2023-02-13 12:06:28 +06:00
0416b200b8 fixes :) 2023-02-13 12:03:23 +06:00
48c4e90912 fixes 2023-02-13 12:00:09 +06:00
5fc88e89b9 Fixes in content waiting expectators 2023-02-13 11:49:36 +06:00
dad42cf939 makeUserLink 2023-02-13 11:16:49 +06:00
041c3ecc1b start 5.1.1 2023-02-11 18:57:46 +06:00
103dd949ce Merge pull request #712 from InsanusMokrassar/5.1.0
5.1.0
2023-02-06 14:08:03 +06:00
e3acdf1802 fix of #697 2023-02-06 13:28:38 +06:00
f81d28dd5f fill changelog and fix several issues 2023-02-06 12:41:19 +06:00
8e02a702f1 improvements in ChatPermissions 2023-02-06 12:04:30 +06:00
cb7a343208 improve copying functions in chat permissions 2023-02-06 11:36:00 +06:00
3be8ddae74 rights copying hotfix 2023-02-06 11:29:07 +06:00
9cd1862300 add opportunity to copy chat permissions 2023-02-06 11:25:31 +06:00
81fdf50217 ChatPermissions now is interface 2023-02-06 10:26:48 +06:00
554d47e301 Update README.md 2023-02-06 00:59:33 +06:00
b66ae7ad77 Update README.md 2023-02-06 00:58:36 +06:00
4ddced8e26 Merge pull request #715 from madhead/feature/replace_can_send_media_messages_field
Replaced the fields `can_send_media_messages`…
2023-02-06 00:25:40 +06:00
d003047a6c Merge branch '5.1.0' into feature/replace_can_send_media_messages_field 2023-02-06 00:24:19 +06:00
1e4a78c812 add support for independent chat permissions 2023-02-06 00:21:46 +06:00
2a3ffd707e improvements in KeyboardButtonRequestChat 2023-02-05 23:41:02 +06:00
aca076381b renames in request buttons 2023-02-05 23:26:41 +06:00
12ac227d2d small fix in request chat button 2023-02-05 23:18:14 +06:00
e235280253 fixes in RequestId 2023-02-05 22:29:21 +06:00
0da0c4e894 Revert "fixes in keyboards"
This reverts commit ae8ef0dd3c.
2023-02-05 22:25:43 +06:00
47f1509ecc add RequestId.random 2023-02-05 22:01:43 +06:00
ae8ef0dd3c fixes in keyboards 2023-02-05 21:47:15 +06:00
687f9e95fa support of user shared/chat shared 2023-02-05 20:46:25 +06:00
6dbe5f024f Merge pull request #713 from madhead/feature/user_chat_id_in_chat_join_request
Add support for `user_chat_id` field
2023-02-05 18:34:36 +06:00
a39a276299 Update libs.versions.toml 2023-02-05 18:34:05 +06:00
9f57e5685f Merge branch '5.1.0' into feature/user_chat_id_in_chat_join_request 2023-02-05 18:33:43 +06:00
bdcba202c9 Update ChatJoinRequest.kt 2023-02-05 18:32:46 +06:00
3c48dcb2a6 downgrade kotlin 2023-02-05 18:26:29 +06:00
b59d94d0a9 Update libs.versions.toml 2023-02-05 17:41:45 +06:00
db74b55c41 Update CHANGELOG.md 2023-02-05 17:41:45 +06:00
37b5af235a start 5.1.0 2023-02-05 17:41:07 +06:00
e2b05ce575 Merge pull request #711 from InsanusMokrassar/5.0.2
5.0.2
2023-02-05 17:34:42 +06:00
49851ee3d7 update micro_utils version 2023-02-05 16:22:33 +06:00
madhead
cd596cc66d Replaced the fields can_send_media_messages in the classes RestrictedChatMember and ChatPermissions with separate fields can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes for different media types. 2023-02-03 22:16:21 +01:00
madhead
5667ae8095 Added the field user_chat_id to the class ChatJoinRequest. 2023-02-03 21:26:55 +01:00
f29996aac8 Update libs.versions.toml 2023-02-04 00:56:47 +06:00
32613bacc6 Update CHANGELOG.md 2023-02-04 00:56:06 +06:00
cf9dba0ecc start 5.1.0 2023-02-04 00:55:46 +06:00
a8c4879769 update dependencies 2023-02-02 09:25:21 +06:00
f083e94c05 fix in BehaviourContext.onEditedContentMessage 2023-02-02 09:24:16 +06:00
c332413e5a start 5.0.2 2023-02-02 09:21:57 +06:00
c9f3d99cd7 Merge pull request #708 from InsanusMokrassar/5.0.1
5.0.1
2023-01-18 23:45:19 +06:00
cf3d07a20d update microutils and fill changelog 2023-01-18 23:44:39 +06:00
e40548e558 fix of return type in SendMediaGroup and fill changelog 2023-01-14 22:09:27 +06:00
4cd8e823c6 Update libs.versions.toml 2023-01-14 09:19:53 +06:00
9c7faec124 Merge pull request #707 from madhead/bugfix/SetChatAdministratorCustomTitle.serializer()
Fix the `requestSerializer` for `SetChatAdministratorCustomTitle`
2023-01-14 09:18:36 +06:00
2856880a6e start 5.0.1 2023-01-14 09:16:04 +06:00
madhead
5445fdbfa5 Fix the requestSerializer for SetChatAdministratorCustomTitle 2023-01-14 00:26:49 +01:00
ba53d0c75d Update CHANGELOG.md 2022-12-31 16:23:24 +06:00
78f6cc5a97 Update README.md 2022-12-31 16:22:57 +06:00
6ab7c6f9d9 Update CHANGELOG.md 2022-12-31 16:21:49 +06:00
cb6b33727e Merge pull request #704 from InsanusMokrassar/5.0.0
5.0.0
2022-12-31 16:04:38 +06:00
bc4a2235c5 add opportunity in long polling to automatically delete webhook 2022-12-31 15:23:14 +06:00
300f94fd48 fixes 2022-12-31 15:23:14 +06:00
40617ad9c8 add support of Bot API 6.5 web apps 2022-12-31 15:23:14 +06:00
bea056bba3 add full support of editGeneralForumTopic, closeGeneralForumTopic, reopenGeneralForumTopic, hideGeneralForumTopic, unhideGeneralForumTopic 2022-12-31 15:23:14 +06:00
9a33451f88 add support of forum_topic_edited, general_forum_topic_hidden, general_forum_topic_unhidden, and write_access_allowed 2022-12-31 15:23:14 +06:00
c4659b558f add support of has_aggressive_anti_spam_enabled 2022-12-31 15:23:14 +06:00
5a30a07554 add support of has_hidden_members 2022-12-31 15:23:14 +06:00
b064becb8a add support of topics for actions 2022-12-31 15:23:14 +06:00
463d5252bd editForumtTopic optional fields 2022-12-31 15:23:14 +06:00
8b5da90e28 add spoilered in telegrammedia 2022-12-31 15:23:14 +06:00
febd6ce63c support of has_media_spoiler in message and sendPhoto/sendVideo/sendAnimation 2022-12-31 15:23:14 +06:00
8df8b87d54 add ReplyKeyboardMarkup 2022-12-31 15:23:14 +06:00
c882717bcc start 5.0.0 2022-12-31 15:23:14 +06:00
4aa5924615 Update CHANGELOG.md 2022-12-31 15:17:21 +06:00
2b8e728559 fixes in updateHandlerWithMediaGroupsAdaptation 2022-12-31 15:17:21 +06:00
90ad34f114 Update BehaviourContextWithFSM.kt 2022-12-31 15:17:21 +06:00
dbe2607994 Update BehaviourContextWithFSM.kt 2022-12-31 15:17:21 +06:00
692b668f92 fixes and improvements 2022-12-31 15:17:21 +06:00
f2322e3e57 Fixes in DefaultBehaviourContextWithFSM 2022-12-31 15:17:21 +06:00
ae002ead43 start 4.2.4 2022-12-31 15:17:21 +06:00
4197e13c54 Update CHANGELOG.md 2022-12-28 09:12:54 +06:00
e09ea9a9b4 upfill changelog 2022-12-28 09:11:49 +06:00
2a32654d57 update miroutils and fill changelog 2022-12-28 09:05:32 +06:00
0fff553ce1 Update KtorRequestsExecutor.kt 2022-12-27 22:31:42 +06:00
33a1701f5b Update ExceptionsOnlyLimiter.kt 2022-12-27 22:30:47 +06:00
f9a9f958ba Update ExceptionsOnlyLimiter.kt 2022-12-27 22:25:26 +06:00
f686be0271 Update ExceptionsOnlyLimiter.kt 2022-12-27 22:22:03 +06:00
91307f3ebf improvements in ExceptionsOnlyLimiter 2022-12-26 21:37:48 +06:00
8e64205f53 several improvements in requests limiters 2022-12-26 20:49:29 +06:00
5434df1f02 Merge pull request #695 from InsanusMokrassar/4.2.2
4.2.2
2022-12-18 10:05:17 +06:00
e56199ac9f Update CHANGELOG.md 2022-12-18 10:01:46 +06:00
3e199c6944 Update libs.versions.toml 2022-12-18 10:01:25 +06:00
b43d9aefb9 fix of #694 2022-12-13 10:52:56 +06:00
fe133bbde0 update microutils 2022-12-13 10:49:18 +06:00
332fe95adf start 4.2.2 2022-12-13 10:48:38 +06:00
1f416d4a28 Merge pull request #693 from InsanusMokrassar/4.2.1
4.2.1
2022-12-08 10:50:07 +06:00
e626d8b5cc fix dependencies and fill changelog 2022-12-08 10:30:26 +06:00
b906d605f4 temporal include of internal microutils build 2022-12-08 09:35:22 +06:00
d3584e793c add makeChatLink 2022-12-08 09:17:58 +06:00
f71ac51461 improve makeLinkToMessage 2022-12-08 09:06:54 +06:00
5fe8cf948a start 4.2.1 2022-12-08 08:57:54 +06:00
85ea101641 Merge pull request #691 from InsanusMokrassar/4.2.0
4.2.0
2022-12-05 11:52:47 +06:00
dc3ecec5c7 Update CHANGELOG.md 2022-12-05 11:51:46 +06:00
ebd5e1a37b Update libs.versions.toml 2022-12-05 05:57:43 +06:00
3da2e4fffb starr 4.2.0 2022-12-05 05:55:15 +06:00
9aea59b44b Update gradle-wrapper.properties 2022-11-28 16:37:50 +06:00
7bab96a9cd Merge pull request #686 from InsanusMokrassar/4.1.3
4.1.3
2022-11-28 16:35:58 +06:00
a0c10d9a9a Update CHANGELOG.md 2022-11-27 17:38:24 +06:00
e2901cb9f9 Update libs.versions.toml 2022-11-27 17:38:16 +06:00
3c60d074ba Update CHANGELOG.md 2022-11-24 19:28:32 +06:00
f10cfdc5f1 Update libs.versions.toml 2022-11-24 19:27:56 +06:00
270f9a60c1 fixes 2022-11-20 13:28:23 +06:00
2b49a75a42 UserId = ChatId 2022-11-20 13:21:20 +06:00
9f7a348000 fill changelog 2022-11-18 23:08:16 +06:00
8cec74aa6a fix in gitea publishing name 2022-11-18 22:22:03 +06:00
d1914c8045 update order of publishing steps 2022-11-18 22:16:47 +06:00
baeb4848cf test version with outs variations of content message generics 2022-11-18 22:11:03 +06:00
dbadcb3f5a Merge pull request #685 from InsanusMokrassar/4.1.2
4.1.2
2022-11-17 12:55:37 +06:00
13dd73dd63 update dependencies 2022-11-17 12:34:33 +06:00
ceba86abcb Fixes in CallbackQuery waiters 2022-11-17 12:33:16 +06:00
f6a0b1a19d start 4.1.2 2022-11-17 12:30:26 +06:00
4ed6e5c7b2 add gitea publication 2022-11-17 11:26:05 +06:00
7f43dc0815 Merge pull request #684 from InsanusMokrassar/4.1.1
4.1.1
2022-11-14 23:24:03 +06:00
c72993017f FullChatIdentifierSerializer 2022-11-11 21:44:37 +06:00
e8991f8f89 Add opportunity to create "IdChatIdentifier" with optional "threadId" 2022-11-11 12:59:42 +06:00
03cd4276a9 start 4.1.1 2022-11-11 12:58:11 +06:00
4427d76cd1 Update FUNDING.yml 2022-11-10 20:50:36 +06:00
00f504a095 Merge pull request #682 from InsanusMokrassar/4.1.0
4.1.0
2022-11-10 20:18:52 +06:00
142 changed files with 3209 additions and 570 deletions

2
.github/FUNDING.yml vendored
View File

@@ -1,3 +1,3 @@
# These are supported funding model platforms # These are supported funding model platforms
custom: ['https://www.tinkoff.ru/rm/ovsyannikov.aleksey113/ObMJ712472'] custom: ['https://www.tinkoff.ru/rm/ovsyannikov.aleksey113/ObMJ712472', 'https://boosty.to/insanusmokrassar']

View File

@@ -12,10 +12,10 @@ jobs:
with: with:
java-version: 11 java-version: 11
- name: Build - name: Build
run: ./gradlew dokkaHtml run: ./gradlew dokkaHtmlMultiModule
- name: Publish KDocs - name: Publish KDocs
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build/dokka/html publish_dir: ./build/dokka/htmlMultiModule
publish_branch: kdocs publish_branch: kdocs

View File

@@ -16,7 +16,12 @@ jobs:
mv gradle.properties.tmp gradle.properties mv gradle.properties.tmp gradle.properties
- name: Build - name: Build
run: ./gradlew build run: ./gradlew build
- name: Publish - name: Publish to Gitea
continue-on-error: true
run: ./gradlew publishAllPublicationsToGiteaRepository
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
- name: Publish to GithubPackages
continue-on-error: true continue-on-error: true
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel
env: env:

View File

@@ -1,5 +1,162 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 6.1.0
* `Versions`:
* `MicroUtils`: `0.17.2` -> `0.17.3`
* `API`:
* Fix of [#732](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/732)
## 6.0.3
* `Versions`:
* `MicroUtils`: `0.17.1` -> `0.17.2`
* `Core`:
* `User` in `CallbackQuery` now is `CommonUser` as well as in `from`
* `User` in `InlineQuery` now is `CommonUser` as well as in `from`
* `BehaviourBuilder`:
* Fixes in `DeepLink` triggers and waiters
## 6.0.2
* `Core`:
* Long polling now uses media groups debounce as in webhooks
## 6.0.1
* `Versions`:
* `Ktor`: `2.2.3` -> `2.2.4`
* `MicroUtils`: `0.17.0` -> `0.17.1`
## 6.0.0
* `Versions`:
* `Kotlin`: `1.7.22` -> `1.8.10`
* `MicroUtils`: `0.16.10` -> `0.17.0`
* `Serialization`: `1.4.1` -> `1.5.0`
* `uuid`: `0.6.0` -> `0.7.0`
* `Core`:
* `*.link` extensions have been deprecated with renaming to avoid collisions with `link` methods
* `API`:
* Add `TelegramBot.resend` methods
* `BehaviourBuilder`:
* Add triggers and waiters for `VisualMediaGroupPartContent`
* `Utils`:
* `*.link` extensions have been deprecated with renaming to avoid collisions with `link` methods
## 5.2.1
* `Core`:
* All the `CallbackQuery`es now will receive `CommonUser` instead of `User` due inability of bots to trigger any
inline interaction with others bots
* `API`:
* Now `sentMessageFlow` will take each sent message in `handleLiveLocation`
## 5.2.0
* `Versions`:
* `MicroUtils`: `0.16.8` -> `0.16.10`
## 5.1.1
* `Core`:
* Add opportunity to get user link with `makeUserLink`
* `BehaviourBuilder`:
* Fixes in content waiting expectators
## 5.1.0
[Bot API 6.5](https://core.telegram.org/bots/api-changelog#february-3-2023) support
* `Core`:
* `ChatPermissions` now is interface and have two main realizations: `ChatPermissions.Granular` and
`ChatPermissions.Common`
* `RestrictedChatMember` now implements `ChatPermissions` too
* `API`:
* Now it is possible to pass all long polling parameters in all places used it
* `Issues`:
* Fix of [#697](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/697)
## 5.0.2
* `Versions`:
* `MicroUtils`: `0.16.6` -> `0.16.8`
* `Ktor`: `2.2.2` -> `2.2.3`
* `BehaviourBuilder`:
* Fixes in `BehaviourContext.onEditedContentMessage` - now it will trigger callback on channel post edits too
## 5.0.1
* `Versions`:
* `MicroUtils`: `0.16.4` -> `0.16.6`
* `Ktor`: `2.2.1` -> `2.2.2`
* `Core`:
* Fixes in `SendMediaGroup` request
* Fixes in `SetChatAdministratorCustomTitle` request (thanks to [@madhead](https://github.com/madhead))
## 5.0.0
[Bot API 6.4](https://core.telegram.org/bots/api-changelog#december-30-2022) support!
* Long-polling improvements
## 4.2.4
* `Core`:
* Fixes in webhook parts adapter
* `BehaviourBuilderWithFSM`:
* Fixes in `DefaultBehaviourContextWithFSM`
## 4.2.3
* `Versions`:
* `MicroUtils`: `0.16.2` -> `0.16.4`
* `Core`:
* Simplify default `RequestsLimiter` (`ExceptionsOnlyLimiter`) (thanks to [@y9san9](https://github.com/y9san9) for help)
## 4.2.2
* `Versions`:
* `MicroUtils`: `0.16.0` -> `0.16.2`
* `Core`:
* Fix of [#694](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/694): add opportunity to create `ChatId` and `ChatIdWithThreadId` from `IdChatIdentifier`
## 4.2.1
* `Versions`:
* `MicroUtils`: `0.15.0` -> `0.16.0`
* `Ktor`: `2.1.3` -> `2.2.1`
* `Utils`:
* Improve support of `makeLinkToMessage` extensions
## 4.2.0
* `Versions`:
* `Kotlin`: `1.7.21` -> `1.7.22`
* `MicroUtils`: `0.14.4` -> `0.15.0`
## 4.1.3
* `Versions`:
* `MicroUtils`: `0.14.2` -> `0.14.4`
* `Core`:
* `ContentMessage`, `CommonMessage`, `PossiblyMediaGroupMessage` and `PossiblySentViaBotCommonMessage` got `out`
variance
* `UserId` now is `ChatId` instead of `IdChatIdentififer`
## 4.1.2
* `Versions`:
* `MicroUtils`: `0.14.1` -> `0.14.2`
* `BehaviourBuilder`:
* Fixes in `CallbackQuery` waiters
## 4.1.1
* `Core`:
* Add opportunity to create `IdChatIdentifier` with optional `threadId`
* New serializer `FullChatIdentifierSerializer` with serialization of `ChatIdWithThreadId`
## 4.1.0 ## 4.1.0
* `Versions`: * `Versions`:

View File

@@ -1,14 +1,14 @@
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-6.3-blue)](https://core.telegram.org/bots/api-changelog#november-5-2022) # TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-6.5-blue)](https://core.telegram.org/bots/api-changelog#february-3-2023)
| Docs | [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Bookstack&message=Tutorial&color=blue&logo=bookstack)](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) | | Docs | [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Bookstack&message=Tutorial&color=blue&logo=bookstack)](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
|:---:|:---:| |:---:|:---:|
| Useful repos | [![Create bot](https://img.shields.io/static/v1?label=Github&message=Template&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![Examples](https://img.shields.io/static/v1?label=Github&message=Examples&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) | | Useful repos | [![Create bot](https://img.shields.io/static/v1?label=Github&message=Template&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![Examples](https://img.shields.io/static/v1?label=Github&message=Examples&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) |
| Misc | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue&logo=google-sheets)](https://docs.google.com/forms/d/e/1FAIpQLSctdJHT_aEniyYT0-IUAEfo1hsIlezX2owlkEAYX4KPl2V2_A/viewform?usp=sf_link) | | Misc | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue&logo=google-sheets)](https://docs.google.com/forms/d/e/1FAIpQLSctdJHT_aEniyYT0-IUAEfo1hsIlezX2owlkEAYX4KPl2V2_A/viewform?usp=sf_link) |
<!--- [![Telegram Channel](./resources/tg_channel_qr.jpg)](https://t.me/InMoTelegramBotAPI) ---> <!--- [![Telegram Channel](./resources/tg_channel_qr.jpg)](https://t.me/ktgbotapi) --->
<p align="center"> <p align="center">
<a href="https://t.me/InMoTelegramBotAPI"> <a href="https://t.me/ktgbotapi">
<img src="./resources/tg_channel_qr.jpg"> <img src="./resources/tg_channel_qr.jpg">
</a> </a>
</p> </p>

View File

@@ -14,12 +14,17 @@ buildscript {
} }
} }
plugins {
alias(libs.plugins.kotlin.dokka)
}
// temporal crutch until legacy tests will be stabled or legacy target will be removed // temporal crutch until legacy tests will be stabled or legacy target will be removed
allprojects { allprojects {
repositories { repositories {
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
google() google()
maven { url "https://git.inmo.dev/api/packages/InsanusMokrassar/maven" }
} }
if (it != rootProject.findProject("docs")) { if (it != rootProject.findProject("docs")) {
tasks.whenTaskAdded { task -> tasks.whenTaskAdded { task ->

View File

@@ -6,4 +6,4 @@ kotlin.incremental=true
kotlin.incremental.js=true kotlin.incremental.js=true
library_group=dev.inmo library_group=dev.inmo
library_version=4.1.0 library_version=6.1.0

View File

@@ -1,22 +1,22 @@
[versions] [versions]
kotlin = "1.7.21" kotlin = "1.8.10"
kotlin-serialization = "1.4.1" kotlin-serialization = "1.5.0"
kotlin-coroutines = "1.6.4" kotlin-coroutines = "1.6.4"
javax-activation = "1.1.1" javax-activation = "1.1.1"
korlibs = "3.4.0" korlibs = "3.4.0"
uuid = "0.6.0" uuid = "0.7.0"
ktor = "2.1.3" ktor = "2.2.4"
ksp = "1.7.21-1.0.8" ksp = "1.8.10-1.0.9"
kotlin-poet = "1.12.0" kotlin-poet = "1.12.0"
microutils = "0.14.1" microutils = "0.17.3"
github-release-plugin = "2.4.1" github-release-plugin = "2.4.1"
dokka = "1.7.20" dokka = "1.8.10"
[libraries] [libraries]
@@ -67,3 +67,4 @@ github-release-plugin = { module = "com.github.breadmoirai:github-release", vers
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }

View File

@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip

View File

@@ -1,7 +1,8 @@
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
task javadocsJar(type: Jar) { task javadocsJar(type: Jar) {
classifier = 'javadoc' archiveClassifier.convention("javadoc")
archiveClassifier.set("javadoc")
} }
publishing { publishing {
@@ -19,22 +20,22 @@ publishing {
} }
developers { developers {
developer { developer {
id = "InsanusMokrassar" id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei" name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com" email = "ovsyannikov.alexey95@gmail.com"
} }
} }
licenses { licenses {
license { license {
name = "Apache Software License 2.0" name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE" url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
} }
} }
} }
repositories { repositories {
@@ -42,35 +43,55 @@ publishing {
maven { maven {
name = "GithubPackages" name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI") url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials { credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER') username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD') password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
} }
}
}
if (project.hasProperty('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) {
maven {
name = "Gitea"
url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven")
credentials(HttpHeaderCredentials) {
name = "Authorization"
value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN')
}
authentication {
header(HttpHeaderAuthentication)
}
} }
} }
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) { if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven { maven {
name = "sonatype" name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials { credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER') username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD') password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
} }
} }
} }
} }
} }
} }
if (project.hasProperty("signing.gnupg.keyName")) { if (project.hasProperty("signing.gnupg.keyName")) {
apply plugin: 'signing' apply plugin: 'signing'
signing { signing {
useGpgCmd() useGpgCmd()
sign publishing.publications sign publishing.publications
} }
task signAll { task signAll {
tasks.withType(Sign).forEach { tasks.withType(Sign).forEach {
dependsOn(it) dependsOn(it)

View File

@@ -1 +1 @@
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"${project.description}","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}} {"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"${project.description}","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"},{"name":"Gitea","url":"https://git.inmo.dev/api/packages/InsanusMokrassar/maven","credsType":{"type":"dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository.CredentialsType.HttpHeaderCredentials","headerName":"Authorization","headerValueProperty":"GITEA_TOKEN"}},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 593 KiB

After

Width:  |  Height:  |  Size: 448 KiB

View File

@@ -19,4 +19,3 @@ include ":tgbotapi.behaviour_builder"
include ":tgbotapi.behaviour_builder.fsm" include ":tgbotapi.behaviour_builder.fsm"
include ":tgbotapi" include ":tgbotapi"
include ":tgbotapi.webapps" include ":tgbotapi.webapps"
include ":docs"

View File

@@ -1,6 +1,7 @@
plugins { plugins {
id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization" id "org.jetbrains.kotlin.plugin.serialization"
id "org.jetbrains.dokka"
} }
project.description = "API extensions with \"Telegram Bot API\"-like extensions for TelegramBot and RequestsExecutor" project.description = "API extensions with \"Telegram Bot API\"-like extensions for TelegramBot and RequestsExecutor"

View File

@@ -5,7 +5,10 @@ import dev.inmo.tgbotapi.requests.DeleteMessage
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
suspend fun TelegramBot.deleteMessage( suspend fun TelegramBot.deleteMessage(
chatId: ChatIdentifier, chatId: ChatIdentifier,
@@ -21,7 +24,16 @@ suspend fun TelegramBot.deleteMessage(
suspend fun TelegramBot.deleteMessage( suspend fun TelegramBot.deleteMessage(
message: Message message: Message
) = deleteMessage(message.chat, message.messageId) ): Boolean {
val mediaGroupContent = ((message as? ContentMessage<*>) ?.content as? MediaGroupCollectionContent<*>)
if (mediaGroupContent == null) {
return deleteMessage(message.chat, message.messageId)
} else {
return mediaGroupContent.group.map {
deleteMessage(it.sourceMessage)
}.all { it }
}
}
suspend fun TelegramBot.delete( suspend fun TelegramBot.delete(
chatId: ChatIdentifier, chatId: ChatIdentifier,

View File

@@ -6,7 +6,6 @@ import dev.inmo.tgbotapi.abstracts.*
import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.edit.edit import dev.inmo.tgbotapi.extensions.api.edit.edit
import dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation
import dev.inmo.tgbotapi.extensions.api.send.send import dev.inmo.tgbotapi.extensions.api.send.send
import dev.inmo.tgbotapi.extensions.api.send.sendLiveLocation import dev.inmo.tgbotapi.extensions.api.send.sendLiveLocation
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
@@ -17,6 +16,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.LocationContent import dev.inmo.tgbotapi.types.message.content.LocationContent
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlin.js.JsName import kotlin.js.JsName
@@ -45,7 +45,8 @@ suspend fun TelegramBot.handleLiveLocation(
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null allowSendingWithoutReply: Boolean? = null,
sentMessageFlow: FlowCollector<ContentMessage<LocationContent>>? = null
) { ) {
var currentLiveLocationMessage: ContentMessage<LocationContent>? = null var currentLiveLocationMessage: ContentMessage<LocationContent>? = null
val updateMessageJob = CoroutineScope(currentCoroutineContext().LinkedSupervisorJob()).launchSafelyWithoutExceptions(start = CoroutineStart.LAZY) { val updateMessageJob = CoroutineScope(currentCoroutineContext().LinkedSupervisorJob()).launchSafelyWithoutExceptions(start = CoroutineStart.LAZY) {
@@ -73,7 +74,9 @@ suspend fun TelegramBot.handleLiveLocation(
replyToMessageId, replyToMessageId,
allowSendingWithoutReply, allowSendingWithoutReply,
it.replyMarkup it.replyMarkup
) ).also {
sentMessageFlow ?.emit(it)
}
} else { } else {
edit( edit(
capturedLiveLocationMessage, capturedLiveLocationMessage,
@@ -83,7 +86,9 @@ suspend fun TelegramBot.handleLiveLocation(
it.heading, it.heading,
it.proximityAlertRadius, it.proximityAlertRadius,
it.replyMarkup it.replyMarkup
) ).also {
sentMessageFlow ?.emit(it)
}
} }
} }
} }
@@ -102,7 +107,8 @@ suspend fun TelegramBot.handleLiveLocation(
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null allowSendingWithoutReply: Boolean? = null,
sentMessageFlow: FlowCollector<ContentMessage<LocationContent>>? = null
) { ) {
handleLiveLocation( handleLiveLocation(
chatId, chatId,
@@ -121,7 +127,8 @@ suspend fun TelegramBot.handleLiveLocation(
disableNotification, disableNotification,
protectContent, protectContent,
replyToMessageId, replyToMessageId,
allowSendingWithoutReply allowSendingWithoutReply,
sentMessageFlow
) )
} }
@@ -139,7 +146,8 @@ suspend fun TelegramBot.handleLiveLocation(
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null allowSendingWithoutReply: Boolean? = null,
sentMessageFlow: FlowCollector<ContentMessage<LocationContent>>? = null
) { ) {
handleLiveLocation( handleLiveLocation(
chatId, chatId,
@@ -154,6 +162,7 @@ suspend fun TelegramBot.handleLiveLocation(
disableNotification, disableNotification,
protectContent, protectContent,
replyToMessageId, replyToMessageId,
allowSendingWithoutReply allowSendingWithoutReply,
sentMessageFlow
) )
} }

View File

@@ -2,15 +2,22 @@ package dev.inmo.tgbotapi.extensions.api
import com.soywiz.klock.DateTime import com.soywiz.klock.DateTime
import com.soywiz.klock.TimeSpan import com.soywiz.klock.TimeSpan
import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.edit.edit
import dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation import dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation
import dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation import dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation
import dev.inmo.tgbotapi.extensions.api.send.send
import dev.inmo.tgbotapi.extensions.api.send.sendLiveLocation
import dev.inmo.tgbotapi.requests.send.SendLiveLocation import dev.inmo.tgbotapi.requests.send.SendLiveLocation
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.location.LiveLocation import dev.inmo.tgbotapi.types.location.LiveLocation
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.location.StaticLocation
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.Message
@@ -18,7 +25,15 @@ import dev.inmo.tgbotapi.types.message.content.LocationContent
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
import io.ktor.utils.io.core.Closeable import io.ktor.utils.io.core.Closeable
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlin.js.JsName
import kotlin.jvm.JvmName
import kotlin.math.ceil import kotlin.math.ceil
val defaultLivePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L val defaultLivePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L
@@ -45,7 +60,8 @@ class LiveLocationProvider internal constructor(
private set private set
get() = field || leftUntilCloseMillis.millisecondsLong < 0L get() = field || leftUntilCloseMillis.millisecondsLong < 0L
private var message: ContentMessage<LocationContent> = initMessage var message: ContentMessage<LocationContent> = initMessage
private set
val lastLocation: LiveLocation val lastLocation: LiveLocation
get() = message.content.location as LiveLocation get() = message.content.location as LiveLocation

View File

@@ -0,0 +1,19 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.CloseForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.CloseGeneralForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
suspend fun TelegramBot.closeGeneralForumTopic(
chatId: ChatIdentifier
) = execute(
CloseGeneralForumTopic(chatId)
)
suspend fun TelegramBot.closeGeneralForumTopic(
chat: Chat
) = closeGeneralForumTopic(chat.id)

View File

@@ -11,8 +11,8 @@ import dev.inmo.tgbotapi.types.chat.Chat
suspend fun TelegramBot.editForumTopic( suspend fun TelegramBot.editForumTopic(
chatId: ChatIdentifier, chatId: ChatIdentifier,
messageThreadId: MessageThreadId, messageThreadId: MessageThreadId,
name: String, name: String? = null,
iconEmojiId: CustomEmojiId iconEmojiId: CustomEmojiId? = null
) = execute( ) = execute(
EditForumTopic( EditForumTopic(
chatId, chatId,
@@ -25,12 +25,12 @@ suspend fun TelegramBot.editForumTopic(
suspend fun TelegramBot.editForumTopic( suspend fun TelegramBot.editForumTopic(
chat: Chat, chat: Chat,
messageThreadId: MessageThreadId, messageThreadId: MessageThreadId,
name: String, name: String? = null,
iconEmojiId: CustomEmojiId iconEmojiId: CustomEmojiId? = null
) = editForumTopic(chat.id, messageThreadId, name, iconEmojiId) ) = editForumTopic(chat.id, messageThreadId, name, iconEmojiId)
suspend fun TelegramBot.editForumTopic( suspend fun TelegramBot.editForumTopic(
chatIdentifier: ChatIdentifier, chatIdentifier: ChatIdentifier,
forumTopic: ForumTopic, forumTopic: ForumTopic,
iconEmojiId: CustomEmojiId = forumTopic.iconEmojiId ?: error("Icon emoji id in forum topic should be presented when edit forum topic basing on other forum topic object") iconEmojiId: CustomEmojiId? = forumTopic.iconEmojiId
) = editForumTopic(chatIdentifier, forumTopic.messageThreadId, forumTopic.name, iconEmojiId) ) = editForumTopic(chatIdentifier, forumTopic.messageThreadId, forumTopic.name, iconEmojiId)

View File

@@ -0,0 +1,30 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.EditForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.EditGeneralForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.CustomEmojiId
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
suspend fun TelegramBot.editGeneralForumTopic(
chatId: ChatIdentifier,
name: String
) = execute(
EditGeneralForumTopic(
chatId,
name
)
)
suspend fun TelegramBot.editGeneralForumTopic(
chat: Chat,
name: String
) = editGeneralForumTopic(chat.id, name)
suspend fun TelegramBot.editGeneralForumTopic(
chatIdentifier: ChatIdentifier,
forumTopic: ForumTopic,
) = editGeneralForumTopic(chatIdentifier, forumTopic.name)

View File

@@ -0,0 +1,20 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.CloseForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.CloseGeneralForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.HideGeneralForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
suspend fun TelegramBot.hideGeneralForumTopic(
chatId: ChatIdentifier
) = execute(
HideGeneralForumTopic(chatId)
)
suspend fun TelegramBot.hideGeneralForumTopic(
chat: Chat
) = hideGeneralForumTopic(chat.id)

View File

@@ -0,0 +1,19 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.ReopenForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.ReopenGeneralForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
suspend fun TelegramBot.reopenGeneralForumTopic(
chatId: ChatIdentifier
) = execute(
ReopenGeneralForumTopic(chatId)
)
suspend fun TelegramBot.reopenGeneralForumTopic(
chat: Chat
) = reopenGeneralForumTopic(chat.id)

View File

@@ -0,0 +1,21 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.CloseForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.CloseGeneralForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.HideGeneralForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.UnhideGeneralForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
suspend fun TelegramBot.unhideGeneralForumTopic(
chatId: ChatIdentifier
) = execute(
UnhideGeneralForumTopic(chatId)
)
suspend fun TelegramBot.unhideGeneralForumTopic(
chat: Chat
) = unhideGeneralForumTopic(chat.id)

View File

@@ -14,27 +14,31 @@ suspend fun TelegramBot.restrictChatMember(
chatId: ChatIdentifier, chatId: ChatIdentifier,
userId: UserId, userId: UserId,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
permissions: ChatPermissions = ChatPermissions() permissions: ChatPermissions = ChatPermissions(),
) = execute(RestrictChatMember(chatId, userId, untilDate, permissions)) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = execute(RestrictChatMember(chatId, userId, untilDate, permissions, useIndependentChatPermissions))
suspend fun TelegramBot.restrictChatMember( suspend fun TelegramBot.restrictChatMember(
chat: PublicChat, chat: PublicChat,
userId: UserId, userId: UserId,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
permissions: ChatPermissions = ChatPermissions() permissions: ChatPermissions = ChatPermissions(),
) = restrictChatMember(chat.id, userId, untilDate, permissions) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = restrictChatMember(chat.id, userId, untilDate, permissions, useIndependentChatPermissions)
suspend fun TelegramBot.restrictChatMember( suspend fun TelegramBot.restrictChatMember(
chatId: IdChatIdentifier, chatId: IdChatIdentifier,
user: User, user: User,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
permissions: ChatPermissions = ChatPermissions() permissions: ChatPermissions = ChatPermissions(),
) = restrictChatMember(chatId, user.id, untilDate, permissions) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = restrictChatMember(chatId, user.id, untilDate, permissions, useIndependentChatPermissions)
suspend fun TelegramBot.restrictChatMember( suspend fun TelegramBot.restrictChatMember(
chat: PublicChat, chat: PublicChat,
user: User, user: User,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
permissions: ChatPermissions = ChatPermissions() permissions: ChatPermissions = ChatPermissions(),
) = restrictChatMember(chat.id, user.id, untilDate, permissions) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = restrictChatMember(chat.id, user.id, untilDate, permissions, useIndependentChatPermissions)

View File

@@ -8,10 +8,12 @@ import dev.inmo.tgbotapi.types.chat.PublicChat
suspend fun TelegramBot.setDefaultChatMembersPermissions( suspend fun TelegramBot.setDefaultChatMembersPermissions(
chatId: ChatIdentifier, chatId: ChatIdentifier,
permissions: ChatPermissions permissions: ChatPermissions,
) = execute(SetChatPermissions(chatId, permissions)) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = execute(SetChatPermissions(chatId, permissions, useIndependentChatPermissions))
suspend fun TelegramBot.setDefaultChatMembersPermissions( suspend fun TelegramBot.setDefaultChatMembersPermissions(
chat: PublicChat, chat: PublicChat,
permissions: ChatPermissions permissions: ChatPermissions,
) = setDefaultChatMembersPermissions(chat.id, permissions) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = setDefaultChatMembersPermissions(chat.id, permissions, useIndependentChatPermissions)

View File

@@ -379,6 +379,7 @@ suspend inline fun TelegramBot.replyWithAnimation(
thumb: InputFile? = null, thumb: InputFile? = null,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -392,6 +393,7 @@ suspend inline fun TelegramBot.replyWithAnimation(
thumb, thumb,
text, text,
parseMode, parseMode,
spoilered,
duration, duration,
width, width,
height, height,
@@ -408,6 +410,7 @@ suspend inline fun TelegramBot.reply(
animation: AnimationFile, animation: AnimationFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -415,12 +418,13 @@ suspend inline fun TelegramBot.reply(
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(to.chat, animation, text, parseMode, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(to.chat, animation, text, parseMode, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.replyWithAnimation( suspend inline fun TelegramBot.replyWithAnimation(
to: Message, to: Message,
animation: InputFile, animation: InputFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
thumb: InputFile? = null, thumb: InputFile? = null,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
@@ -434,6 +438,7 @@ suspend inline fun TelegramBot.replyWithAnimation(
animation, animation,
thumb, thumb,
entities, entities,
spoilered,
duration, duration,
width, width,
height, height,
@@ -449,6 +454,7 @@ suspend inline fun TelegramBot.reply(
to: Message, to: Message,
animation: AnimationFile, animation: AnimationFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -456,7 +462,7 @@ suspend inline fun TelegramBot.reply(
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(to.chat, animation, entities, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(to.chat, animation, entities, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
// Audio // Audio
@@ -608,64 +614,70 @@ suspend inline fun TelegramBot.replyWithPhoto(
fileId: InputFile, fileId: InputFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, fileId, text, parseMode, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(to.chat, fileId, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
to: Message, to: Message,
photo: Photo, photo: Photo,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, photo, text, parseMode, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(to.chat, photo, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
to: Message, to: Message,
photoSize: PhotoSize, photoSize: PhotoSize,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, photoSize, text, parseMode, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(to.chat, photoSize, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.replyWithPhoto( suspend inline fun TelegramBot.replyWithPhoto(
to: Message, to: Message,
fileId: InputFile, fileId: InputFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, fileId, entities, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(to.chat, fileId, entities, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
to: Message, to: Message,
photo: Photo, photo: Photo,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, photo, entities, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(to.chat, photo, entities, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
to: Message, to: Message,
photoSize: PhotoSize, photoSize: PhotoSize,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, photoSize, entities, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(to.chat, photoSize, entities, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
// Sticker // Sticker
@@ -697,6 +709,7 @@ suspend inline fun TelegramBot.replyWithVideo(
thumb: InputFile? = null, thumb: InputFile? = null,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -704,24 +717,26 @@ suspend inline fun TelegramBot.replyWithVideo(
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(to.chat, video, thumb, text, parseMode, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(to.chat, video, thumb, text, parseMode, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
to: Message, to: Message,
video: VideoFile, video: VideoFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(to.chat, video, text, parseMode, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(to.chat, video, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.replyWithVideo( suspend inline fun TelegramBot.replyWithVideo(
to: Message, to: Message,
video: InputFile, video: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -729,17 +744,18 @@ suspend inline fun TelegramBot.replyWithVideo(
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(to.chat, video, thumb, entities, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(to.chat, video, thumb, entities, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
to: Message, to: Message,
video: VideoFile, video: VideoFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(to.chat, video, entities, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(to.chat, video, entities, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
// VideoNotes // VideoNotes

View File

@@ -410,6 +410,7 @@ suspend inline fun TelegramBot.replyWithAnimation(
thumb: InputFile? = null, thumb: InputFile? = null,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -424,6 +425,7 @@ suspend inline fun TelegramBot.replyWithAnimation(
thumb, thumb,
text, text,
parseMode, parseMode,
spoilered,
duration, duration,
width, width,
height, height,
@@ -441,6 +443,7 @@ suspend inline fun TelegramBot.reply(
animation: AnimationFile, animation: AnimationFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -449,13 +452,14 @@ suspend inline fun TelegramBot.reply(
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(toChatId, animation, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(toChatId, animation, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.replyWithAnimation( suspend inline fun TelegramBot.replyWithAnimation(
toChatId: IdChatIdentifier, toChatId: IdChatIdentifier,
toMessageId: MessageId, toMessageId: MessageId,
animation: InputFile, animation: InputFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
thumb: InputFile? = null, thumb: InputFile? = null,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
@@ -470,6 +474,7 @@ suspend inline fun TelegramBot.replyWithAnimation(
animation, animation,
thumb, thumb,
entities, entities,
spoilered,
duration, duration,
width, width,
height, height,
@@ -486,6 +491,7 @@ suspend inline fun TelegramBot.reply(
toMessageId: MessageId, toMessageId: MessageId,
animation: AnimationFile, animation: AnimationFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -494,7 +500,7 @@ suspend inline fun TelegramBot.reply(
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(toChatId, animation, entities, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(toChatId, animation, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
// Audio // Audio
@@ -671,12 +677,13 @@ suspend inline fun TelegramBot.replyWithPhoto(
fileId: InputFile, fileId: InputFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = toChatId.threadId, threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(toChatId, fileId, text, parseMode, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(toChatId, fileId, text, parseMode, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
toChatId: IdChatIdentifier, toChatId: IdChatIdentifier,
@@ -684,12 +691,13 @@ suspend inline fun TelegramBot.reply(
photo: Photo, photo: Photo,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = toChatId.threadId, threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(toChatId, photo, text, parseMode, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(toChatId, photo, text, parseMode, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
toChatId: IdChatIdentifier, toChatId: IdChatIdentifier,
@@ -697,12 +705,13 @@ suspend inline fun TelegramBot.reply(
photoSize: PhotoSize, photoSize: PhotoSize,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = toChatId.threadId, threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(toChatId, photoSize, text, parseMode, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(toChatId, photoSize, text, parseMode, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.replyWithPhoto( suspend inline fun TelegramBot.replyWithPhoto(
@@ -710,36 +719,39 @@ suspend inline fun TelegramBot.replyWithPhoto(
toMessageId: MessageId, toMessageId: MessageId,
fileId: InputFile, fileId: InputFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = toChatId.threadId, threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(toChatId, fileId, entities, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(toChatId, fileId, entities, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
toChatId: IdChatIdentifier, toChatId: IdChatIdentifier,
toMessageId: MessageId, toMessageId: MessageId,
photo: Photo, photo: Photo,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = toChatId.threadId, threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(toChatId, photo, entities, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(toChatId, photo, entities, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
toChatId: IdChatIdentifier, toChatId: IdChatIdentifier,
toMessageId: MessageId, toMessageId: MessageId,
photoSize: PhotoSize, photoSize: PhotoSize,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = toChatId.threadId, threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(toChatId, photoSize, entities, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(toChatId, photoSize, entities, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
// Sticker // Sticker
@@ -776,6 +788,7 @@ suspend inline fun TelegramBot.replyWithVideo(
thumb: InputFile? = null, thumb: InputFile? = null,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -784,7 +797,7 @@ suspend inline fun TelegramBot.replyWithVideo(
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(toChatId, video, thumb, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(toChatId, video, thumb, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
toChatId: IdChatIdentifier, toChatId: IdChatIdentifier,
@@ -792,12 +805,13 @@ suspend inline fun TelegramBot.reply(
video: VideoFile, video: VideoFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = toChatId.threadId, threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(toChatId, video, text, parseMode, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(toChatId, video, text, parseMode, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.replyWithVideo( suspend inline fun TelegramBot.replyWithVideo(
toChatId: IdChatIdentifier, toChatId: IdChatIdentifier,
@@ -805,6 +819,7 @@ suspend inline fun TelegramBot.replyWithVideo(
video: InputFile, video: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -813,19 +828,20 @@ suspend inline fun TelegramBot.replyWithVideo(
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(toChatId, video, thumb, entities, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(toChatId, video, thumb, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
toChatId: IdChatIdentifier, toChatId: IdChatIdentifier,
toMessageId: MessageId, toMessageId: MessageId,
video: VideoFile, video: VideoFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = toChatId.threadId, threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(toChatId, video, entities, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(toChatId, video, entities, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup)
// VideoNotes // VideoNotes

View File

@@ -0,0 +1,108 @@
package dev.inmo.tgbotapi.extensions.api.send
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.MessageContent
import dev.inmo.tgbotapi.types.threadId
/**
* This method will send [content] to the [chatId] as is
*/
suspend inline fun <T : MessageContent> TelegramBot.resend(
chatId: ChatIdentifier,
content: T,
messageThreadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = execute(
content.createResend(
chatId = chatId,
messageThreadId = messageThreadId,
disableNotification = disableNotification,
protectContent = protectContent,
replyToMessageId = replyToMessageId,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
) as ContentMessage<T>
/**
* This method will send [content] to the [chatId] as is
*/
suspend inline fun <T : MessageContent> TelegramBot.resend(
chat: Chat,
content: T,
messageThreadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = resend(
chatId = chat.id,
content = content,
messageThreadId = messageThreadId,
disableNotification = disableNotification,
protectContent = protectContent,
replyToMessageId = replyToMessageId,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
/**
* This method will send [message] content to the [chatId]. In difference with [copyMessage], this method will use
* native methods for data sending (like [dev.inmo.tgbotapi.extensions.api.send.media.sendPhoto] if inoming content is
* [dev.inmo.tgbotapi.types.message.content.PhotoContent])
*/
suspend inline fun <T : MessageContent> TelegramBot.resend(
chatId: ChatIdentifier,
message: ContentMessage<T>,
messageThreadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = resend(
chatId = chatId,
content = message.content,
messageThreadId = messageThreadId,
disableNotification = disableNotification,
protectContent = protectContent,
replyToMessageId = replyToMessageId,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
/**
* This method will send [message] content to the [chat]. In difference with [copyMessage], this method will use
* native methods for data sending (like [dev.inmo.tgbotapi.extensions.api.send.media.sendPhoto] if inoming content is
* [dev.inmo.tgbotapi.types.message.content.PhotoContent])
*/
suspend inline fun <T : MessageContent> TelegramBot.resend(
chat: Chat,
message: ContentMessage<T>,
messageThreadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = resend(
chatId = chat.id,
message = message,
messageThreadId = messageThreadId,
disableNotification = disableNotification,
protectContent = protectContent,
replyToMessageId = replyToMessageId,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)

View File

@@ -3,104 +3,129 @@ package dev.inmo.tgbotapi.extensions.api.send
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.send.SendAction import dev.inmo.tgbotapi.requests.send.SendAction
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.actions.* import dev.inmo.tgbotapi.types.actions.*
import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.threadId
suspend fun TelegramBot.sendBotAction( suspend fun TelegramBot.sendBotAction(
chatId: ChatIdentifier, chatId: ChatIdentifier,
action: BotAction action: BotAction,
threadId: MessageThreadId? = chatId.threadId
) = execute( ) = execute(
SendAction(chatId, action) SendAction(chatId, action, threadId)
) )
suspend fun TelegramBot.sendBotAction( suspend fun TelegramBot.sendBotAction(
chat: Chat, chat: Chat,
action: BotAction action: BotAction,
) = sendBotAction(chat.id, action) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat.id, action, threadId)
suspend fun TelegramBot.sendActionTyping( suspend fun TelegramBot.sendActionTyping(
chatId: ChatIdentifier chatId: ChatIdentifier,
) = sendBotAction(chatId, TypingAction) threadId: MessageThreadId? = chatId.threadId
) = sendBotAction(chatId, TypingAction, threadId)
suspend fun TelegramBot.sendActionUploadPhoto( suspend fun TelegramBot.sendActionUploadPhoto(
chatId: ChatIdentifier chatId: ChatIdentifier,
) = sendBotAction(chatId, UploadPhotoAction) threadId: MessageThreadId? = chatId.threadId
) = sendBotAction(chatId, UploadPhotoAction, threadId)
suspend fun TelegramBot.sendActionRecordVideo( suspend fun TelegramBot.sendActionRecordVideo(
chatId: ChatIdentifier chatId: ChatIdentifier,
) = sendBotAction(chatId, RecordVideoAction) threadId: MessageThreadId? = chatId.threadId
) = sendBotAction(chatId, RecordVideoAction, threadId)
suspend fun TelegramBot.sendActionUploadVideo( suspend fun TelegramBot.sendActionUploadVideo(
chatId: ChatIdentifier chatId: ChatIdentifier,
) = sendBotAction(chatId, UploadVideoAction) threadId: MessageThreadId? = chatId.threadId
) = sendBotAction(chatId, UploadVideoAction, threadId)
suspend fun TelegramBot.sendActionRecordVoice( suspend fun TelegramBot.sendActionRecordVoice(
chatId: ChatIdentifier chatId: ChatIdentifier,
) = sendBotAction(chatId, RecordVoiceAction) threadId: MessageThreadId? = chatId.threadId
) = sendBotAction(chatId, RecordVoiceAction, threadId)
suspend fun TelegramBot.sendActionUploadVoice( suspend fun TelegramBot.sendActionUploadVoice(
chatId: ChatIdentifier chatId: ChatIdentifier,
) = sendBotAction(chatId, UploadVoiceAction) threadId: MessageThreadId? = chatId.threadId
) = sendBotAction(chatId, UploadVoiceAction, threadId)
suspend fun TelegramBot.sendActionUploadDocument( suspend fun TelegramBot.sendActionUploadDocument(
chatId: ChatIdentifier chatId: ChatIdentifier,
) = sendBotAction(chatId, UploadDocumentAction) threadId: MessageThreadId? = chatId.threadId
) = sendBotAction(chatId, UploadDocumentAction, threadId)
suspend fun TelegramBot.sendActionFindLocation( suspend fun TelegramBot.sendActionFindLocation(
chatId: ChatIdentifier chatId: ChatIdentifier,
) = sendBotAction(chatId, FindLocationAction) threadId: MessageThreadId? = chatId.threadId
) = sendBotAction(chatId, FindLocationAction, threadId)
suspend fun TelegramBot.sendActionRecordVideoNote( suspend fun TelegramBot.sendActionRecordVideoNote(
chatId: ChatIdentifier chatId: ChatIdentifier,
) = sendBotAction(chatId, RecordVideoNoteAction) threadId: MessageThreadId? = chatId.threadId
) = sendBotAction(chatId, RecordVideoNoteAction, threadId)
suspend fun TelegramBot.sendActionUploadVideoNote( suspend fun TelegramBot.sendActionUploadVideoNote(
chatId: ChatIdentifier chatId: ChatIdentifier,
) = sendBotAction(chatId, UploadVideoNoteAction) threadId: MessageThreadId? = chatId.threadId
) = sendBotAction(chatId, UploadVideoNoteAction, threadId)
suspend fun TelegramBot.sendActionTyping( suspend fun TelegramBot.sendActionTyping(
chat: Chat chat: Chat,
) = sendBotAction(chat, TypingAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, TypingAction, threadId)
suspend fun TelegramBot.sendActionUploadPhoto( suspend fun TelegramBot.sendActionUploadPhoto(
chat: Chat chat: Chat,
) = sendBotAction(chat, UploadPhotoAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, UploadPhotoAction, threadId)
suspend fun TelegramBot.sendActionRecordVideo( suspend fun TelegramBot.sendActionRecordVideo(
chat: Chat chat: Chat,
) = sendBotAction(chat, RecordVideoAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, RecordVideoAction, threadId)
suspend fun TelegramBot.sendActionUploadVideo( suspend fun TelegramBot.sendActionUploadVideo(
chat: Chat chat: Chat,
) = sendBotAction(chat, UploadVideoAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, UploadVideoAction, threadId)
suspend fun TelegramBot.sendActionRecordVoice( suspend fun TelegramBot.sendActionRecordVoice(
chat: Chat chat: Chat,
) = sendBotAction(chat, RecordVoiceAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, RecordVoiceAction, threadId)
suspend fun TelegramBot.sendActionUploadVoice( suspend fun TelegramBot.sendActionUploadVoice(
chat: Chat chat: Chat,
) = sendBotAction(chat, UploadVoiceAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, UploadVoiceAction, threadId)
suspend fun TelegramBot.sendActionUploadDocument( suspend fun TelegramBot.sendActionUploadDocument(
chat: Chat chat: Chat,
) = sendBotAction(chat, UploadDocumentAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, UploadDocumentAction, threadId)
suspend fun TelegramBot.sendActionFindLocation( suspend fun TelegramBot.sendActionFindLocation(
chat: Chat chat: Chat,
) = sendBotAction(chat, FindLocationAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, FindLocationAction, threadId)
suspend fun TelegramBot.sendActionRecordVideoNote( suspend fun TelegramBot.sendActionRecordVideoNote(
chat: Chat chat: Chat,
) = sendBotAction(chat, RecordVideoNoteAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, RecordVideoNoteAction, threadId)
suspend fun TelegramBot.sendActionUploadVideoNote( suspend fun TelegramBot.sendActionUploadVideoNote(
chat: Chat chat: Chat,
) = sendBotAction(chat, UploadVideoNoteAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, UploadVideoNoteAction, threadId)
suspend fun TelegramBot.sendActionChooseStickerAction( suspend fun TelegramBot.sendActionChooseStickerAction(
chat: Chat chat: Chat,
) = sendBotAction(chat, ChooseStickerAction) threadId: MessageThreadId? = chat.id.threadId
) = sendBotAction(chat, ChooseStickerAction, threadId)

View File

@@ -38,13 +38,14 @@ suspend fun <T> TelegramBot.withAction(
suspend fun <T> TelegramBot.withAction( suspend fun <T> TelegramBot.withAction(
chatId: IdChatIdentifier, chatId: IdChatIdentifier,
action: BotAction, action: BotAction,
threadId: MessageThreadId? = chatId.threadId,
block: TelegramBotActionCallback<T> block: TelegramBotActionCallback<T>
): T { ): T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction( return withAction(
SendAction(chatId, action), SendAction(chatId, action, threadId),
block block
) )
} }
@@ -53,6 +54,7 @@ suspend fun <T> TelegramBot.withAction(
suspend fun <T> TelegramBot.withAction( suspend fun <T> TelegramBot.withAction(
chat: Chat, chat: Chat,
action: BotAction, action: BotAction,
threadId: MessageThreadId? = chat.id.threadId,
block: TelegramBotActionCallback<T> block: TelegramBotActionCallback<T>
): T { ): T {
contract { contract {
@@ -61,163 +63,164 @@ suspend fun <T> TelegramBot.withAction(
return withAction( return withAction(
chat.id, chat.id,
action, action,
threadId,
block block
) )
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withTypingAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withTypingAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, TypingAction, block) return withAction(chatId, TypingAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadPhotoAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withUploadPhotoAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, UploadPhotoAction, block) return withAction(chatId, UploadPhotoAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVideoAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withRecordVideoAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, RecordVideoAction, block) return withAction(chatId, RecordVideoAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVideoAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withUploadVideoAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, UploadVideoAction, block) return withAction(chatId, UploadVideoAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVoiceAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withRecordVoiceAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, RecordVoiceAction, block) return withAction(chatId, RecordVoiceAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVoiceAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withUploadVoiceAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, UploadVoiceAction, block) return withAction(chatId, UploadVoiceAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadDocumentAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withUploadDocumentAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, UploadDocumentAction, block) return withAction(chatId, UploadDocumentAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withFindLocationAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withFindLocationAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, FindLocationAction, block) return withAction(chatId, FindLocationAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withRecordVideoNoteAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, RecordVideoNoteAction, block) return withAction(chatId, RecordVideoNoteAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withUploadVideoNoteAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, UploadVideoNoteAction, block) return withAction(chatId, UploadVideoNoteAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withChooseStickerAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withChooseStickerAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chatId, ChooseStickerAction, block) return withAction(chatId, ChooseStickerAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withTypingAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, TypingAction, block) return withAction(chat, TypingAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadPhotoAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withUploadPhotoAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, UploadPhotoAction, block) return withAction(chat, UploadPhotoAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withRecordVideoAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, RecordVideoAction, block) return withAction(chat, RecordVideoAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withUploadVideoAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, UploadVideoAction, block) return withAction(chat, UploadVideoAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVoiceAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withRecordVoiceAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, RecordVoiceAction, block) return withAction(chat, RecordVoiceAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVoiceAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withUploadVoiceAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, UploadVoiceAction, block) return withAction(chat, UploadVoiceAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadDocumentAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withUploadDocumentAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, UploadDocumentAction, block) return withAction(chat, UploadDocumentAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withFindLocationAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, FindLocationAction, block) return withAction(chat, FindLocationAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withRecordVideoNoteAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, RecordVideoNoteAction, block) return withAction(chat, RecordVideoNoteAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withUploadVideoNoteAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, UploadVideoNoteAction, block) return withAction(chat, UploadVideoNoteAction, threadId, block)
} }
@OptIn(ExperimentalContracts::class) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withChooseStickerAction(chat: Chat, block: TelegramBotActionCallback<T>) : T { suspend fun <T> TelegramBot.withChooseStickerAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback<T>) : T {
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
return withAction(chat, ChooseStickerAction, block) return withAction(chat, ChooseStickerAction, threadId, block)
} }

View File

@@ -56,6 +56,7 @@ suspend fun TelegramBot.send(
animation: AnimationFile, animation: AnimationFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -65,7 +66,7 @@ suspend fun TelegramBot.send(
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(chatId, animation, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(chatId, animation, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendAnimation] request * Will execute [sendAnimation] request
@@ -77,6 +78,7 @@ suspend fun TelegramBot.send(
animation: AnimationFile, animation: AnimationFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -86,7 +88,7 @@ suspend fun TelegramBot.send(
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(chat, animation, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(chat, animation, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendAnimation] request * Will execute [sendAnimation] request
@@ -97,6 +99,7 @@ suspend fun TelegramBot.send(
chatId: ChatIdentifier, chatId: ChatIdentifier,
animation: AnimationFile, animation: AnimationFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -106,7 +109,7 @@ suspend fun TelegramBot.send(
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(chatId, animation, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(chatId, animation, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendAnimation] request * Will execute [sendAnimation] request
@@ -117,6 +120,7 @@ suspend fun TelegramBot.send(
chat: Chat, chat: Chat,
animation: AnimationFile, animation: AnimationFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -126,7 +130,7 @@ suspend fun TelegramBot.send(
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(chat, animation, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(chat, animation, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendAudio] request * Will execute [sendAudio] request
@@ -688,13 +692,14 @@ suspend fun TelegramBot.send(
photo: Photo, photo: Photo,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photo, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chatId, photo, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendPhoto] request * Will execute [sendPhoto] request
@@ -706,13 +711,14 @@ suspend fun TelegramBot.send(
photo: Photo, photo: Photo,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat, photo, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat, photo, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendPhoto] request * Will execute [sendPhoto] request
@@ -724,13 +730,14 @@ suspend fun TelegramBot.send(
photoSize: PhotoSize, photoSize: PhotoSize,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photoSize, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chatId, photoSize, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendPhoto] request * Will execute [sendPhoto] request
@@ -742,13 +749,14 @@ suspend fun TelegramBot.send(
photoSize: PhotoSize, photoSize: PhotoSize,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat, photoSize, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat, photoSize, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendPhoto] request * Will execute [sendPhoto] request
@@ -759,13 +767,14 @@ suspend inline fun TelegramBot.send(
chatId: ChatIdentifier, chatId: ChatIdentifier,
photo: Photo, photo: Photo,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photo, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chatId, photo, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendPhoto] request * Will execute [sendPhoto] request
@@ -776,13 +785,14 @@ suspend inline fun TelegramBot.send(
chat: Chat, chat: Chat,
photo: Photo, photo: Photo,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat, photo, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat, photo, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendPhoto] request * Will execute [sendPhoto] request
@@ -793,13 +803,14 @@ suspend inline fun TelegramBot.send(
chatId: ChatIdentifier, chatId: ChatIdentifier,
photoSize: PhotoSize, photoSize: PhotoSize,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photoSize, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chatId, photoSize, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendPhoto] request * Will execute [sendPhoto] request
@@ -810,13 +821,14 @@ suspend inline fun TelegramBot.send(
chat: Chat, chat: Chat,
photoSize: PhotoSize, photoSize: PhotoSize,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat, photoSize, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat, photoSize, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendRegularPoll] request * Will execute [sendRegularPoll] request
@@ -1357,13 +1369,14 @@ suspend fun TelegramBot.send(
video: VideoFile, video: VideoFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(chatId, video, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(chatId, video, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendVideo] request * Will execute [sendVideo] request
@@ -1375,13 +1388,14 @@ suspend fun TelegramBot.send(
video: VideoFile, video: VideoFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(chat, video, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(chat, video, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendVideo] request * Will execute [sendVideo] request
@@ -1392,13 +1406,14 @@ suspend inline fun TelegramBot.send(
chatId: ChatIdentifier, chatId: ChatIdentifier,
video: VideoFile, video: VideoFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(chatId, video, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(chatId, video, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendVideo] request * Will execute [sendVideo] request
@@ -1409,13 +1424,14 @@ suspend inline fun TelegramBot.send(
chat: Chat, chat: Chat,
video: VideoFile, video: VideoFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(chat, video, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(chat, video, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* Will execute [sendVideoNote] request * Will execute [sendVideoNote] request

View File

@@ -23,6 +23,7 @@ suspend fun TelegramBot.sendAnimation(
thumb: InputFile? = null, thumb: InputFile? = null,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -39,6 +40,7 @@ suspend fun TelegramBot.sendAnimation(
thumb, thumb,
text, text,
parseMode, parseMode,
spoilered,
duration, duration,
width, width,
height, height,
@@ -60,6 +62,7 @@ suspend fun TelegramBot.sendAnimation(
animation: AnimationFile, animation: AnimationFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -70,7 +73,7 @@ suspend fun TelegramBot.sendAnimation(
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation( ) = sendAnimation(
chatId, animation.fileId, animation.thumb ?.fileId, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup chatId, animation.fileId, animation.thumb ?.fileId, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup
) )
/** /**
@@ -83,6 +86,7 @@ suspend fun TelegramBot.sendAnimation(
thumb: InputFile? = null, thumb: InputFile? = null,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -92,7 +96,7 @@ suspend fun TelegramBot.sendAnimation(
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(chat.id, animation, thumb, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(chat.id, animation, thumb, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -103,6 +107,7 @@ suspend fun TelegramBot.sendAnimation(
animation: AnimationFile, animation: AnimationFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -112,7 +117,7 @@ suspend fun TelegramBot.sendAnimation(
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(chat.id, animation, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(chat.id, animation, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
@@ -124,6 +129,7 @@ suspend fun TelegramBot.sendAnimation(
animation: InputFile, animation: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -139,6 +145,7 @@ suspend fun TelegramBot.sendAnimation(
animation, animation,
thumb, thumb,
entities, entities,
spoilered,
duration, duration,
width, width,
height, height,
@@ -159,6 +166,7 @@ suspend fun TelegramBot.sendAnimation(
chatId: ChatIdentifier, chatId: ChatIdentifier,
animation: AnimationFile, animation: AnimationFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -169,7 +177,7 @@ suspend fun TelegramBot.sendAnimation(
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation( ) = sendAnimation(
chatId, animation.fileId, animation.thumb ?.fileId, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup chatId, animation.fileId, animation.thumb ?.fileId, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup
) )
/** /**
@@ -181,6 +189,7 @@ suspend fun TelegramBot.sendAnimation(
animation: InputFile, animation: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -190,7 +199,7 @@ suspend fun TelegramBot.sendAnimation(
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(chat.id, animation, thumb, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(chat.id, animation, thumb, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -200,6 +209,7 @@ suspend fun TelegramBot.sendAnimation(
chat: Chat, chat: Chat,
animation: AnimationFile, animation: AnimationFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -209,4 +219,4 @@ suspend fun TelegramBot.sendAnimation(
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendAnimation(chat.id, animation, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendAnimation(chat.id, animation, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)

View File

@@ -22,6 +22,7 @@ suspend fun TelegramBot.sendPhoto(
fileId: InputFile, fileId: InputFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
@@ -34,6 +35,7 @@ suspend fun TelegramBot.sendPhoto(
fileId, fileId,
text, text,
parseMode, parseMode,
spoilered,
threadId, threadId,
disableNotification, disableNotification,
protectContent, protectContent,
@@ -52,13 +54,14 @@ suspend fun TelegramBot.sendPhoto(
fileId: InputFile, fileId: InputFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, fileId, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat.id, fileId, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -69,13 +72,14 @@ suspend fun TelegramBot.sendPhoto(
photo: Photo, photo: Photo,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -86,13 +90,14 @@ suspend fun TelegramBot.sendPhoto(
photo: Photo, photo: Photo,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, photo, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat.id, photo, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -103,13 +108,14 @@ suspend fun TelegramBot.sendPhoto(
photoSize: PhotoSize, photoSize: PhotoSize,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photoSize.fileId, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chatId, photoSize.fileId, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -120,13 +126,14 @@ suspend fun TelegramBot.sendPhoto(
photoSize: PhotoSize, photoSize: PhotoSize,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, photoSize, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat.id, photoSize, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
@@ -137,6 +144,7 @@ suspend inline fun TelegramBot.sendPhoto(
chatId: ChatIdentifier, chatId: ChatIdentifier,
fileId: InputFile, fileId: InputFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
@@ -148,6 +156,7 @@ suspend inline fun TelegramBot.sendPhoto(
chatId, chatId,
fileId, fileId,
entities, entities,
spoilered,
threadId, threadId,
disableNotification, disableNotification,
protectContent, protectContent,
@@ -165,13 +174,14 @@ suspend inline fun TelegramBot.sendPhoto(
chat: Chat, chat: Chat,
fileId: InputFile, fileId: InputFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, fileId, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat.id, fileId, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -181,13 +191,14 @@ suspend inline fun TelegramBot.sendPhoto(
chatId: ChatIdentifier, chatId: ChatIdentifier,
photo: Photo, photo: Photo,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -197,13 +208,14 @@ suspend inline fun TelegramBot.sendPhoto(
chat: Chat, chat: Chat,
photo: Photo, photo: Photo,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, photo, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat.id, photo, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -213,13 +225,14 @@ suspend inline fun TelegramBot.sendPhoto(
chatId: ChatIdentifier, chatId: ChatIdentifier,
photoSize: PhotoSize, photoSize: PhotoSize,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photoSize.fileId, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chatId, photoSize.fileId, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -229,10 +242,11 @@ suspend inline fun TelegramBot.sendPhoto(
chat: Chat, chat: Chat,
photoSize: PhotoSize, photoSize: PhotoSize,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, photoSize, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat.id, photoSize, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)

View File

@@ -23,6 +23,7 @@ suspend fun TelegramBot.sendVideo(
thumb: InputFile? = null, thumb: InputFile? = null,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -39,6 +40,7 @@ suspend fun TelegramBot.sendVideo(
thumb, thumb,
text, text,
parseMode, parseMode,
spoilered,
duration, duration,
width, width,
height, height,
@@ -61,13 +63,14 @@ suspend fun TelegramBot.sendVideo(
video: VideoFile, video: VideoFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, text, parseMode, video.duration, video.width, video.height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, text, parseMode, spoilered, video.duration, video.width, video.height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -79,6 +82,7 @@ suspend fun TelegramBot.sendVideo(
thumb: InputFile? = null, thumb: InputFile? = null,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -88,7 +92,7 @@ suspend fun TelegramBot.sendVideo(
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(chat.id, video, thumb, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(chat.id, video, thumb, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
@@ -100,13 +104,14 @@ suspend fun TelegramBot.sendVideo(
video: VideoFile, video: VideoFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(chat.id, video, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(chat.id, video, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -117,6 +122,7 @@ suspend inline fun TelegramBot.sendVideo(
video: InputFile, video: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -132,6 +138,7 @@ suspend inline fun TelegramBot.sendVideo(
video, video,
thumb, thumb,
entities, entities,
spoilered,
duration, duration,
width, width,
height, height,
@@ -153,13 +160,14 @@ suspend inline fun TelegramBot.sendVideo(
chatId: ChatIdentifier, chatId: ChatIdentifier,
video: VideoFile, video: VideoFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, entities, video.duration, video.width, video.height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, entities, spoilered, video.duration, video.width, video.height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -170,6 +178,7 @@ suspend inline fun TelegramBot.sendVideo(
video: InputFile, video: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -179,7 +188,7 @@ suspend inline fun TelegramBot.sendVideo(
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(chat.id, video, thumb, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(chat.id, video, thumb, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
@@ -190,10 +199,11 @@ suspend inline fun TelegramBot.sendVideo(
chat: Chat, chat: Chat,
video: VideoFile, video: VideoFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chat.id.threadId, threadId: MessageThreadId? = chat.id.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVideo(chat.id, video, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendVideo(chat.id, video, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)

View File

@@ -1,7 +1,8 @@
package dev.inmo.tgbotapi.extensions.api.utils package dev.inmo.tgbotapi.extensions.api.utils
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
import dev.inmo.tgbotapi.extensions.api.InternalUtils.convertWithMediaGroupUpdates import dev.inmo.tgbotapi.extensions.api.InternalUtils.convertWithMediaGroupUpdates
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver
@@ -28,26 +29,18 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation(
) )
launch { launch {
launch { launchSafelyWithoutExceptions {
for (update in updatesChannel) { for (update in updatesChannel) {
val dataAsPossiblySentViaBotCommonMessage = update.data as? PossiblySentViaBotCommonMessage<*> val data = update.data
when {
if (dataAsPossiblySentViaBotCommonMessage == null) { data is PossiblyMediaGroupMessage<*> && data.mediaGroupId != null -> {
output(update) mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
continue }
else -> output(update)
} }
val mediaGroupId = dataAsPossiblySentViaBotCommonMessage.mediaGroupId
if (mediaGroupId == null) {
output(update)
continue
}
mediaGroupChannel.send("${mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
} }
} }
launch { launchSafelyWithoutExceptions {
for ((_, mediaGroup) in mediaGroupAccumulatedChannel) { for ((_, mediaGroup) in mediaGroupAccumulatedChannel) {
mediaGroup.convertWithMediaGroupUpdates().forEach { mediaGroup.convertWithMediaGroupUpdates().forEach {
output(it) output(it)

View File

@@ -1,6 +1,7 @@
plugins { plugins {
id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization" id "org.jetbrains.kotlin.plugin.serialization"
id "org.jetbrains.dokka"
} }
project.description = "Behaviour Builder DSL" project.description = "Behaviour Builder DSL"

View File

@@ -10,6 +10,8 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.handlers_registrar.T
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlin.reflect.KClass import kotlin.reflect.KClass
/** /**
@@ -133,6 +135,9 @@ class DefaultBehaviourContextWithFSM<T : State>(
private val additionalHandlers = mutableListOf<BehaviourWithFSMStateHandlerHolder<*, T>>() private val additionalHandlers = mutableListOf<BehaviourWithFSMStateHandlerHolder<*, T>>()
private var actualHandlersList = additionalHandlers + handlers private var actualHandlersList = additionalHandlers + handlers
protected val statesJobs = mutableMapOf<T, Job>()
protected val statesJobsMutex = Mutex()
override suspend fun launchStateHandling(state: T, handlers: List<CheckableHandlerHolder<in T, T>>): T? { override suspend fun launchStateHandling(state: T, handlers: List<CheckableHandlerHolder<in T, T>>): T? {
return launchStateHandling(state, handlers, onStateHandlingErrorHandler) return launchStateHandling(state, handlers, onStateHandlingErrorHandler)
} }
@@ -164,21 +169,49 @@ class DefaultBehaviourContextWithFSM<T : State>(
statesManager.endChain(state) statesManager.endChain(state)
} }
} }
fun Job.enableRemoveOnCompletion(state: T) {
invokeOnCompletion {
launchSafelyWithoutExceptions {
statesJobsMutex.withLock {
if (this@enableRemoveOnCompletion === statesJobs[state]) {
statesJobs.remove(state)
}
}
}
}
}
statesManager.onStartChain.subscribeSafelyWithoutExceptions(this) { statesManager.onStartChain.subscribeSafelyWithoutExceptions(this) {
launch { statePerformer(it) } statesJobsMutex.withLock {
runCatchingSafely { statesJobs.remove(it) ?.cancel() }
statesJobs[it] = launch { statePerformer(it) }.apply { enableRemoveOnCompletion(it) }
}
}
statesManager.onEndChain.subscribeSafelyWithoutExceptions(this) {
statesJobsMutex.withLock {
runCatchingSafely { statesJobs.remove(it) ?.cancel() }
}
updatesFlows.remove(it.context)
} }
statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) { (old, new) -> statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) { (old, new) ->
statesJobsMutex.withLock {
runCatchingSafely { statesJobs.remove(old) ?.cancel() }
runCatchingSafely { statesJobs.remove(new) ?.cancel() }
statesJobs[new] = launch { statePerformer(new) }.apply { enableRemoveOnCompletion(new) }
}
if (old.context != new.context) { if (old.context != new.context) {
updatesFlows.remove(old.context) updatesFlows.remove(old.context)
} }
launch { statePerformer(new) }
}
statesManager.onEndChain.subscribeSafelyWithoutExceptions(this) {
updatesFlows.remove(it.context)
} }
statesManager.getActiveStates().forEach { statesManager.getActiveStates().forEach {
launch { statePerformer(it) } statesJobsMutex.withLock {
runCatchingSafely { statesJobs.remove(it) ?.cancel() }
statesJobs[it] = launch { statePerformer(it) }.apply { enableRemoveOnCompletion(it) }
}
} }
} }
/** /**

View File

@@ -8,6 +8,8 @@ import dev.inmo.micro_utils.fsm.common.utils.StateHandlingErrorHandler
import dev.inmo.micro_utils.fsm.common.utils.defaultStateHandlingErrorHandler import dev.inmo.micro_utils.fsm.common.utils.defaultStateHandlingErrorHandler
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.updateHandlerWithMediaGroupsAdaptation
import dev.inmo.tgbotapi.types.Seconds
import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import kotlinx.coroutines.* import kotlinx.coroutines.*
@@ -46,6 +48,10 @@ suspend fun <T : State> TelegramBot.buildBehaviourWithFSM(
* Use [buildBehaviourWithFSM] to create [BehaviourContextWithFSM] and launch getting of updates * Use [buildBehaviourWithFSM] to create [BehaviourContextWithFSM] and launch getting of updates
* using [longPolling]. For [longPolling] will be used result [BehaviourContextWithFSM] for both parameters * using [longPolling]. For [longPolling] will be used result [BehaviourContextWithFSM] for both parameters
* flowsUpdatesFilter and scope * flowsUpdatesFilter and scope
*
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
* retrieved in different updates
*/ */
suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling( suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
upstreamUpdatesFlow: Flow<Update>? = null, upstreamUpdatesFlow: Flow<Update>? = null,
@@ -54,6 +60,10 @@ suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(), presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(),
onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(), onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(),
timeoutSeconds: Seconds = 30,
autoDisableWebhooks: Boolean = true,
autoSkipTimeoutExceptions: Boolean = true,
mediaGroupsDebounceTimeMillis: Long? = 1000L,
block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit> block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>
): Pair<DefaultBehaviourContextWithFSM<T>, Job> = buildBehaviourWithFSM( ): Pair<DefaultBehaviourContextWithFSM<T>, Job> = buildBehaviourWithFSM(
upstreamUpdatesFlow, upstreamUpdatesFlow,
@@ -66,7 +76,7 @@ suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
).run { ).run {
this to scope.launch { this to scope.launch {
start() start()
longPolling(flowsUpdatesFilter, scope = scope) longPolling(flowsUpdatesFilter, timeoutSeconds, scope, autoDisableWebhooks, autoSkipTimeoutExceptions, mediaGroupsDebounceTimeMillis, defaultExceptionsHandler)
} }
} }
@@ -112,6 +122,10 @@ suspend fun <T : State> TelegramBot.buildBehaviourWithFSM(
* using [longPolling]. For [longPolling] will be used result [BehaviourContextWithFSM] for both parameters * using [longPolling]. For [longPolling] will be used result [BehaviourContextWithFSM] for both parameters
* flowsUpdatesFilter and scope * flowsUpdatesFilter and scope
* *
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
* retrieved in different updates
*
* @see buildBehaviourWithFSMAndStartLongPolling * @see buildBehaviourWithFSMAndStartLongPolling
* @see BehaviourContext * @see BehaviourContext
* @see longPolling * @see longPolling
@@ -124,6 +138,10 @@ suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(), presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(),
onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(), onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(),
timeoutSeconds: Seconds = 30,
autoDisableWebhooks: Boolean = true,
autoSkipTimeoutExceptions: Boolean = true,
mediaGroupsDebounceTimeMillis: Long? = 1000L,
block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit> block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>
) = FlowsUpdatesFilter().let { ) = FlowsUpdatesFilter().let {
buildBehaviourWithFSM( buildBehaviourWithFSM(
@@ -138,7 +156,12 @@ suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
start() start()
longPolling( longPolling(
flowsUpdatesFilter, flowsUpdatesFilter,
scope = scope timeoutSeconds,
scope,
autoDisableWebhooks,
autoSkipTimeoutExceptions,
mediaGroupsDebounceTimeMillis,
defaultExceptionsHandler
) )
} }
} }

View File

@@ -11,6 +11,8 @@ import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder
import dev.inmo.tgbotapi.bot.ktor.telegramBot import dev.inmo.tgbotapi.bot.ktor.telegramBot
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.updateHandlerWithMediaGroupsAdaptation
import dev.inmo.tgbotapi.types.Seconds
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@@ -25,6 +27,10 @@ import kotlin.coroutines.coroutineContext
* **WARNING** This method WILL NOT launch any listening of updates. Use something like * **WARNING** This method WILL NOT launch any listening of updates. Use something like
* [startGettingOfUpdatesByLongPolling] or tools for work with webhooks * [startGettingOfUpdatesByLongPolling] or tools for work with webhooks
* *
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
* retrieved in different updates
*
* @return Created bot which has been used to create [BehaviourContext] via [buildBehaviourWithFSM] * @return Created bot which has been used to create [BehaviourContext] via [buildBehaviourWithFSM]
* *
* @see [BehaviourContext] * @see [BehaviourContext]
@@ -42,6 +48,10 @@ suspend fun <T : State> telegramBotWithBehaviourAndFSM(
presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(), presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(),
testServer: Boolean = false, testServer: Boolean = false,
onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(), onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(),
timeoutSeconds: Seconds = 30,
autoDisableWebhooks: Boolean = true,
autoSkipTimeoutExceptions: Boolean = true,
mediaGroupsDebounceTimeMillis: Long? = 1000L,
block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit> block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>
): TelegramBot = telegramBot( ): TelegramBot = telegramBot(
token, token,
@@ -56,6 +66,10 @@ suspend fun <T : State> telegramBotWithBehaviourAndFSM(
statesManager, statesManager,
presetHandlers, presetHandlers,
onStateHandlingErrorHandler, onStateHandlingErrorHandler,
timeoutSeconds,
autoDisableWebhooks,
autoSkipTimeoutExceptions,
mediaGroupsDebounceTimeMillis,
block block
) )
} }
@@ -64,6 +78,10 @@ suspend fun <T : State> telegramBotWithBehaviourAndFSM(
* Create bot using [telegramBot] and start listening for updates using [buildBehaviourWithFSMAndStartLongPolling]. This * Create bot using [telegramBot] and start listening for updates using [buildBehaviourWithFSMAndStartLongPolling]. This
* method will launch updates retrieving via long polling inside of [buildBehaviourWithFSMAndStartLongPolling] * method will launch updates retrieving via long polling inside of [buildBehaviourWithFSMAndStartLongPolling]
* *
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
* retrieved in different updates
*
* @return Pair of [TelegramBot] and [Job]. This [Job] can be used to stop listening updates in your [block] you passed * @return Pair of [TelegramBot] and [Job]. This [Job] can be used to stop listening updates in your [block] you passed
* here * here
* *
@@ -81,6 +99,10 @@ suspend fun <T : State> telegramBotWithBehaviourAndFSMAndStartLongPolling(
presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(), presetHandlers: List<BehaviourWithFSMStateHandlerHolder<*, T>> = listOf(),
testServer: Boolean = false, testServer: Boolean = false,
onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(), onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler(),
timeoutSeconds: Seconds = 30,
autoDisableWebhooks: Boolean = true,
autoSkipTimeoutExceptions: Boolean = true,
mediaGroupsDebounceTimeMillis: Long? = 1000L,
block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit> block: CustomBehaviourContextReceiver<DefaultBehaviourContextWithFSM<T>, Unit>
): Pair<TelegramBot, Job> { ): Pair<TelegramBot, Job> {
return telegramBot( return telegramBot(
@@ -95,6 +117,10 @@ suspend fun <T : State> telegramBotWithBehaviourAndFSMAndStartLongPolling(
statesManager, statesManager,
presetHandlers, presetHandlers,
onStateHandlingErrorHandler, onStateHandlingErrorHandler,
timeoutSeconds,
autoDisableWebhooks,
autoSkipTimeoutExceptions,
mediaGroupsDebounceTimeMillis,
block block
) )
} }

View File

@@ -1,6 +1,7 @@
plugins { plugins {
id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization" id "org.jetbrains.kotlin.plugin.serialization"
id "org.jetbrains.dokka"
} }
project.description = "Behaviour Builder DSL" project.description = "Behaviour Builder DSL"

View File

@@ -5,6 +5,8 @@ import dev.inmo.micro_utils.coroutines.ExceptionHandler
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.updateHandlerWithMediaGroupsAdaptation
import dev.inmo.tgbotapi.types.Seconds
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import kotlinx.coroutines.* import kotlinx.coroutines.*
@@ -46,6 +48,10 @@ suspend fun TelegramBot.buildBehaviour(
* Use this method to build bot behaviour and run it via long polling. In case you wish to get [FlowsUpdatesFilter] for * Use this method to build bot behaviour and run it via long polling. In case you wish to get [FlowsUpdatesFilter] for
* additional manipulations, you must provide external [FlowsUpdatesFilter] in other [buildBehaviour] function. * additional manipulations, you must provide external [FlowsUpdatesFilter] in other [buildBehaviour] function.
* *
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
* retrieved in different updates
*
* @see buildBehaviour * @see buildBehaviour
* @see BehaviourContext * @see BehaviourContext
* @see startGettingOfUpdatesByLongPolling * @see startGettingOfUpdatesByLongPolling
@@ -53,6 +59,10 @@ suspend fun TelegramBot.buildBehaviour(
suspend fun TelegramBot.buildBehaviourWithLongPolling( suspend fun TelegramBot.buildBehaviourWithLongPolling(
scope: CoroutineScope = defaultCoroutineScopeProvider(), scope: CoroutineScope = defaultCoroutineScopeProvider(),
defaultExceptionsHandler: ExceptionHandler<Unit>? = null, defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
timeoutSeconds: Seconds = 30,
autoDisableWebhooks: Boolean = true,
autoSkipTimeoutExceptions: Boolean = true,
mediaGroupsDebounceTimeMillis: Long? = 1000L,
block: BehaviourContextReceiver<Unit> block: BehaviourContextReceiver<Unit>
): Job { ): Job {
val behaviourContext = buildBehaviour( val behaviourContext = buildBehaviour(
@@ -62,6 +72,10 @@ suspend fun TelegramBot.buildBehaviourWithLongPolling(
) )
return longPolling( return longPolling(
behaviourContext, behaviourContext,
scope = behaviourContext scope = behaviourContext,
timeoutSeconds = timeoutSeconds,
autoDisableWebhooks = autoDisableWebhooks,
autoSkipTimeoutExceptions = autoSkipTimeoutExceptions,
mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis
) )
} }

View File

@@ -5,6 +5,8 @@ import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder
import dev.inmo.tgbotapi.bot.ktor.telegramBot import dev.inmo.tgbotapi.bot.ktor.telegramBot
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.updateHandlerWithMediaGroupsAdaptation
import dev.inmo.tgbotapi.types.Seconds
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
import kotlinx.coroutines.* import kotlinx.coroutines.*
@@ -52,6 +54,10 @@ suspend fun telegramBotWithBehaviour(
* *
* **WARNING** This method WILL launch updates listening inside of calling [buildBehaviourWithLongPolling] * **WARNING** This method WILL launch updates listening inside of calling [buildBehaviourWithLongPolling]
* *
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
* retrieved in different updates
*
* @return Pair of [TelegramBot] and [Job]. This [Job] can be used to stop listening updates in your [block] you passed * @return Pair of [TelegramBot] and [Job]. This [Job] can be used to stop listening updates in your [block] you passed
* here * here
* *
@@ -66,6 +72,10 @@ suspend fun telegramBotWithBehaviourAndLongPolling(
builder: KtorRequestsExecutorBuilder.() -> Unit = {}, builder: KtorRequestsExecutorBuilder.() -> Unit = {},
defaultExceptionsHandler: ExceptionHandler<Unit>? = null, defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
testServer: Boolean = false, testServer: Boolean = false,
timeoutSeconds: Seconds = 30,
autoDisableWebhooks: Boolean = true,
autoSkipTimeoutExceptions: Boolean = true,
mediaGroupsDebounceTimeMillis: Long? = 1000L,
block: BehaviourContextReceiver<Unit> block: BehaviourContextReceiver<Unit>
): Pair<TelegramBot, Job> { ): Pair<TelegramBot, Job> {
return telegramBot( return telegramBot(
@@ -77,6 +87,10 @@ suspend fun telegramBotWithBehaviourAndLongPolling(
it to it.buildBehaviourWithLongPolling( it to it.buildBehaviourWithLongPolling(
scope ?: CoroutineScope(coroutineContext), scope ?: CoroutineScope(coroutineContext),
defaultExceptionsHandler, defaultExceptionsHandler,
timeoutSeconds,
autoDisableWebhooks,
autoSkipTimeoutExceptions,
mediaGroupsDebounceTimeMillis,
block block
) )
} }

View File

@@ -20,7 +20,7 @@ suspend inline fun <reified O> BehaviourContext.waitCallbackQueries(
initRequest, initRequest,
errorFactory errorFactory
) { ) {
(it.callbackQueryUpdateOrNull() ?.data as O).let(::listOfNotNull) (it.callbackQueryUpdateOrNull() ?.data as? O).let(::listOfNotNull)
} }

View File

@@ -16,119 +16,180 @@ typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T?
@RiskFeature(lowLevelRiskFeatureMessage) @RiskFeature(lowLevelRiskFeatureMessage)
suspend inline fun <reified O : MessageContent> BehaviourContext.waitContent( suspend inline fun <reified O : MessageContent> BehaviourContext.waitContent(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
includeMediaGroups: Boolean = true,
noinline errorFactory: NullableRequestBuilder<*> = { null } noinline errorFactory: NullableRequestBuilder<*> = { null }
): Flow<O> = waitContentMessage<O>(initRequest, includeMediaGroups, errorFactory).map { it.content } ): Flow<O> = waitContentMessage<O>(initRequest, errorFactory).map { it.content }
@Deprecated(
includeMediaGroupsDeprecationMessage,
ReplaceWith("waitAnyContent(initRequest, errorFactory)", "dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitAnyContent")
)
suspend fun BehaviourContext.waitContent( suspend fun BehaviourContext.waitContent(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContent<MessageContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<MessageContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitAnyContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<MessageContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitContact( suspend fun BehaviourContext.waitContact(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<ContactContent>(initRequest, false, errorFactory) ) = waitContent<ContactContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitDice( suspend fun BehaviourContext.waitDice(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<DiceContent>(initRequest, false, errorFactory) ) = waitContent<DiceContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitGame( suspend fun BehaviourContext.waitGame(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<GameContent>(initRequest, false, errorFactory) ) = waitContent<GameContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitLocation( suspend fun BehaviourContext.waitLocation(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<LocationContent>(initRequest, false, errorFactory) ) = waitContent<LocationContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitLiveLocation( suspend fun BehaviourContext.waitLiveLocation(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<LiveLocationContent>(initRequest, false, errorFactory) ) = waitContent<LiveLocationContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitStaticLocation( suspend fun BehaviourContext.waitStaticLocation(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<StaticLocationContent>(initRequest, false, errorFactory) ) = waitContent<StaticLocationContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitPoll( suspend fun BehaviourContext.waitPoll(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<PollContent>(initRequest, false, errorFactory) ) = waitContent<PollContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitText( suspend fun BehaviourContext.waitText(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<TextContent>(initRequest, false, errorFactory) ) = waitContent<TextContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVenue( suspend fun BehaviourContext.waitVenue(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<VenueContent>(initRequest, false, errorFactory) ) = waitContent<VenueContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitAudioMediaGroupContent( suspend fun BehaviourContext.waitAudioMediaGroupContent(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContent<AudioMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<AudioMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitAudioMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
) = waitContent<AudioMediaGroupPartContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitDocumentMediaGroupContent( suspend fun BehaviourContext.waitDocumentMediaGroupContent(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContent<DocumentMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<DocumentMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitDocumentMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<DocumentMediaGroupPartContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitMedia( suspend fun BehaviourContext.waitMedia(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false includeMediaGroups: Boolean
) = waitContent<MediaContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<MediaContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitMedia(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<MediaContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitAnyMediaGroupContent( suspend fun BehaviourContext.waitAnyMediaGroupContent(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContent<MediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<MediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitAnyMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
) = waitContent<MediaGroupPartContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitVisualMediaGroupContent( suspend fun BehaviourContext.waitVisualMediaGroupContent(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContent<VisualMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<VisualMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVisualMediaGroupContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
) = waitContent<VisualMediaGroupPartContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitTextedMediaContent( suspend fun BehaviourContext.waitTextedMediaContent(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContent<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<TextedMediaContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitTextedMediaContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
) = waitContent<TextedMediaContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitAnimation( suspend fun BehaviourContext.waitAnimation(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<AnimationContent>(initRequest, false, errorFactory) ) = waitContent<AnimationContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitAudio( suspend fun BehaviourContext.waitAudio(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false includeMediaGroups: Boolean
) = waitContent<AudioContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<AudioContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitAudio(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
) = waitContent<AudioContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitDocument( suspend fun BehaviourContext.waitDocument(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false includeMediaGroups: Boolean
) = waitContent<DocumentContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<DocumentContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitDocument(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
) = waitContent<DocumentContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitPhoto( suspend fun BehaviourContext.waitPhoto(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false includeMediaGroups: Boolean
) = waitContent<PhotoContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<PhotoContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitPhoto(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
) = waitContent<PhotoContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitSticker( suspend fun BehaviourContext.waitSticker(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<StickerContent>(initRequest, false, errorFactory) ) = waitContent<StickerContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitVideo( suspend fun BehaviourContext.waitVideo(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false includeMediaGroups: Boolean
) = waitContent<VideoContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContent<VideoContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVideo(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<VideoContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVideoNote( suspend fun BehaviourContext.waitVideoNote(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<VideoNoteContent>(initRequest, false, errorFactory) ) = waitContent<VideoNoteContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVoice( suspend fun BehaviourContext.waitVoice(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<VoiceContent>(initRequest, false, errorFactory) ) = waitContent<VoiceContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitInvoice( suspend fun BehaviourContext.waitInvoice(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<InvoiceContent>(initRequest, false, errorFactory) ) = waitContent<InvoiceContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVisualContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent<VisualMediaGroupPartContent>(initRequest, errorFactory)

View File

@@ -13,17 +13,20 @@ import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
const val includeMediaGroupsDeprecationMessage = "includeMediaGroups is deprecated and its usage will not lead to any changes"
typealias CommonMessageToCommonMessageMapper<T> = suspend CommonMessage<T>.() -> CommonMessage<T>? typealias CommonMessageToCommonMessageMapper<T> = suspend CommonMessage<T>.() -> CommonMessage<T>?
@RiskFeature(lowLevelRiskFeatureMessage) @RiskFeature(lowLevelRiskFeatureMessage)
suspend inline fun <reified O : MessageContent> BehaviourContext.waitContentMessage( suspend inline fun <reified O : MessageContent> BehaviourContext.waitContentMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
includeMediaGroups: Boolean = true,
noinline errorFactory: NullableRequestBuilder<*> = { null } noinline errorFactory: NullableRequestBuilder<*> = { null }
): Flow<CommonMessage<O>> = expectFlow( ): Flow<CommonMessage<O>> = expectFlow(
initRequest, initRequest,
errorFactory errorFactory
) { ) {
if (it !is BaseSentMessageUpdate) {
return@expectFlow emptyList()
}
listOfNotNull((it.data as? CommonMessage<*>) ?.withContent<O>()) listOfNotNull((it.data as? CommonMessage<*>) ?.withContent<O>())
} }
@@ -44,114 +47,177 @@ internal inline fun <reified T : MessageContent> contentMessageConverter(
if (content is T) this as CommonMessage<T> else null if (content is T) this as CommonMessage<T> else null
} }
@Deprecated(
includeMediaGroupsDeprecationMessage,
ReplaceWith("waitAnyContentMessage(initRequest, errorFactory)", "dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitAnyContentMessage")
)
suspend fun BehaviourContext.waitContentMessage( suspend fun BehaviourContext.waitContentMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContentMessage<MessageContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<MessageContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitAnyContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
) = waitContentMessage<MessageContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitContactMessage( suspend fun BehaviourContext.waitContactMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<ContactContent>(initRequest, false, errorFactory) ) = waitContentMessage<ContactContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitDiceMessage( suspend fun BehaviourContext.waitDiceMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<DiceContent>(initRequest, false, errorFactory) ) = waitContentMessage<DiceContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitGameMessage( suspend fun BehaviourContext.waitGameMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<GameContent>(initRequest, false, errorFactory) ) = waitContentMessage<GameContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitLocationMessage( suspend fun BehaviourContext.waitLocationMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<LocationContent>(initRequest, false, errorFactory) ) = waitContentMessage<LocationContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitLiveLocationMessage( suspend fun BehaviourContext.waitLiveLocationMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<LiveLocationContent>(initRequest, false, errorFactory) ) = waitContentMessage<LiveLocationContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitStaticLocationMessage( suspend fun BehaviourContext.waitStaticLocationMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<StaticLocationContent>(initRequest, false, errorFactory) ) = waitContentMessage<StaticLocationContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitPollMessage( suspend fun BehaviourContext.waitPollMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<PollContent>(initRequest, false, errorFactory) ) = waitContentMessage<PollContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitTextMessage( suspend fun BehaviourContext.waitTextMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<TextContent>(initRequest, false, errorFactory) ) = waitContentMessage<TextContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVenueMessage( suspend fun BehaviourContext.waitVenueMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<VenueContent>(initRequest, false, errorFactory) ) = waitContentMessage<VenueContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitAudioMediaGroupContentMessage( suspend fun BehaviourContext.waitAudioMediaGroupContentMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContentMessage<AudioMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<AudioMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitAudioMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<AudioMediaGroupPartContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage( suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContentMessage<DocumentMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<DocumentMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<DocumentMediaGroupPartContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitMediaMessage( suspend fun BehaviourContext.waitMediaMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false includeMediaGroups: Boolean
) = waitContentMessage<MediaContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<MediaContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitMediaMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<MediaContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitAnyMediaGroupContentMessage( suspend fun BehaviourContext.waitAnyMediaGroupContentMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContentMessage<MediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<MediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitAnyMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<MediaGroupPartContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitVisualMediaGroupContentMessage( suspend fun BehaviourContext.waitVisualMediaGroupContentMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContentMessage<VisualMediaGroupPartContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<VisualMediaGroupPartContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVisualMediaGroupContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<VisualMediaGroupPartContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitTextedMediaContentMessage( suspend fun BehaviourContext.waitTextedMediaContentMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = true includeMediaGroups: Boolean
) = waitContentMessage<TextedMediaContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<TextedMediaContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitTextedMediaContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<TextedMediaContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitAnimationMessage( suspend fun BehaviourContext.waitAnimationMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<AnimationContent>(initRequest, false, errorFactory) ) = waitContentMessage<AnimationContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitAudioMessage( suspend fun BehaviourContext.waitAudioMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false includeMediaGroups: Boolean
) = waitContentMessage<AudioContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<AudioContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitAudioMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<AudioContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitDocumentMessage( suspend fun BehaviourContext.waitDocumentMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false includeMediaGroups: Boolean
) = waitContentMessage<DocumentContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<DocumentContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitDocumentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<DocumentContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitPhotoMessage( suspend fun BehaviourContext.waitPhotoMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false includeMediaGroups: Boolean
) = waitContentMessage<PhotoContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<PhotoContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitPhotoMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<PhotoContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitStickerMessage( suspend fun BehaviourContext.waitStickerMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<StickerContent>(initRequest, false, errorFactory) ) = waitContentMessage<StickerContent>(initRequest, errorFactory)
@Deprecated(includeMediaGroupsDeprecationMessage)
suspend fun BehaviourContext.waitVideoMessage( suspend fun BehaviourContext.waitVideoMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }, errorFactory: NullableRequestBuilder<*> = { null },
includeMediaGroups: Boolean = false includeMediaGroups: Boolean
) = waitContentMessage<VideoContent>(initRequest, includeMediaGroups, errorFactory) ) = waitContentMessage<VideoContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVideoMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<VideoContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVideoNoteMessage( suspend fun BehaviourContext.waitVideoNoteMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<VideoNoteContent>(initRequest, false, errorFactory) ) = waitContentMessage<VideoNoteContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVoiceMessage( suspend fun BehaviourContext.waitVoiceMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<VoiceContent>(initRequest, false, errorFactory) ) = waitContentMessage<VoiceContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitInvoiceMessage( suspend fun BehaviourContext.waitInvoiceMessage(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<InvoiceContent>(initRequest, false, errorFactory) ) = waitContentMessage<InvoiceContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitVisualContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage<VisualMediaGroupPartContent>(initRequest, errorFactory)

View File

@@ -9,10 +9,17 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.*
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicEdited
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicHidden
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidden
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
import dev.inmo.tgbotapi.types.request.ChatShared
import dev.inmo.tgbotapi.types.request.ChatSharedRequest
import dev.inmo.tgbotapi.types.request.UserShared
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@@ -151,3 +158,34 @@ suspend fun BehaviourContext.waitForumTopicReopened(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitEvents<ForumTopicReopened>(initRequest, errorFactory) ) = waitEvents<ForumTopicReopened>(initRequest, errorFactory)
suspend fun BehaviourContext.waitForumTopicEdited(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEvents<ForumTopicEdited>(initRequest, errorFactory)
suspend fun BehaviourContext.waitGeneralForumTopicHidden(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEvents<GeneralForumTopicHidden>(initRequest, errorFactory)
suspend fun BehaviourContext.waitGeneralForumTopicUnhidden(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEvents<GeneralForumTopicUnhidden>(initRequest, errorFactory)
suspend fun BehaviourContext.waitWriteAccessAllowed(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEvents<WriteAccessAllowed>(initRequest, errorFactory)
suspend fun BehaviourContext.waitChatSharedRequest(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEvents<ChatSharedRequest>(initRequest, errorFactory)
suspend fun BehaviourContext.waitUserShared(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEvents<UserShared>(initRequest, errorFactory)
suspend fun BehaviourContext.waitChatShared(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEvents<ChatShared>(initRequest, errorFactory)

View File

@@ -9,10 +9,17 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.*
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicEdited
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicHidden
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidden
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
import dev.inmo.tgbotapi.types.request.ChatShared
import dev.inmo.tgbotapi.types.request.ChatSharedRequest
import dev.inmo.tgbotapi.types.request.UserShared
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@@ -148,3 +155,34 @@ suspend fun BehaviourContext.waitForumTopicReopenedEventsMessages(
initRequest: Request<*>? = null, initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null } errorFactory: NullableRequestBuilder<*> = { null }
) = waitEventsMessages<ForumTopicReopened>(initRequest, errorFactory) ) = waitEventsMessages<ForumTopicReopened>(initRequest, errorFactory)
suspend fun BehaviourContext.waitForumTopicEditedEventsMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEventsMessages<ForumTopicEdited>(initRequest, errorFactory)
suspend fun BehaviourContext.waitGeneralForumTopicHiddenEventsMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEventsMessages<GeneralForumTopicHidden>(initRequest, errorFactory)
suspend fun BehaviourContext.waitGeneralForumTopicUnhiddenEventsMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEventsMessages<GeneralForumTopicUnhidden>(initRequest, errorFactory)
suspend fun BehaviourContext.waitWriteAccessAllowedEventsMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEventsMessages<WriteAccessAllowed>(initRequest, errorFactory)
suspend fun BehaviourContext.waitChatSharedRequestEventsMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEventsMessages<ChatSharedRequest>(initRequest, errorFactory)
suspend fun BehaviourContext.waitUserSharedEventsMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEventsMessages<UserShared>(initRequest, errorFactory)
suspend fun BehaviourContext.waitChatSharedEventsMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEventsMessages<ChatShared>(initRequest, errorFactory)

View File

@@ -607,3 +607,27 @@ suspend fun <BC : BehaviourContext> BC.onInvoice(
markerFactory, markerFactory,
scenarioReceiver scenarioReceiver
) )
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onVisualContent(
initialFilter: CommonMessageFilter<VisualMediaGroupPartContent>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, VisualMediaGroupMessage, Update> = MessageFilterByChat,
markerFactory: MarkerFactory<in VisualMediaGroupMessage, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, VisualMediaGroupMessage>
) = onContentMessageWithType(
initialFilter,
subcontextUpdatesFilter,
markerFactory,
scenarioReceiver
)

View File

@@ -38,7 +38,7 @@ suspend fun <BC : BehaviourContext> BC.onDeepLink(
scenarioReceiver, scenarioReceiver,
) { ) {
(it.messageUpdateOrNull()) ?.data ?.commonMessageOrNull() ?.withContentOrNull<TextContent>() ?.let { message -> (it.messageUpdateOrNull()) ?.data ?.commonMessageOrNull() ?.withContentOrNull<TextContent>() ?.let { message ->
message to message.content.textSources[1].source.removePrefix(" ").decodeURLQueryComponent() message to (message.content.textSources.getOrNull(1) ?.source ?.removePrefix(" ") ?.decodeURLQueryComponent() ?: return@let null)
} ?.let(::listOfNotNull) } ?.let(::listOfNotNull)
}.also { }.also {
triggersHolder.handleableCommandsHolder.registerHandleable(startRegex) triggersHolder.handleableCommandsHolder.registerHandleable(startRegex)

View File

@@ -1,18 +1,3 @@
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/@file:Suppress("unused", "UNCHECKED_CAST")
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.*
@@ -35,7 +20,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : MessageContent>
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<T>> noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<T>>
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
when (it) { when (it) {
is BaseEditMessageUpdate -> (it.editMessageUpdateOrNull() ?.data ?.withContent<T>()) is BaseEditMessageUpdate -> (it.data.withContent<T>())
else -> null else -> null
} ?.let(::listOfNotNull) } ?.let(::listOfNotNull)
} }

View File

@@ -13,12 +13,19 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.*
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicEdited
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicHidden
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidden
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
import dev.inmo.tgbotapi.types.message.PrivateEventMessage import dev.inmo.tgbotapi.types.message.PrivateEventMessage
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
import dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage import dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
import dev.inmo.tgbotapi.types.request.ChatShared
import dev.inmo.tgbotapi.types.request.ChatSharedRequest
import dev.inmo.tgbotapi.types.request.UserShared
import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.types.update.abstracts.Update
internal suspend inline fun <BC : BehaviourContext, reified T : ChatEvent> BC.onEvent( internal suspend inline fun <BC : BehaviourContext, reified T : ChatEvent> BC.onEvent(
@@ -575,3 +582,143 @@ suspend fun <BC : BehaviourContext> BC.onForumTopicReopened(
markerFactory: MarkerFactory<in ChatEventMessage<ForumTopicReopened>, Any> = ByChatMessageMarkerFactory, markerFactory: MarkerFactory<in ChatEventMessage<ForumTopicReopened>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, SupergroupEventMessage<ForumTopicReopened>> scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, SupergroupEventMessage<ForumTopicReopened>>
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) ) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onForumTopicEdited(
initialFilter: SimpleFilter<SupergroupEventMessage<ForumTopicEdited>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, SupergroupEventMessage<ForumTopicEdited>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<ForumTopicEdited>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, SupergroupEventMessage<ForumTopicEdited>>
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onGeneralForumTopicHidden(
initialFilter: SimpleFilter<SupergroupEventMessage<GeneralForumTopicHidden>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, SupergroupEventMessage<GeneralForumTopicHidden>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<GeneralForumTopicHidden>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, SupergroupEventMessage<GeneralForumTopicHidden>>
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onGeneralForumTopicUnhidden(
initialFilter: SimpleFilter<SupergroupEventMessage<GeneralForumTopicUnhidden>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, SupergroupEventMessage<GeneralForumTopicUnhidden>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<GeneralForumTopicUnhidden>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, SupergroupEventMessage<GeneralForumTopicUnhidden>>
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onWriteAccessAllowed(
initialFilter: SimpleFilter<SupergroupEventMessage<WriteAccessAllowed>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, SupergroupEventMessage<WriteAccessAllowed>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<WriteAccessAllowed>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, SupergroupEventMessage<WriteAccessAllowed>>
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onChatSharedRequest(
initialFilter: SimpleFilter<PrivateEventMessage<ChatSharedRequest>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PrivateEventMessage<ChatSharedRequest>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<ChatSharedRequest>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PrivateEventMessage<ChatSharedRequest>>
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onUserShared(
initialFilter: SimpleFilter<PrivateEventMessage<UserShared>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PrivateEventMessage<UserShared>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<UserShared>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PrivateEventMessage<UserShared>>
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onChatShared(
initialFilter: SimpleFilter<PrivateEventMessage<ChatShared>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PrivateEventMessage<ChatShared>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<ChatShared>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PrivateEventMessage<ChatShared>>
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)

View File

@@ -2,6 +2,7 @@ plugins {
id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization" id "org.jetbrains.kotlin.plugin.serialization"
id "com.google.devtools.ksp" id "com.google.devtools.ksp"
id "org.jetbrains.dokka"
} }
project.description = "Core part of tgbotapi with all (and only) required functionality for working with Telegram Bot API" project.description = "Core part of tgbotapi with all (and only) required functionality for working with Telegram Bot API"

View File

@@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.abstracts
interface SpoilerableData {
val spoilered: Boolean
}

View File

@@ -30,7 +30,7 @@ class KtorRequestsExecutor(
client: HttpClient = HttpClient(), client: HttpClient = HttpClient(),
callsFactories: List<KtorCallFactory> = emptyList(), callsFactories: List<KtorCallFactory> = emptyList(),
excludeDefaultFactories: Boolean = false, excludeDefaultFactories: Boolean = false,
private val requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter(), private val requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter,
private val jsonFormatter: Json = nonstrictJsonFormat, private val jsonFormatter: Json = nonstrictJsonFormat,
private val pipelineStepsHolder: KtorPipelineStepsHolder = KtorPipelineStepsHolder private val pipelineStepsHolder: KtorPipelineStepsHolder = KtorPipelineStepsHolder
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) { ) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
@@ -51,7 +51,7 @@ class KtorRequestsExecutor(
override suspend fun <T : Any> execute(request: Request<T>): T { override suspend fun <T : Any> execute(request: Request<T>): T {
return runCatchingSafely { return runCatchingSafely {
pipelineStepsHolder.onBeforeSearchCallFactory(request, callsFactories) pipelineStepsHolder.onBeforeSearchCallFactory(request, callsFactories)
requestsLimiter.limit { requestsLimiter.limit(request) {
var result: T? = null var result: T? = null
lateinit var factoryHandledRequest: KtorCallFactory lateinit var factoryHandledRequest: KtorCallFactory
for (potentialFactory in callsFactories) { for (potentialFactory in callsFactories) {
@@ -111,7 +111,7 @@ class KtorRequestsExecutorBuilder(
var client: HttpClient = HttpClient() var client: HttpClient = HttpClient()
var callsFactories: List<KtorCallFactory> = emptyList() var callsFactories: List<KtorCallFactory> = emptyList()
var excludeDefaultFactories: Boolean = false var excludeDefaultFactories: Boolean = false
var requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter() var requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter
var jsonFormatter: Json = nonstrictJsonFormat var jsonFormatter: Json = nonstrictJsonFormat
fun build() = KtorRequestsExecutor(telegramAPIUrlsKeeper, client, callsFactories, excludeDefaultFactories, requestsLimiter, jsonFormatter) fun build() = KtorRequestsExecutor(telegramAPIUrlsKeeper, client, callsFactories, excludeDefaultFactories, requestsLimiter, jsonFormatter)

View File

@@ -1,66 +1,18 @@
package dev.inmo.tgbotapi.bot.settings.limiters package dev.inmo.tgbotapi.bot.settings.limiters
import dev.inmo.micro_utils.coroutines.safely
import dev.inmo.tgbotapi.bot.exceptions.TooMuchRequestsException import dev.inmo.tgbotapi.bot.exceptions.TooMuchRequestsException
import dev.inmo.tgbotapi.types.MilliSeconds
import dev.inmo.tgbotapi.types.RetryAfterError
import io.ktor.client.plugins.ClientRequestException
import io.ktor.http.HttpStatusCode
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
/** /**
* This limiter will limit requests only after getting a [RetryAfterError] or [ClientRequestException] with * Simple limiter which will lock any request when [TooMuchRequestsExceptions] is thrown and rerun request after lock time
* [HttpStatusCode.TooManyRequests] status code. Important thing is that in case if some of block has been blocked, all
* the others will wait until it will be possible to be called
*
* @param defaultTooManyRequestsDelay This parameter will be used in case of getting [ClientRequestException] with
* [HttpStatusCode.TooManyRequests] as a parameter for delay like it would be [TooMuchRequestsException]. The reason of
* it is that in [ClientRequestException] there is no information about required delay between requests
*/ */
class ExceptionsOnlyLimiter( object ExceptionsOnlyLimiter : RequestLimiter {
private val defaultTooManyRequestsDelay: MilliSeconds = 1000L
) : RequestLimiter {
private val lockState = MutableStateFlow(false)
private suspend fun lock(timeMillis: MilliSeconds) {
try {
safely {
lockState.emit(true)
delay(timeMillis)
}
} finally {
lockState.emit(false)
}
}
override suspend fun <T> limit(block: suspend () -> T): T { override suspend fun <T> limit(block: suspend () -> T): T {
while (true) { return try {
lockState.first { !it } block()
var throwable: Throwable? = null } catch (e: TooMuchRequestsException) {
val result = safely({ delay(e.retryAfter.leftToRetry)
throwable = when (it) { limit(block)
is TooMuchRequestsException -> {
lock(it.retryAfter.leftToRetry)
it
}
is ClientRequestException -> {
if (it.response.status == HttpStatusCode.TooManyRequests) {
lock(defaultTooManyRequestsDelay)
} else {
throw it
}
it
}
else -> throw it
}
null
}) {
block()
}
if (throwable == null) {
return result!!
}
} }
} }
} }

View File

@@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.bot.settings.limiters
object NoLimitsLimiter : RequestLimiter {
override suspend fun <T> limit(block: suspend () -> T): T = block()
}

View File

@@ -1,8 +1,12 @@
package dev.inmo.tgbotapi.bot.settings.limiters package dev.inmo.tgbotapi.bot.settings.limiters
import dev.inmo.tgbotapi.requests.abstracts.Request
interface RequestLimiter { interface RequestLimiter {
/** /**
* Use limit for working of block (like delay between or after, for example) * Use limit for working of block (like delay between or after, for example)
*/ */
suspend fun <T> limit(block: suspend () -> T): T suspend fun <T> limit(block: suspend () -> T): T
suspend fun <T : Any> limit(request: Request<T>, block: suspend () -> T) = limit(block)
} }

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.requests.chat.forum
import dev.inmo.tgbotapi.abstracts.types.ChatRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.utils.RGBColor
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
@Serializable
data class CloseGeneralForumTopic (
@SerialName(chatIdField)
override val chatId: ChatIdentifier
): ModifyForumRequest, GeneralForumRequest<Boolean> {
override fun method(): String = "closeGeneralForumTopic"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -1,11 +1,7 @@
package dev.inmo.tgbotapi.requests.chat.forum package dev.inmo.tgbotapi.requests.chat.forum
import dev.inmo.tgbotapi.abstracts.types.ChatRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.utils.RGBColor
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
@Serializable @Serializable
data class EditForumTopic ( data class EditForumTopic (
@@ -14,12 +10,12 @@ data class EditForumTopic (
@SerialName(messageThreadIdField) @SerialName(messageThreadIdField)
val messageThreadId: MessageThreadId, val messageThreadId: MessageThreadId,
@SerialName(nameField) @SerialName(nameField)
val name: String, val name: String? = null,
@SerialName(iconCustomEmojiIdField) @SerialName(iconCustomEmojiIdField)
val iconEmojiId: CustomEmojiId, val iconEmojiId: CustomEmojiId? = null,
): ModifyForumRequest { ): ModifyForumRequest {
init { init {
if (name.length !in threadNameLength) { if (name != null && name.length !in threadNameLength) {
throw IllegalArgumentException("Thread name must be in $threadNameLength range") throw IllegalArgumentException("Thread name must be in $threadNameLength range")
} }
} }

View File

@@ -0,0 +1,22 @@
package dev.inmo.tgbotapi.requests.chat.forum
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.*
@Serializable
data class EditGeneralForumTopic (
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(nameField)
val name: String
): ModifyForumRequest, GeneralForumRequest<Boolean> {
init {
if (name.length !in threadNameLength) {
throw IllegalArgumentException("Thread name must be in $threadNameLength range")
}
}
override fun method(): String = "editGeneralForumTopic"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -0,0 +1,6 @@
package dev.inmo.tgbotapi.requests.chat.forum
import dev.inmo.tgbotapi.abstracts.types.ChatRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
sealed interface GeneralForumRequest<T : Any> : ForumRequest<T>, ChatRequest

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.requests.chat.forum
import dev.inmo.tgbotapi.abstracts.types.ChatRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.utils.RGBColor
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
@Serializable
data class HideGeneralForumTopic (
@SerialName(chatIdField)
override val chatId: ChatIdentifier
): ModifyForumRequest, GeneralForumRequest<Boolean> {
override fun method(): String = "hideGeneralForumTopic"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.requests.chat.forum
import dev.inmo.tgbotapi.abstracts.types.ChatRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.utils.RGBColor
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
@Serializable
data class ReopenGeneralForumTopic (
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
): ModifyForumRequest, GeneralForumRequest<Boolean> {
override fun method(): String = "reopenGeneralForumTopic"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.requests.chat.forum
import dev.inmo.tgbotapi.abstracts.types.ChatRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.utils.RGBColor
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
@Serializable
data class UnhideGeneralForumTopic (
@SerialName(chatIdField)
override val chatId: ChatIdentifier
): ModifyForumRequest, GeneralForumRequest<Boolean> {
override fun method(): String = "unhideGeneralForumTopic"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -16,7 +16,9 @@ data class RestrictChatMember(
@SerialName(untilDateField) @SerialName(untilDateField)
override val untilDate: TelegramDate? = null, override val untilDate: TelegramDate? = null,
@SerialName(permissionsField) @SerialName(permissionsField)
val permissions: ChatPermissions = ChatPermissions() val permissions: ChatPermissions = ChatPermissions(),
@SerialName(useIndependentChatPermissionsField)
val useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) : ChatMemberRequest<Boolean>, UntilDate { ) : ChatMemberRequest<Boolean>, UntilDate {
override fun method(): String = "restrictChatMember" override fun method(): String = "restrictChatMember"
override val resultDeserializer: DeserializationStrategy<Boolean> override val resultDeserializer: DeserializationStrategy<Boolean>

View File

@@ -18,7 +18,7 @@ data class SetChatAdministratorCustomTitle(
override val resultDeserializer: DeserializationStrategy<Boolean> override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer() get() = Boolean.serializer()
override val requestSerializer: SerializationStrategy<*> override val requestSerializer: SerializationStrategy<*>
get() = RestrictChatMember.serializer() get() = serializer()
init { init {
if (customTitle.length !in customTitleLength) { if (customTitle.length !in customTitleLength) {

View File

@@ -12,7 +12,9 @@ data class SetChatPermissions (
@SerialName(chatIdField) @SerialName(chatIdField)
override val chatId: ChatIdentifier, override val chatId: ChatIdentifier,
@SerialName(permissionsField) @SerialName(permissionsField)
val permissions: ChatPermissions val permissions: ChatPermissions,
@SerialName(useIndependentChatPermissionsField)
val useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
): ChatRequest, SimpleRequest<Boolean> { ): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "setChatPermissions" override fun method(): String = "setChatPermissions"
override val resultDeserializer: DeserializationStrategy<Boolean> override val resultDeserializer: DeserializationStrategy<Boolean>

View File

@@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.requests.send package dev.inmo.tgbotapi.requests.send
import dev.inmo.tgbotapi.requests.send.abstracts.OptionallyMessageThreadRequest
import dev.inmo.tgbotapi.requests.send.abstracts.SendChatMessageRequest import dev.inmo.tgbotapi.requests.send.abstracts.SendChatMessageRequest
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.actions.BotAction import dev.inmo.tgbotapi.types.actions.BotAction
@@ -14,8 +15,10 @@ data class SendAction(
@SerialName(chatIdField) @SerialName(chatIdField)
override val chatId: ChatIdentifier, override val chatId: ChatIdentifier,
@SerialName(actionField) @SerialName(actionField)
val action: BotAction val action: BotAction,
): SendChatMessageRequest<Boolean> { @SerialName(messageThreadIdField)
override val threadId: MessageThreadId? = chatId.threadId
): SendChatMessageRequest<Boolean>, OptionallyMessageThreadRequest {
override fun method(): String = "sendChatAction" override fun method(): String = "sendChatAction"
override val resultDeserializer: DeserializationStrategy<Boolean> override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer() get() = Boolean.serializer()

View File

@@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.requests.send.abstracts
import dev.inmo.tgbotapi.abstracts.SpoilerableData
interface OptionallyWithSpoilerRequest : SpoilerableData

View File

@@ -25,6 +25,7 @@ fun SendAnimation(
thumb: InputFile? = null, thumb: InputFile? = null,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -47,6 +48,7 @@ fun SendAnimation(
text, text,
parseMode, parseMode,
null, null,
spoilered,
duration, duration,
width, width,
height, height,
@@ -73,6 +75,7 @@ fun SendAnimation(
animation: InputFile, animation: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -95,6 +98,7 @@ fun SendAnimation(
entities.makeString(), entities.makeString(),
null, null,
entities.toRawMessageEntities(), entities.toRawMessageEntities(),
spoilered,
duration, duration,
width, width,
height, height,
@@ -133,6 +137,8 @@ data class SendAnimationData internal constructor(
override val parseMode: ParseMode? = null, override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField) @SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null, private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(hasSpoilerField)
override val spoilered: Boolean = false,
@SerialName(durationField) @SerialName(durationField)
override val duration: Long? = null, override val duration: Long? = null,
@SerialName(widthField) @SerialName(widthField)
@@ -157,7 +163,8 @@ data class SendAnimationData internal constructor(
TextableSendMessageRequest<ContentMessage<AnimationContent>>, TextableSendMessageRequest<ContentMessage<AnimationContent>>,
ThumbedSendMessageRequest<ContentMessage<AnimationContent>>, ThumbedSendMessageRequest<ContentMessage<AnimationContent>>,
DuratedSendMessageRequest<ContentMessage<AnimationContent>>, DuratedSendMessageRequest<ContentMessage<AnimationContent>>,
SizedSendMessageRequest<ContentMessage<AnimationContent>> SizedSendMessageRequest<ContentMessage<AnimationContent>>,
OptionallyWithSpoilerRequest
{ {
override val textSources: TextSourcesList? by lazy { override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)

View File

@@ -37,7 +37,7 @@ fun <T : MediaGroupPartContent> SendMediaGroup(
protectContent: Boolean = false, protectContent: Boolean = false,
replyToMessageId: MessageId? = null, replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null allowSendingWithoutReply: Boolean? = null
): Request<PossiblySentViaBotCommonMessage<T>> { ): Request<PossiblySentViaBotCommonMessage<MediaGroupContent<T>>> {
if (media.size !in mediaCountInMediaGroup) { if (media.size !in mediaCountInMediaGroup) {
throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size) throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size)
} }
@@ -70,7 +70,7 @@ fun <T : MediaGroupPartContent> SendMediaGroup(
data, data,
SendMediaGroupFiles(files) SendMediaGroupFiles(files)
) )
}) as Request<PossiblySentViaBotCommonMessage<T>> }) as Request<PossiblySentViaBotCommonMessage<MediaGroupContent<T>>>
} }
/** /**

View File

@@ -23,6 +23,7 @@ fun SendPhoto(
photo: InputFile, photo: InputFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
@@ -36,6 +37,7 @@ fun SendPhoto(
text, text,
parseMode, parseMode,
null, null,
spoilered,
threadId, threadId,
disableNotification, disableNotification,
protectContent, protectContent,
@@ -55,6 +57,7 @@ fun SendPhoto(
chatId: ChatIdentifier, chatId: ChatIdentifier,
photo: InputFile, photo: InputFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
threadId: MessageThreadId? = chatId.threadId, threadId: MessageThreadId? = chatId.threadId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
@@ -68,6 +71,7 @@ fun SendPhoto(
entities.makeString(), entities.makeString(),
null, null,
entities.toRawMessageEntities(), entities.toRawMessageEntities(),
spoilered,
threadId, threadId,
disableNotification, disableNotification,
protectContent, protectContent,
@@ -98,6 +102,8 @@ data class SendPhotoData internal constructor(
override val parseMode: ParseMode? = null, override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField) @SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null, private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(hasSpoilerField)
override val spoilered: Boolean = false,
@SerialName(messageThreadIdField) @SerialName(messageThreadIdField)
override val threadId: MessageThreadId? = chatId.threadId, override val threadId: MessageThreadId? = chatId.threadId,
@SerialName(disableNotificationField) @SerialName(disableNotificationField)
@@ -113,7 +119,8 @@ data class SendPhotoData internal constructor(
) : DataRequest<ContentMessage<PhotoContent>>, ) : DataRequest<ContentMessage<PhotoContent>>,
SendMessageRequest<ContentMessage<PhotoContent>>, SendMessageRequest<ContentMessage<PhotoContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<PhotoContent>>, ReplyingMarkupSendMessageRequest<ContentMessage<PhotoContent>>,
TextableSendMessageRequest<ContentMessage<PhotoContent>> TextableSendMessageRequest<ContentMessage<PhotoContent>>,
OptionallyWithSpoilerRequest
{ {
override val textSources: TextSourcesList? by lazy { override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)

View File

@@ -25,6 +25,7 @@ fun SendVideo(
thumb: InputFile? = null, thumb: InputFile? = null,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -48,6 +49,7 @@ fun SendVideo(
text, text,
parseMode, parseMode,
null, null,
spoilered,
duration, duration,
width, width,
height, height,
@@ -75,6 +77,7 @@ fun SendVideo(
video: InputFile, video: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@@ -98,6 +101,7 @@ fun SendVideo(
entities.makeString(), entities.makeString(),
null, null,
entities.toRawMessageEntities(), entities.toRawMessageEntities(),
spoilered,
duration, duration,
width, width,
height, height,
@@ -137,6 +141,8 @@ data class SendVideoData internal constructor(
override val parseMode: ParseMode? = null, override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField) @SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null, private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(hasSpoilerField)
override val spoilered: Boolean = false,
@SerialName(durationField) @SerialName(durationField)
override val duration: Long? = null, override val duration: Long? = null,
@SerialName(widthField) @SerialName(widthField)
@@ -163,7 +169,8 @@ data class SendVideoData internal constructor(
TextableSendMessageRequest<ContentMessage<VideoContent>>, TextableSendMessageRequest<ContentMessage<VideoContent>>,
ThumbedSendMessageRequest<ContentMessage<VideoContent>>, ThumbedSendMessageRequest<ContentMessage<VideoContent>>,
DuratedSendMessageRequest<ContentMessage<VideoContent>>, DuratedSendMessageRequest<ContentMessage<VideoContent>>,
SizedSendMessageRequest<ContentMessage<VideoContent>> SizedSendMessageRequest<ContentMessage<VideoContent>>,
OptionallyWithSpoilerRequest
{ {
override val textSources: TextSourcesList? by lazy { override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)

View File

@@ -14,6 +14,7 @@ import kotlinx.serialization.json.longOrNull
import kotlin.jvm.JvmInline import kotlin.jvm.JvmInline
const val internalLinkBeginning = "https://t.me" const val internalLinkBeginning = "https://t.me"
const val internalUserLinkBeginning = "tg://user?id="
@Serializable(ChatIdentifierSerializer::class) @Serializable(ChatIdentifierSerializer::class)
@ClassCastsIncluded @ClassCastsIncluded
@@ -30,6 +31,9 @@ sealed interface IdChatIdentifier : ChatIdentifier {
companion object { companion object {
operator fun invoke(chatId: Identifier) = ChatId(chatId) operator fun invoke(chatId: Identifier) = ChatId(chatId)
operator fun invoke(chatId: Identifier, threadId: MessageThreadId?) = threadId ?.let {
ChatIdWithThreadId(chatId, threadId)
} ?: ChatId(chatId)
} }
} }
@@ -51,24 +55,34 @@ value class ChatIdWithThreadId(val chatIdWithThreadId: Pair<Identifier, MessageT
val ChatIdentifier.threadId: MessageThreadId? val ChatIdentifier.threadId: MessageThreadId?
get() = (this as? IdChatIdentifier) ?.threadId get() = (this as? IdChatIdentifier) ?.threadId
fun IdChatIdentifier.toChatId() = when (this) {
is ChatId -> this
is ChatIdWithThreadId -> ChatId(chatId)
}
fun IdChatIdentifier.toChatWithThreadId(threadId: MessageThreadId) = IdChatIdentifier(chatId, threadId)
/** /**
* https://core.telegram.org/bots/api#formatting-options * https://core.telegram.org/bots/api#formatting-options
*/ */
@Warning("This API have restrictions in Telegram System") @Warning("This API have restrictions in Telegram System")
val Identifier.userLink: String val Identifier.userLink: String
get() = "tg://user?id=$this" get() = "$internalUserLinkBeginning$this"
/** /**
* https://core.telegram.org/bots/api#formatting-options * https://core.telegram.org/bots/api#formatting-options
*/ */
@Warning("This API have restrictions in Telegram System") @Warning("This API have restrictions in Telegram System")
val UserId.userLink: String val UserId.userLink: String
get() = chatId.userLink get() = chatId.userLink
val User.link: String val User.userLink: String
get() = id.userLink get() = id.userLink
@Deprecated("Deprecated due to the conflicts in name", ReplaceWith("this.userLink", "dev.inmo.tgbotapi.types.userLink"))
val User.link: String
get() = userLink
typealias UserId = IdChatIdentifier typealias UserId = ChatId
fun Identifier.toChatId(): IdChatIdentifier = ChatId(this) fun Identifier.toChatId(): ChatId = ChatId(this)
fun Int.toChatId(): IdChatIdentifier = toLong().toChatId() fun Int.toChatId(): IdChatIdentifier = toLong().toChatId()
fun Byte.toChatId(): IdChatIdentifier = toLong().toChatId() fun Byte.toChatId(): IdChatIdentifier = toLong().toChatId()
@@ -94,6 +108,7 @@ object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
override val descriptor: SerialDescriptor = internalSerializer.descriptor override val descriptor: SerialDescriptor = internalSerializer.descriptor
override fun deserialize(decoder: Decoder): ChatIdentifier { override fun deserialize(decoder: Decoder): ChatIdentifier {
val id = internalSerializer.deserialize(decoder) val id = internalSerializer.deserialize(decoder)
return id.longOrNull ?.let { return id.longOrNull ?.let {
ChatId(it) ChatId(it)
} ?: id.content.let { } ?: id.content.let {
@@ -112,3 +127,41 @@ object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
} }
} }
} }
@RiskFeature
object FullChatIdentifierSerializer : KSerializer<ChatIdentifier> {
private val internalSerializer = JsonPrimitive.serializer()
override val descriptor: SerialDescriptor = internalSerializer.descriptor
override fun deserialize(decoder: Decoder): ChatIdentifier {
val id = internalSerializer.deserialize(decoder)
return id.longOrNull ?.let {
ChatId(it)
} ?:let {
val splitted = id.content.split("/")
if (splitted.size == 2) {
val (chatId, threadId) = splitted
ChatIdWithThreadId(
chatId.toLongOrNull() ?: return@let null,
threadId.toLongOrNull() ?: return@let null
)
} else {
null
}
} ?: id.content.let {
if (!it.startsWith("@")) {
Username("@$it")
} else {
Username(it)
}
}
}
override fun serialize(encoder: Encoder, value: ChatIdentifier) {
when (value) {
is ChatId -> encoder.encodeLong(value.chatId)
is ChatIdWithThreadId -> encoder.encodeString("${value.chatId}/${value.threadId}")
is Username -> encoder.encodeString(value.username)
}
}
}

View File

@@ -228,6 +228,7 @@ const val allowsMultipleAnswersField = "allows_multiple_answers"
const val isAnonymousField = "is_anonymous" const val isAnonymousField = "is_anonymous"
const val canManageTopicsField = "can_manage_topics" const val canManageTopicsField = "can_manage_topics"
const val captionEntitiesField = "caption_entities" const val captionEntitiesField = "caption_entities"
const val hasSpoilerField = "has_spoiler"
const val loginUrlField = "login_url" const val loginUrlField = "login_url"
const val forwardTextField = "forward_text" const val forwardTextField = "forward_text"
const val botUsernameField = "bot_username" const val botUsernameField = "bot_username"
@@ -242,8 +243,10 @@ const val customTitleField = "custom_title"
const val optionIdsField = "option_ids" const val optionIdsField = "option_ids"
const val ipAddressField = "ip_address" const val ipAddressField = "ip_address"
const val linkedChatIdField = "linked_chat_id" const val linkedChatIdField = "linked_chat_id"
const val hasHiddenMembersField = "has_hidden_members"
const val joinToSendMessagesField = "join_to_send_messages" const val joinToSendMessagesField = "join_to_send_messages"
const val joinByRequestField = "join_by_request" const val joinByRequestField = "join_by_request"
const val hasAggressiveAntiSpamEnabledField = "has_aggressive_anti_spam_enabled"
const val horizontalAccuracyField = "horizontal_accuracy" const val horizontalAccuracyField = "horizontal_accuracy"
const val revokeMessagesField = "revoke_messages" const val revokeMessagesField = "revoke_messages"
const val messageAutoDeleteTimeField = "message_auto_delete_time" const val messageAutoDeleteTimeField = "message_auto_delete_time"
@@ -258,6 +261,19 @@ const val iconColorField = "icon_color"
const val requestContactField = "request_contact" const val requestContactField = "request_contact"
const val requestLocationField = "request_location" const val requestLocationField = "request_location"
const val requestPollField = "request_poll" const val requestPollField = "request_poll"
const val requestUserField = "request_user"
const val requestChatField = "request_chat"
const val requestIdField = "request_id"
const val userIsBotField = "user_is_bot"
const val userIsPremiumField = "user_is_premium"
const val chatIsChannelField = "chat_is_channel"
const val chatIsForumField = "chat_is_forum"
const val chatHasUsernameField = "chat_has_username"
const val chatIsCreatedField = "chat_is_created"
const val userAdministratorRightsField = "user_administrator_rights"
const val botAdministratorRightsField = "bot_administrator_rights"
const val botIsMemberField = "bot_is_member"
const val fileNameField = "file_name" const val fileNameField = "file_name"
const val mimeTypeField = "mime_type" const val mimeTypeField = "mime_type"
@@ -324,7 +340,12 @@ const val scopeField = "scope"
const val isMemberField = "is_member" const val isMemberField = "is_member"
const val isForumField = "is_forum" const val isForumField = "is_forum"
const val canSendMessagesField = "can_send_messages" const val canSendMessagesField = "can_send_messages"
const val canSendMediaMessagesField = "can_send_media_messages" const val canSendAudiosField = "can_send_audios"
const val canSendDocumentsField = "can_send_documents"
const val canSendPhotosField = "can_send_photos"
const val canSendVideosField = "can_send_videos"
const val canSendVideoNotesField = "can_send_video_notes"
const val canSendVoiceNotesField = "can_send_voice_notes"
const val canSendOtherMessagesField = "can_send_other_messages" const val canSendOtherMessagesField = "can_send_other_messages"
const val canSendPollsField = "can_send_polls" const val canSendPollsField = "can_send_polls"
const val canAddWebPagePreviewsField = "can_add_web_page_previews" const val canAddWebPagePreviewsField = "can_add_web_page_previews"
@@ -342,6 +363,7 @@ const val canPinMessagesField = "can_pin_messages"
const val canPromoteMembersField = "can_promote_members" const val canPromoteMembersField = "can_promote_members"
const val canManageVoiceChatsField = "can_manage_voice_chats" const val canManageVoiceChatsField = "can_manage_voice_chats"
const val canManageVideoChatsField = "can_manage_video_chats" const val canManageVideoChatsField = "can_manage_video_chats"
const val useIndependentChatPermissionsField = "use_independent_chat_permissions"
const val rightsField = "rights" const val rightsField = "rights"
const val forChannelsField = "for_channels" const val forChannelsField = "for_channels"
const val canManageChatField = "can_manage_chat" const val canManageChatField = "can_manage_chat"
@@ -372,6 +394,7 @@ const val latitudeField = "latitude"
const val longitudeField = "longitude" const val longitudeField = "longitude"
const val headingField = "heading" const val headingField = "heading"
const val fromField = "from" const val fromField = "from"
const val userChatIdField = "user_chat_id"
const val userField = "user" const val userField = "user"
const val dateField = "date" const val dateField = "date"
const val chatField = "chat" const val chatField = "chat"
@@ -461,6 +484,7 @@ const val shouldSendEmailToProviderField = "send_email_to_provider"
const val resizeKeyboardField = "resize_keyboard" const val resizeKeyboardField = "resize_keyboard"
const val oneTimeKeyboardField = "one_time_keyboard" const val oneTimeKeyboardField = "one_time_keyboard"
const val inputFieldPlaceholderField = "input_field_placeholder" const val inputFieldPlaceholderField = "input_field_placeholder"
const val isPersistentField = "is_persistent"
const val priceDependOnShipAddressField = "is_flexible" const val priceDependOnShipAddressField = "is_flexible"

View File

@@ -3,10 +3,11 @@ package dev.inmo.tgbotapi.types.InlineQueries.query
import dev.inmo.tgbotapi.types.InlineQueryIdentifier import dev.inmo.tgbotapi.types.InlineQueryIdentifier
import dev.inmo.tgbotapi.types.chat.User import dev.inmo.tgbotapi.types.chat.User
import dev.inmo.tgbotapi.types.chat.ChatType import dev.inmo.tgbotapi.types.chat.ChatType
import dev.inmo.tgbotapi.types.chat.CommonUser
data class BaseInlineQuery( data class BaseInlineQuery(
override val id: InlineQueryIdentifier, override val id: InlineQueryIdentifier,
override val from: User, override val from: CommonUser,
override val query: String, override val query: String,
override val offset: String, override val offset: String,
override val chatType: ChatType? override val chatType: ChatType?

View File

@@ -3,10 +3,16 @@ package dev.inmo.tgbotapi.types.InlineQueries.query
import dev.inmo.tgbotapi.abstracts.FromUser import dev.inmo.tgbotapi.abstracts.FromUser
import dev.inmo.tgbotapi.types.InlineQueryIdentifier import dev.inmo.tgbotapi.types.InlineQueryIdentifier
import dev.inmo.tgbotapi.types.chat.ChatType import dev.inmo.tgbotapi.types.chat.ChatType
import dev.inmo.tgbotapi.types.chat.CommonUser
import dev.inmo.tgbotapi.types.chat.User
sealed interface InlineQuery : FromUser { sealed interface InlineQuery : FromUser {
val id: InlineQueryIdentifier val id: InlineQueryIdentifier
val query: String val query: String
val offset: String val offset: String
val chatType: ChatType? val chatType: ChatType?
override val from: CommonUser
override val user: CommonUser
get() = from
} }

View File

@@ -3,11 +3,12 @@ package dev.inmo.tgbotapi.types.InlineQueries.query
import dev.inmo.tgbotapi.types.InlineQueryIdentifier import dev.inmo.tgbotapi.types.InlineQueryIdentifier
import dev.inmo.tgbotapi.types.chat.User import dev.inmo.tgbotapi.types.chat.User
import dev.inmo.tgbotapi.types.chat.ChatType import dev.inmo.tgbotapi.types.chat.ChatType
import dev.inmo.tgbotapi.types.chat.CommonUser
import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.location.Location
data class LocationInlineQuery( data class LocationInlineQuery(
override val id: InlineQueryIdentifier, override val id: InlineQueryIdentifier,
override val from: User, override val from: CommonUser,
override val query: String, override val query: String,
override val offset: String, override val offset: String,
override val chatType: ChatType?, override val chatType: ChatType?,

View File

@@ -12,7 +12,7 @@ internal data class RawInlineQuery(
@SerialName(idField) @SerialName(idField)
val id: InlineQueryIdentifier, val id: InlineQueryIdentifier,
@SerialName(fromField) @SerialName(fromField)
val from: User, val from: CommonUser,
@SerialName(queryField) @SerialName(queryField)
val query: String, val query: String,
@SerialName(offsetField) @SerialName(offsetField)

View File

@@ -94,6 +94,42 @@ data class RequestPollKeyboardButton(
val requestPoll: KeyboardButtonPollType val requestPoll: KeyboardButtonPollType
) : KeyboardButton ) : KeyboardButton
/**
* Private chats only. When user will tap on this button, he will be asked for the chat with [requestChat] options. You
* will be able to catch this [ChatId] in updates and data using
* [dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUserShared] in case you are using Behaviour
* Builder OR with [dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter.messagesFlow]
* and [kotlinx.coroutines.flow.filterIsInstance].
*
* In case you will use [dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUserShared] it is
* recommended to use [kotlinx.coroutines.flow.Flow] [kotlinx.coroutines.flow.filter] with checking of incoming
* [dev.inmo.tgbotapi.types.request.UserShared.requestId]
*/
@Serializable
data class RequestUserKeyboardButton(
override val text: String,
@SerialName(requestUserField)
val requestUser: KeyboardButtonRequestUser
) : KeyboardButton
/**
* Private chats only. When user will tap on this button, he will be asked for the chat with [requestChat] options. You
* will be able to catch this [ChatId] in updates and data using
* [dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared] in case you are using Behaviour
* Builder OR with [dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter.messagesFlow]
* and [kotlinx.coroutines.flow.filterIsInstance].
*
* In case you will use [dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared] it is
* recommended to use [kotlinx.coroutines.flow.Flow] [kotlinx.coroutines.flow.filter] with checking of incoming
* [dev.inmo.tgbotapi.types.request.ChatShared.requestId]
*/
@Serializable
data class RequestChatKeyboardButton(
override val text: String,
@SerialName(requestChatField)
val requestChat: KeyboardButtonRequestChat
) : KeyboardButton
@RiskFeature @RiskFeature
object KeyboardButtonSerializer : KSerializer<KeyboardButton> { object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
private val internalSerializer = JsonElement.serializer() private val internalSerializer = JsonElement.serializer()
@@ -124,6 +160,20 @@ object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
asJson[requestPollField] ?.jsonObject ?: buildJsonObject { } asJson[requestPollField] ?.jsonObject ?: buildJsonObject { }
) )
) )
asJson is JsonObject && asJson[requestUserField] != null -> RequestUserKeyboardButton(
asJson[textField]!!.jsonPrimitive.content,
nonstrictJsonFormat.decodeFromJsonElement(
KeyboardButtonRequestUser.serializer(),
asJson[requestUserField] ?.jsonObject ?: buildJsonObject { }
)
)
asJson is JsonObject && asJson[requestChatField] != null -> RequestChatKeyboardButton(
asJson[textField]!!.jsonPrimitive.content,
nonstrictJsonFormat.decodeFromJsonElement(
KeyboardButtonRequestChat.serializer(),
asJson[requestChatField] ?.jsonObject ?: buildJsonObject { }
)
)
else -> UnknownKeyboardButton( else -> UnknownKeyboardButton(
when (asJson) { when (asJson) {
is JsonObject -> asJson[textField]!!.jsonPrimitive.content is JsonObject -> asJson[textField]!!.jsonPrimitive.content
@@ -142,6 +192,8 @@ object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
is WebAppKeyboardButton -> WebAppKeyboardButton.serializer().serialize(encoder, value) is WebAppKeyboardButton -> WebAppKeyboardButton.serializer().serialize(encoder, value)
is RequestPollKeyboardButton -> RequestPollKeyboardButton.serializer().serialize(encoder, value) is RequestPollKeyboardButton -> RequestPollKeyboardButton.serializer().serialize(encoder, value)
is SimpleKeyboardButton -> encoder.encodeString(value.text) is SimpleKeyboardButton -> encoder.encodeString(value.text)
is RequestUserKeyboardButton -> RequestUserKeyboardButton.serializer().serialize(encoder, value)
is RequestChatKeyboardButton -> RequestChatKeyboardButton.serializer().serialize(encoder, value)
is UnknownKeyboardButton -> JsonElement.serializer().serialize(encoder, nonstrictJsonFormat.parseToJsonElement(value.raw)) is UnknownKeyboardButton -> JsonElement.serializer().serialize(encoder, nonstrictJsonFormat.parseToJsonElement(value.raw))
} }
} }

View File

@@ -0,0 +1,78 @@
package dev.inmo.tgbotapi.types.buttons
import dev.inmo.tgbotapi.types.botAdministratorRightsField
import dev.inmo.tgbotapi.types.botIsMemberField
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights
import dev.inmo.tgbotapi.types.chatHasUsernameField
import dev.inmo.tgbotapi.types.chatIsChannelField
import dev.inmo.tgbotapi.types.chatIsCreatedField
import dev.inmo.tgbotapi.types.chatIsForumField
import dev.inmo.tgbotapi.types.request.RequestId
import dev.inmo.tgbotapi.types.requestIdField
import dev.inmo.tgbotapi.types.userAdministratorRightsField
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
/**
* @see Channel
* @see Group
*/
@Serializable
data class KeyboardButtonRequestChat(
@SerialName(requestIdField)
val requestId: RequestId,
@SerialName(chatIsChannelField)
val isChannel: Boolean? = null,
@SerialName(chatIsForumField)
val isForum: Boolean? = null,
@SerialName(chatHasUsernameField)
val isPublic: Boolean? = null,
@SerialName(chatIsCreatedField)
val isOwnedBy: Boolean? = null,
@SerialName(userAdministratorRightsField)
val userRightsInChat: ChatAdministratorRights? = null,
@SerialName(botAdministratorRightsField)
val botRightsInChat: ChatAdministratorRights? = null,
@SerialName(botIsMemberField)
val botIsMember: Boolean? = null
) {
companion object {
fun Channel(
requestId: RequestId,
isPublic: Boolean? = null,
isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null,
botRightsInChat: ChatAdministratorRights? = null,
botIsMember: Boolean? = null
) = KeyboardButtonRequestChat(
requestId = requestId,
isChannel = true,
isForum = null,
isPublic = isPublic,
isOwnedBy = isOwnedBy,
userRightsInChat = userRightsInChat,
botRightsInChat = botRightsInChat,
botIsMember = botIsMember
)
fun Group(
requestId: RequestId,
isForum: Boolean? = null,
isPublic: Boolean? = null,
isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null,
botRightsInChat: ChatAdministratorRights? = null,
botIsMember: Boolean? = null
) = KeyboardButtonRequestChat(
requestId = requestId,
isChannel = false,
isForum = isForum,
isPublic = isPublic,
isOwnedBy = isOwnedBy,
userRightsInChat = userRightsInChat,
botRightsInChat = botRightsInChat,
botIsMember = botIsMember
)
}
}

View File

@@ -0,0 +1,91 @@
package dev.inmo.tgbotapi.types.buttons
import dev.inmo.tgbotapi.types.request.RequestId
import dev.inmo.tgbotapi.types.requestIdField
import dev.inmo.tgbotapi.types.userIsBotField
import dev.inmo.tgbotapi.types.userIsPremiumField
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializable(KeyboardButtonRequestUser.Companion::class)
@ClassCastsIncluded
sealed interface KeyboardButtonRequestUser {
val requestId: RequestId
val isBot: Boolean?
@Serializable
data class Any(
@SerialName(requestIdField)
override val requestId: RequestId
) : KeyboardButtonRequestUser {
@SerialName(userIsBotField)
@EncodeDefault
override val isBot: Boolean? = null
}
@Serializable
data class Common(
@SerialName(requestIdField)
override val requestId: RequestId,
@SerialName(userIsPremiumField)
val isPremium: Boolean? = null
) : KeyboardButtonRequestUser {
@SerialName(userIsBotField)
@EncodeDefault
override val isBot: Boolean = false
}
@Serializable
data class Bot(
@SerialName(requestIdField)
override val requestId: RequestId
) : KeyboardButtonRequestUser {
@SerialName(userIsBotField)
@EncodeDefault
override val isBot: Boolean = true
}
@Serializer(KeyboardButtonRequestUser::class)
companion object : KSerializer<KeyboardButtonRequestUser> {
@Serializable
private data class Surrogate(
@SerialName(requestIdField)
val requestId: RequestId,
@SerialName(userIsBotField)
val userIsBot: Boolean? = null,
@SerialName(userIsPremiumField)
val userIsPremium: Boolean? = null
)
private val realSerializer = Surrogate.serializer()
override val descriptor: SerialDescriptor = realSerializer.descriptor
override fun deserialize(decoder: Decoder): KeyboardButtonRequestUser {
val surrogate = realSerializer.deserialize(decoder)
return when (surrogate.userIsBot) {
true -> Bot(surrogate.requestId)
false -> Common(surrogate.requestId, surrogate.userIsPremium)
null -> Any(surrogate.requestId)
}
}
override fun serialize(encoder: Encoder, value: KeyboardButtonRequestUser) {
realSerializer.serialize(
encoder,
Surrogate(
value.requestId,
value.isBot,
(value as? Common) ?.isPremium
)
)
}
}
}

View File

@@ -13,7 +13,9 @@ data class ReplyKeyboardMarkup(
val oneTimeKeyboard: Boolean? = null, val oneTimeKeyboard: Boolean? = null,
@SerialName(inputFieldPlaceholderField) @SerialName(inputFieldPlaceholderField)
val inputFieldPlaceholder: String? = null, val inputFieldPlaceholder: String? = null,
val selective: Boolean? = null val selective: Boolean? = null,
@SerialName(isPersistentField)
val persistent: Boolean? = null
) : KeyboardMarkup { ) : KeyboardMarkup {
init { init {
if (inputFieldPlaceholder != null && inputFieldPlaceholder.length !in inputFieldPlaceholderLimit) { if (inputFieldPlaceholder != null && inputFieldPlaceholder.length !in inputFieldPlaceholderLimit) {

View File

@@ -2,6 +2,8 @@ package dev.inmo.tgbotapi.types.buttons.reply
import dev.inmo.tgbotapi.types.buttons.* import dev.inmo.tgbotapi.types.buttons.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.*
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights
import dev.inmo.tgbotapi.types.request.RequestId
import dev.inmo.tgbotapi.types.webapps.WebAppInfo import dev.inmo.tgbotapi.types.webapps.WebAppInfo
@@ -67,3 +69,161 @@ inline fun webAppReplyButton(
text: String, text: String,
url: String url: String
) = webAppReplyButton(text, WebAppInfo(url)) ) = webAppReplyButton(text, WebAppInfo(url))
/**
* Creates and put [RequestUserKeyboardButton]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestUserReplyButton(
text: String,
requestUser: KeyboardButtonRequestUser
) = RequestUserKeyboardButton(
text,
requestUser
)
/**
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUser.Bot]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestBotReplyButton(
text: String,
requestId: RequestId
) = requestUserReplyButton(
text,
KeyboardButtonRequestUser.Bot(requestId)
)
/**
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUser.Common]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestUserReplyButton(
text: String,
requestId: RequestId,
premiumUser: Boolean? = null
) = requestUserReplyButton(
text,
KeyboardButtonRequestUser.Common(requestId, premiumUser)
)
/**
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUser.Any]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestUserOrBotReplyButton(
text: String,
requestId: RequestId
) = requestUserReplyButton(
text,
KeyboardButtonRequestUser.Any(requestId)
)
/**
* Creates and put [RequestChatKeyboardButton]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestChatReplyButton(
text: String,
requestChat: KeyboardButtonRequestChat
) = RequestChatKeyboardButton(
text,
requestChat
)
/**
* Creates and put [RequestChatKeyboardButton] with [KeyboardButtonRequestChat]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestChatReplyButton(
text: String,
requestId: RequestId,
isChannel: Boolean? = null,
isForum: Boolean? = null,
isPublic: Boolean? = null,
isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null,
botRightsInChat: ChatAdministratorRights? = null,
botIsMember: Boolean = false
) = requestChatReplyButton(
text,
KeyboardButtonRequestChat(
requestId = requestId,
isChannel = isChannel,
isForum = isForum,
isPublic = isPublic,
isOwnedBy = isOwnedBy,
userRightsInChat = userRightsInChat,
botRightsInChat = botRightsInChat,
botIsMember = botIsMember
)
)
/**
* Creates and put [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Channel]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestChannelReplyButton(
text: String,
requestId: RequestId,
isPublic: Boolean? = null,
isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null,
botRightsInChat: ChatAdministratorRights? = null,
botIsMember: Boolean = false
) = requestChatReplyButton(
text,
KeyboardButtonRequestChat.Channel(
requestId = requestId,
isPublic = isPublic,
isOwnedBy = isOwnedBy,
userRightsInChat = userRightsInChat,
botRightsInChat = botRightsInChat,
botIsMember = botIsMember
)
)
/**
* Creates and put [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Group]
*
* @see replyKeyboard
* @see ReplyKeyboardBuilder.row
*/
inline fun requestChannelReplyButton(
text: String,
requestId: RequestId,
isForum: Boolean? = null,
isPublic: Boolean? = null,
isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null,
botRightsInChat: ChatAdministratorRights? = null,
botIsMember: Boolean? = null
) = requestChatReplyButton(
text,
KeyboardButtonRequestChat.Group(
requestId = requestId,
isForum = isForum,
isPublic = isPublic,
isOwnedBy = isOwnedBy,
userRightsInChat = userRightsInChat,
botRightsInChat = botRightsInChat,
botIsMember = botIsMember
)
)

View File

@@ -15,6 +15,8 @@ data class ChatJoinRequest(
val chat: PublicChat, val chat: PublicChat,
@SerialName(fromField) @SerialName(fromField)
override val from: User, override val from: User,
@SerialName(userChatIdField)
val userChatId: UserId,
@SerialName(dateField) @SerialName(dateField)
val date: TelegramDate, val date: TelegramDate,
@SerialName(inviteLinkField) @SerialName(inviteLinkField)

View File

@@ -1,32 +1,259 @@
package dev.inmo.tgbotapi.types.chat package dev.inmo.tgbotapi.types.chat
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializable /**
data class ChatPermissions( * Represents any type with common permissions list
@SerialName(canSendMessagesField) *
val canSendMessages: Boolean = false, * !!WARNING!! Default serializer of this interface is using [Granular] as surrogate and in fact serialized
@SerialName(canSendMediaMessagesField) * and deserialized as [Granular]. In case you wish some custom behaviour you must implement your own
val canSendMediaMessages: Boolean = false, * [KSerializer] or pass another serializer
@SerialName(canSendPollsField) */
val canSendPolls: Boolean = false, @Serializable(ChatPermissions.Companion::class)
@SerialName(canSendOtherMessagesField) interface ChatPermissions {
val canSendOtherMessages: Boolean = false, val canSendMessages: Boolean?
@SerialName(canAddWebPagePreviewsField) val canSendAudios: Boolean?
val canAddWebPagePreviews: Boolean = false, val canSendDocuments: Boolean?
@SerialName(canChangeInfoField) val canSendPhotos: Boolean?
val canChangeInfo: Boolean = false, val canSendVideos: Boolean?
@SerialName(canInviteUsersField) val canSendVideoNotes: Boolean?
val canInviteUsers: Boolean = false, val canSendVoiceNotes: Boolean?
@SerialName(canPinMessagesField) val canSendPolls: Boolean?
val canPinMessages: Boolean = false val canSendOtherMessages: Boolean?
) val canAddWebPagePreviews: Boolean?
val canChangeInfo: Boolean?
val canInviteUsers: Boolean?
val canPinMessages: Boolean?
@Transient
val isGranular
get() = canSendAudios != null ||
canSendDocuments != null ||
canSendVideoNotes != null ||
canSendPhotos != null ||
canSendVideos != null ||
canSendVoiceNotes != null
val canSendStickers: Boolean?
get() = canSendOtherMessages
val canSendGifs: Boolean?
get() = canSendStickers
@Serializable
data class Granular(
@SerialName(canSendMessagesField)
override val canSendMessages: Boolean? = null,
@SerialName(canSendAudiosField)
override val canSendAudios: Boolean? = null,
@SerialName(canSendDocumentsField)
override val canSendDocuments: Boolean? = null,
@SerialName(canSendPhotosField)
override val canSendPhotos: Boolean? = null,
@SerialName(canSendVideosField)
override val canSendVideos: Boolean? = null,
@SerialName(canSendVideoNotesField)
override val canSendVideoNotes: Boolean? = null,
@SerialName(canSendVoiceNotesField)
override val canSendVoiceNotes: Boolean? = null,
@SerialName(canSendPollsField)
override val canSendPolls: Boolean? = null,
@SerialName(canSendOtherMessagesField)
override val canSendOtherMessages: Boolean? = null,
@SerialName(canAddWebPagePreviewsField)
override val canAddWebPagePreviews: Boolean? = null,
@SerialName(canChangeInfoField)
override val canChangeInfo: Boolean? = null,
@SerialName(canInviteUsersField)
override val canInviteUsers: Boolean? = null,
@SerialName(canPinMessagesField)
override val canPinMessages: Boolean? = null
) : ChatPermissions {
@Transient
override val isGranular: Boolean
get() = true
}
@Serializable
data class Common(
@SerialName(canSendPollsField)
override val canSendPolls: Boolean? = null,
@SerialName(canSendOtherMessagesField)
override val canSendOtherMessages: Boolean? = null,
@SerialName(canAddWebPagePreviewsField)
override val canAddWebPagePreviews: Boolean? = null,
@SerialName(canChangeInfoField)
override val canChangeInfo: Boolean? = null,
@SerialName(canInviteUsersField)
override val canInviteUsers: Boolean? = null,
@SerialName(canPinMessagesField)
override val canPinMessages: Boolean? = null
) : ChatPermissions {
@Transient
override val isGranular: Boolean
get() = false
@Transient
override val canSendMessages: Boolean? = canSendOtherMessages ?.let {
it && (canAddWebPagePreviews ?: return@let null)
}
@Transient
override val canSendAudios: Boolean?
get() = canSendMessages
@Transient
override val canSendDocuments: Boolean?
get() = canSendMessages
@Transient
override val canSendPhotos: Boolean?
get() = canSendMessages
@Transient
override val canSendVideos: Boolean?
get() = canSendMessages
@Transient
override val canSendVideoNotes: Boolean?
get() = canSendMessages
@Transient
override val canSendVoiceNotes: Boolean?
get() = canSendMessages
}
companion object : KSerializer<ChatPermissions> {
operator fun invoke(
canSendMessages: Boolean? = null,
canSendAudios: Boolean? = null,
canSendDocuments: Boolean? = null,
canSendPhotos: Boolean? = null,
canSendVideos: Boolean? = null,
canSendVideoNotes: Boolean? = null,
canSendVoiceNotes: Boolean? = null,
canSendPolls: Boolean? = null,
canSendOtherMessages: Boolean? = null,
canAddWebPagePreviews: Boolean? = null,
canChangeInfo: Boolean? = null,
canInviteUsers: Boolean? = null,
canPinMessages: Boolean? = null
) = Granular(
canSendMessages = canSendMessages,
canSendAudios = canSendAudios,
canSendDocuments = canSendDocuments,
canSendPhotos = canSendPhotos,
canSendVideos = canSendVideos,
canSendVideoNotes = canSendVideoNotes,
canSendVoiceNotes = canSendVoiceNotes,
canSendPolls = canSendPolls,
canSendOtherMessages = canSendOtherMessages,
canAddWebPagePreviews = canAddWebPagePreviews,
canChangeInfo = canChangeInfo,
canInviteUsers = canInviteUsers,
canPinMessages = canPinMessages
)
private val realSerializer = Granular.serializer()
private val commonSerializer = Common.serializer()
override val descriptor: SerialDescriptor
get() = realSerializer.descriptor
override fun deserialize(decoder: Decoder): ChatPermissions {
return realSerializer.deserialize(decoder)
}
override fun serialize(encoder: Encoder, value: ChatPermissions) {
realSerializer.serialize(
encoder,
(value as? Granular) ?: value.run {
Granular(
canSendMessages = canSendMessages,
canSendAudios = canSendAudios,
canSendDocuments = canSendDocuments,
canSendPhotos = canSendPhotos,
canSendVideos = canSendVideos,
canSendVideoNotes = canSendVideoNotes,
canSendVoiceNotes = canSendVoiceNotes,
canSendPolls = canSendPolls,
canSendOtherMessages = canSendOtherMessages,
canAddWebPagePreviews = canAddWebPagePreviews,
canChangeInfo = canChangeInfo,
canInviteUsers = canInviteUsers,
canPinMessages = canPinMessages
)
}
)
}
}
/**
* Copying current instance as [ChatPermissions], but realizations of this interface may differently override this
* method
*/
fun copyGranular(
canSendMessages: Boolean? = this.canSendMessages,
canSendAudios: Boolean? = this.canSendAudios,
canSendDocuments: Boolean? = this.canSendDocuments,
canSendPhotos: Boolean? = this.canSendPhotos,
canSendVideos: Boolean? = this.canSendVideos,
canSendVideoNotes: Boolean? = this.canSendVideoNotes,
canSendVoiceNotes: Boolean? = this.canSendVoiceNotes,
canSendPolls: Boolean? = this.canSendPolls,
canSendOtherMessages: Boolean? = this.canSendOtherMessages,
canAddWebPagePreviews: Boolean? = this.canAddWebPagePreviews,
canChangeInfo: Boolean? = this.canChangeInfo,
canInviteUsers: Boolean? = this.canInviteUsers,
canPinMessages: Boolean? = this.canPinMessages
): ChatPermissions = ChatPermissions(
canSendMessages = canSendMessages,
canSendAudios = canSendAudios,
canSendDocuments = canSendDocuments,
canSendPhotos = canSendPhotos,
canSendVideos = canSendVideos,
canSendVideoNotes = canSendVideoNotes,
canSendVoiceNotes = canSendVoiceNotes,
canSendPolls = canSendPolls,
canSendOtherMessages = canSendOtherMessages,
canAddWebPagePreviews = canAddWebPagePreviews,
canChangeInfo = canChangeInfo,
canInviteUsers = canInviteUsers,
canPinMessages = canPinMessages
)
/**
* Copying current instance as [ChatPermissions], but realizations of this interface may differently override this
* method
*/
fun copyCommon(
canSendPolls: Boolean? = this.canSendPolls,
canSendOtherMessages: Boolean? = this.canSendOtherMessages,
canAddWebPagePreviews: Boolean? = this.canAddWebPagePreviews,
canChangeInfo: Boolean? = this.canChangeInfo,
canInviteUsers: Boolean? = this.canInviteUsers,
canPinMessages: Boolean? = this.canPinMessages
): ChatPermissions = ChatPermissions(
canSendMessages = null,
canSendAudios = null,
canSendDocuments = null,
canSendPhotos = null,
canSendVideos = null,
canSendVideoNotes = null,
canSendVoiceNotes = null,
canSendPolls = canSendPolls,
canSendOtherMessages = canSendOtherMessages,
canAddWebPagePreviews = canAddWebPagePreviews,
canChangeInfo = canChangeInfo,
canInviteUsers = canInviteUsers,
canPinMessages = canPinMessages
)
}
val LeftRestrictionsChatPermissions = ChatPermissions( val LeftRestrictionsChatPermissions = ChatPermissions(
canSendMessages = true, canSendMessages = true,
canSendMediaMessages = true, canSendAudios = true,
canSendDocuments = true,
canSendPhotos = true,
canSendVideos = true,
canSendVideoNotes = true,
canSendVoiceNotes = true,
canSendPolls = true, canSendPolls = true,
canSendOtherMessages = true, canSendOtherMessages = true,
canAddWebPagePreviews = true, canAddWebPagePreviews = true,
@@ -37,7 +264,12 @@ val LeftRestrictionsChatPermissions = ChatPermissions(
val RestrictionsChatPermissions = ChatPermissions( val RestrictionsChatPermissions = ChatPermissions(
canSendMessages = false, canSendMessages = false,
canSendMediaMessages = false, canSendAudios = false,
canSendDocuments = false,
canSendPhotos = false,
canSendVideos = false,
canSendVideoNotes = false,
canSendVoiceNotes = false,
canSendPolls = false, canSendPolls = false,
canSendOtherMessages = false, canSendOtherMessages = false,
canAddWebPagePreviews = false, canAddWebPagePreviews = false,

View File

@@ -27,7 +27,9 @@ data class ExtendedChannelChatImpl(
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
override val pinnedMessage: Message? = null, override val pinnedMessage: Message? = null,
@SerialName(linkedChatIdField) @SerialName(linkedChatIdField)
override val linkedGroupChatId: IdChatIdentifier? = null override val linkedGroupChatId: IdChatIdentifier? = null,
@SerialName(hasHiddenMembersField)
override val membersHidden: Boolean = false
) : ExtendedChannelChat ) : ExtendedChannelChat
@Serializable @Serializable
@@ -46,13 +48,15 @@ data class ExtendedGroupChatImpl(
override val inviteLink: String? = null, override val inviteLink: String? = null,
@SerialName(pinnedMessageField) @SerialName(pinnedMessageField)
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
override val pinnedMessage: Message? = null override val pinnedMessage: Message? = null,
@SerialName(hasHiddenMembersField)
override val membersHidden: Boolean = false
) : ExtendedGroupChat ) : ExtendedGroupChat
@Serializable @Serializable
data class ExtendedPrivateChatImpl( data class ExtendedPrivateChatImpl(
@SerialName(idField) @SerialName(idField)
override val id: IdChatIdentifier, override val id: UserId,
@SerialName(photoField) @SerialName(photoField)
override val chatPhoto: ChatPhoto? = null, override val chatPhoto: ChatPhoto? = null,
@SerialName(usernameField) @SerialName(usernameField)
@@ -109,7 +113,11 @@ data class ExtendedSupergroupChatImpl(
@SerialName(joinToSendMessagesField) @SerialName(joinToSendMessagesField)
override val requiresJoinForMessaging: Boolean = false, override val requiresJoinForMessaging: Boolean = false,
@SerialName(joinByRequestField) @SerialName(joinByRequestField)
override val requireAdminApproveToJoin: Boolean = false override val requireAdminApproveToJoin: Boolean = false,
@SerialName(hasAggressiveAntiSpamEnabledField)
override val isAggressiveAntiSpamEnabled: Boolean = false,
@SerialName(hasHiddenMembersField)
override val membersHidden: Boolean = false
) : ExtendedSupergroupChat ) : ExtendedSupergroupChat
@Serializable @Serializable
@@ -146,7 +154,11 @@ data class ExtendedForumChatImpl(
@SerialName(joinToSendMessagesField) @SerialName(joinToSendMessagesField)
override val requiresJoinForMessaging: Boolean = false, override val requiresJoinForMessaging: Boolean = false,
@SerialName(joinByRequestField) @SerialName(joinByRequestField)
override val requireAdminApproveToJoin: Boolean = false override val requireAdminApproveToJoin: Boolean = false,
@SerialName(hasAggressiveAntiSpamEnabledField)
override val isAggressiveAntiSpamEnabled: Boolean = false,
@SerialName(hasHiddenMembersField)
override val membersHidden: Boolean = false
) : ExtendedForumChat ) : ExtendedForumChat
@Serializable @Serializable

View File

@@ -31,6 +31,7 @@ sealed interface ExtendedPublicChat : ExtendedChat, PublicChat {
val inviteLink: String? val inviteLink: String?
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
val pinnedMessage: Message? val pinnedMessage: Message?
val membersHidden: Boolean
} }
@Serializable(ExtendedChatSerializer::class) @Serializable(ExtendedChatSerializer::class)
@@ -50,6 +51,11 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat, Ext
* This field represents field "join_by_request" from API * This field represents field "join_by_request" from API
*/ */
val requireAdminApproveToJoin: Boolean val requireAdminApproveToJoin: Boolean
/**
* This field represents field "has_aggressive_anti_spam_enabled" from API
*/
val isAggressiveAntiSpamEnabled: Boolean
} }
@Serializable(ExtendedChatSerializer::class) @Serializable(ExtendedChatSerializer::class)

View File

@@ -18,7 +18,7 @@ data class GroupChatImpl(
@Serializable @Serializable
data class PrivateChatImpl( data class PrivateChatImpl(
@SerialName(idField) @SerialName(idField)
override val id: IdChatIdentifier, override val id: UserId,
@SerialName(usernameField) @SerialName(usernameField)
override val username: Username? = null, override val username: Username? = null,
@SerialName(firstNameField) @SerialName(firstNameField)

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.chat.member package dev.inmo.tgbotapi.types.chat.member
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.ChatPermissions
import dev.inmo.tgbotapi.types.chat.User import dev.inmo.tgbotapi.types.chat.User
import kotlinx.serialization.* import kotlinx.serialization.*
@@ -13,15 +14,25 @@ data class RestrictedChatMember(
@SerialName(isMemberField) @SerialName(isMemberField)
val isMember: Boolean = false, val isMember: Boolean = false,
@SerialName(canSendMessagesField) @SerialName(canSendMessagesField)
val canSendMessages: Boolean = false, override val canSendMessages: Boolean = false,
@SerialName(canSendMediaMessagesField) @SerialName(canSendAudiosField)
val canSendMediaMessages: Boolean = false, override val canSendAudios: Boolean = false,
@SerialName(canSendDocumentsField)
override val canSendDocuments: Boolean = false,
@SerialName(canSendPhotosField)
override val canSendPhotos: Boolean = false,
@SerialName(canSendVideosField)
override val canSendVideos: Boolean = false,
@SerialName(canSendVideoNotesField)
override val canSendVideoNotes: Boolean = false,
@SerialName(canSendVoiceNotesField)
override val canSendVoiceNotes: Boolean = false,
@SerialName(canSendPollsField) @SerialName(canSendPollsField)
val canSendPolls: Boolean = false, override val canSendPolls: Boolean = false,
@SerialName(canSendOtherMessagesField) @SerialName(canSendOtherMessagesField)
val canSendOtherMessages: Boolean = false, override val canSendOtherMessages: Boolean = false,
@SerialName(canAddWebPagePreviewsField) @SerialName(canAddWebPagePreviewsField)
val canAddWebpagePreviews: Boolean = false, override val canAddWebPagePreviews: Boolean = false,
@SerialName(canChangeInfoField) @SerialName(canChangeInfoField)
override val canChangeInfo: Boolean = false, override val canChangeInfo: Boolean = false,
@SerialName(canInviteUsersField) @SerialName(canInviteUsersField)
@@ -30,7 +41,7 @@ data class RestrictedChatMember(
override val canPinMessages: Boolean = false, override val canPinMessages: Boolean = false,
@SerialName(canManageTopicsField) @SerialName(canManageTopicsField)
override val canManageTopics: Boolean = false override val canManageTopics: Boolean = false
) : BannedChatMember, SpecialRightsChatMember { ) : BannedChatMember, SpecialRightsChatMember, ChatPermissions {
@SerialName(statusField) @SerialName(statusField)
@Required @Required
private val type: String = "restricted" private val type: String = "restricted"

View File

@@ -42,6 +42,7 @@ sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile {
get() = false get() = false
} }
@OptIn(RiskFeature::class)
object StickerSerializer : KSerializer<Sticker> { object StickerSerializer : KSerializer<Sticker> {
override val descriptor: SerialDescriptor = StickerSurrogate.serializer().descriptor override val descriptor: SerialDescriptor = StickerSurrogate.serializer().descriptor

View File

@@ -34,11 +34,13 @@ data class VideoFile(
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun VideoFile.toTelegramMediaVideo( inline fun VideoFile.toTelegramMediaVideo(
text: String? = null, text: String? = null,
parseMode: ParseMode? = null parseMode: ParseMode? = null,
spoilered: Boolean = false
) = TelegramMediaVideo( ) = TelegramMediaVideo(
fileId, fileId,
text, text,
parseMode, parseMode,
spoilered,
width, width,
height, height,
duration, duration,
@@ -47,10 +49,12 @@ inline fun VideoFile.toTelegramMediaVideo(
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun VideoFile.toTelegramMediaVideo( inline fun VideoFile.toTelegramMediaVideo(
textSources: TextSourcesList textSources: TextSourcesList,
spoilered: Boolean = false
) = TelegramMediaVideo( ) = TelegramMediaVideo(
fileId, fileId,
textSources, textSources,
spoilered,
width, width,
height, height,
duration, duration,

View File

@@ -20,4 +20,4 @@ sealed interface AudioMediaGroupMemberTelegramMedia: MediaGroupMemberTelegramMed
sealed interface DocumentMediaGroupMemberTelegramMedia: MediaGroupMemberTelegramMedia sealed interface DocumentMediaGroupMemberTelegramMedia: MediaGroupMemberTelegramMedia
@Serializable(MediaGroupMemberTelegramMediaSerializer::class) @Serializable(MediaGroupMemberTelegramMediaSerializer::class)
sealed interface VisualMediaGroupMemberTelegramMedia : MediaGroupMemberTelegramMedia sealed interface VisualMediaGroupMemberTelegramMedia : MediaGroupMemberTelegramMedia, SpoilerableTelegramMedia

View File

@@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.types.media
import dev.inmo.tgbotapi.abstracts.SpoilerableData
sealed interface SpoilerableTelegramMedia : TelegramMedia, SpoilerableData

View File

@@ -18,15 +18,17 @@ fun TelegramMediaAnimation(
file: InputFile, file: InputFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
duration: Long? = null, duration: Long? = null,
thumb: InputFile? = null thumb: InputFile? = null
) = TelegramMediaAnimation(file, text, parseMode, null, width, height, duration, thumb) ) = TelegramMediaAnimation(file, text, parseMode, null, spoilered, width, height, duration, thumb)
fun TelegramMediaAnimation( fun TelegramMediaAnimation(
file: InputFile, file: InputFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
duration: Long? = null, duration: Long? = null,
@@ -36,6 +38,7 @@ fun TelegramMediaAnimation(
entities.makeString(), entities.makeString(),
null, null,
entities.toRawMessageEntities(), entities.toRawMessageEntities(),
spoilered,
width, width,
height, height,
duration, duration,
@@ -51,11 +54,13 @@ data class TelegramMediaAnimation internal constructor(
override val parseMode: ParseMode? = null, override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField) @SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null, private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(hasSpoilerField)
override val spoilered: Boolean = false,
override val width: Int? = null, override val width: Int? = null,
override val height: Int? = null, override val height: Int? = null,
override val duration: Long? = null, override val duration: Long? = null,
override val thumb: InputFile? = null override val thumb: InputFile? = null
) : TelegramMedia, SizedTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia, TextedOutput { ) : TelegramMedia, SizedTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia, TextedOutput, SpoilerableTelegramMedia {
override val type: String = "animation" override val type: String = "animation"
override val textSources: TextSourcesList? by lazy { override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)

View File

@@ -18,13 +18,15 @@ internal const val photoTelegramMediaType = "photo"
fun TelegramMediaPhoto( fun TelegramMediaPhoto(
file: InputFile, file: InputFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null parseMode: ParseMode? = null,
) = TelegramMediaPhoto(file, text, parseMode, null) spoilered: Boolean = false
) = TelegramMediaPhoto(file, text, parseMode, null, spoilered)
fun TelegramMediaPhoto( fun TelegramMediaPhoto(
file: InputFile, file: InputFile,
entities: TextSourcesList entities: TextSourcesList,
) = TelegramMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities()) spoilered: Boolean = false
) = TelegramMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities(), spoilered)
@Serializable @Serializable
data class TelegramMediaPhoto internal constructor( data class TelegramMediaPhoto internal constructor(
@@ -34,7 +36,9 @@ data class TelegramMediaPhoto internal constructor(
@SerialName(parseModeField) @SerialName(parseModeField)
override val parseMode: ParseMode? = null, override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField) @SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(hasSpoilerField)
override val spoilered: Boolean = false,
) : TelegramMedia, VisualMediaGroupMemberTelegramMedia { ) : TelegramMedia, VisualMediaGroupMemberTelegramMedia {
override val type: String = photoTelegramMediaType override val type: String = photoTelegramMediaType
override val textSources: TextSourcesList? by lazy { override val textSources: TextSourcesList? by lazy {
@@ -50,16 +54,20 @@ data class TelegramMediaPhoto internal constructor(
fun PhotoSize.toTelegramMediaPhoto( fun PhotoSize.toTelegramMediaPhoto(
text: String? = null, text: String? = null,
parseMode: ParseMode? = null parseMode: ParseMode? = null,
spoilered: Boolean = false
): TelegramMediaPhoto = TelegramMediaPhoto( ): TelegramMediaPhoto = TelegramMediaPhoto(
fileId, fileId,
text, text,
parseMode parseMode,
spoilered
) )
fun PhotoSize.toTelegramMediaPhoto( fun PhotoSize.toTelegramMediaPhoto(
textSources: TextSourcesList = emptyList() textSources: TextSourcesList = emptyList(),
spoilered: Boolean = false
): TelegramMediaPhoto = TelegramMediaPhoto( ): TelegramMediaPhoto = TelegramMediaPhoto(
fileId, fileId,
textSources textSources,
spoilered
) )

View File

@@ -18,20 +18,22 @@ fun TelegramMediaVideo(
file: InputFile, file: InputFile,
text: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
spoilered: Boolean = false,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
duration: Long? = null, duration: Long? = null,
thumb: InputFile? = null thumb: InputFile? = null
) = TelegramMediaVideo(file, text, parseMode, null, width, height, duration, thumb) ) = TelegramMediaVideo(file, text, parseMode, null, spoilered, width, height, duration, thumb)
fun TelegramMediaVideo( fun TelegramMediaVideo(
file: InputFile, file: InputFile,
entities: TextSourcesList, entities: TextSourcesList,
spoilered: Boolean = false,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
duration: Long? = null, duration: Long? = null,
thumb: InputFile? = null thumb: InputFile? = null
) = TelegramMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb) ) = TelegramMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), spoilered, width, height, duration, thumb)
@Serializable @Serializable
data class TelegramMediaVideo internal constructor ( data class TelegramMediaVideo internal constructor (
@@ -42,6 +44,8 @@ data class TelegramMediaVideo internal constructor (
override val parseMode: ParseMode? = null, override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField) @SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null, private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(hasSpoilerField)
override val spoilered: Boolean = false,
override val width: Int? = null, override val width: Int? = null,
override val height: Int? = null, override val height: Int? = null,
override val duration: Long? = null, override val duration: Long? = null,

View File

@@ -0,0 +1,18 @@
package dev.inmo.tgbotapi.types.message.ChatEvents.forum
import dev.inmo.tgbotapi.types.CustomEmojiId
import dev.inmo.tgbotapi.types.iconColorField
import dev.inmo.tgbotapi.types.iconCustomEmojiIdField
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ForumEvent
import dev.inmo.tgbotapi.types.nameField
import dev.inmo.tgbotapi.utils.RGBColor
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ForumTopicEdited(
@SerialName(nameField)
val name: String,
@SerialName(iconCustomEmojiIdField)
val iconEmojiId: CustomEmojiId? = null
) : ForumEvent

View File

@@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.message.ChatEvents.forum
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ForumEvent
import kotlinx.serialization.Serializable
@Serializable
object GeneralForumTopicHidden : ForumEvent

View File

@@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.message.ChatEvents.forum
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ForumEvent
import kotlinx.serialization.Serializable
@Serializable
object GeneralForumTopicUnhidden : ForumEvent

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