Skip to content

Commit b5f02e6

Browse files
Update API Scheme to Layer 205 (#187)
Co-authored-by: KurimuzonAkuma <[email protected]>
1 parent db7f55e commit b5f02e6

34 files changed

+1217
-78
lines changed

compiler/api/source/main_api.tl

Lines changed: 46 additions & 26 deletions
Large diffs are not rendered by default.

compiler/docs/compiler.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ def get_title_list(s: str) -> list:
229229
translate_message_text
230230
delete_chat_history
231231
send_screenshot_notification
232+
send_checklist
233+
edit_message_checklist
234+
mark_checklist_tasks_as_done
232235
""",
233236
chats="""
234237
Chats
@@ -494,6 +497,7 @@ def get_title_list(s: str) -> list:
494497
VideoChatEnded
495498
VideoChatParticipantsInvited
496499
PaidMessagePriceChanged
500+
DirectMessagePriceChanged
497501
PaidMessagesRefunded
498502
Dialog
499503
EmojiStatus
@@ -535,6 +539,12 @@ def get_title_list(s: str) -> list:
535539
InputPollOption
536540
Poll
537541
PollAnswer
542+
ChecklistTask
543+
Checklist
544+
InputChecklistTask
545+
InputChecklist
546+
ChecklistTasksDone
547+
ChecklistTasksAdded
538548
Location
539549
Venue
540550
Gift

compiler/errors/source/400_BAD_REQUEST.tsv

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ BOT_WEBVIEW_DISABLED A webview cannot be opened in the specified conditions: emi
5858
BROADCAST_ID_INVALID Broadcast ID invalid.
5959
BROADCAST_PUBLIC_VOTERS_FORBIDDEN You can't forward polls with public voters.
6060
BROADCAST_REQUIRED This method can only be called on a channel, please use stats.getMegagroupStats for supergroups.
61+
BUSINESS_BOT_MISSING The business bot is missing.
6162
BUSINESS_CONNECTION_INVALID The business connection is invalid.
6263
BUSINESS_CONNECTION_NOT_ALLOWED This business connection is not allowed.
6364
BUSINESS_PEER_INVALID Messages can't be set to the specified peer through the current [business connection](https://core.telegram.org/api/business#connected-bots).
@@ -89,6 +90,7 @@ CHANNEL_BANNED The channel is banned
8990
CHANNEL_FORUM_MISSING This supergroup is not a forum.
9091
CHANNEL_ID_INVALID The specified supergroup ID is invalid.
9192
CHANNEL_INVALID The provided channel is invalid.
93+
CHANNEL_MONOFORUM_UNSUPPORTED The provided channel is not supported.
9294
CHANNEL_PARICIPANT_MISSING The current user is not in the channel.
9395
CHANNEL_PRIVATE You haven't joined this channel/supergroup.
9496
CHANNEL_TOO_BIG This channel has too many participants (>1000) to be deleted.
@@ -210,6 +212,7 @@ FORUM_ENABLED You can't execute the specified action because the group is a [for
210212
FRESH_CHANGE_ADMINS_FORBIDDEN You were just elected admin, you can't add or modify other admins yet.
211213
FROM_MESSAGE_BOT_DISABLED Bots can't use fromMessage min constructors.
212214
FROM_PEER_INVALID The specified from_id is invalid.
215+
FROZEN_PARTICIPANT_MISSING The account is frozen and cannot access the chat participant.
213216
GAME_BOT_INVALID Bots can't send another bot's game.
214217
GENERAL_MODIFY_ICON_FORBIDDEN You can't modify the icon of the 'General' topic.
215218
GEO_POINT_INVALID Invalid geoposition provided.
@@ -302,6 +305,7 @@ MESSAGE_TOO_LONG The provided message is too long.
302305
MESSAGE_TOO_OLD The message is too old, the requested information is not available.
303306
METHOD_INVALID The specified method is invalid.
304307
MIN_DATE_INVALID The specified minimum date is invalid.
308+
MONOFORUM_FILTER_INVALID The specified filter is invalid.
305309
MSG_ID_INVALID Invalid message ID provided.
306310
MSG_TOO_OLD [`chat_read_mark_expire_period` seconds](https://core.telegram.org/api/config#chat-read-mark-expire-period) have passed since the message was sent, read receipts were deleted.
307311
MSG_WAIT_FAILED A waiting call returned an error.
@@ -374,6 +378,7 @@ POLL_OPTION_INVALID Invalid poll option provided.
374378
POLL_QUESTION_INVALID One of the poll questions is not acceptable.
375379
POLL_UNSUPPORTED This layer does not support polls in the invoked method
376380
POLL_VOTE_REQUIRED Cast a vote in the poll before calling this method
381+
PRECHECKOUT_FAILED precheckout failed
377382
PREMIUM_ACCOUNT_REQUIRED A premium account is required to execute this action.
378383
PRICING_CHAT_INVALID The pricing for the [subscription](https://core.telegram.org/api/subscriptions) is invalid, the maximum price is specified in the [`stars_subscription_amount_max` config key](https://core.telegram.org/api/config#stars-subscription-amount-max).
379384
PRIVACY_KEY_INVALID The privacy key is invalid.
@@ -407,6 +412,7 @@ REPLY_MARKUP_TOO_LONG The specified reply_markup is too long.
407412
REPLY_MESSAGES_TOO_MUCH Each shortcut can contain a maximum of [appConfig.`quick_reply_messages_limit`](https://core.telegram.org/api/config#quick-reply-messages-limit) messages, the limit was reached.
408413
REPLY_MESSAGE_ID_INVALID The specified reply-to message ID is invalid.
409414
REPLY_TO_INVALID The specified `reply_to` field is invalid.
415+
REPLY_TO_MONOFORUM_PEER_INVALID The specified `reply_to` field is invalid.
410416
REPLY_TO_USER_INVALID The replied-to user is invalid.
411417
REQUEST_TOKEN_INVALID The master DC did not accept the `request_token` from the CDN DC. Continue downloading the file from the master DC using upload.getFile.
412418
RESET_REQUEST_MISSING No password reset is in progress.
@@ -448,8 +454,13 @@ SMS_CODE_CREATE_FAILED An error occurred while creating the SMS code.
448454
SRP_A_INVALID The specified inputCheckPasswordSRP.A value is invalid.
449455
SRP_ID_INVALID Invalid SRP ID provided.
450456
SRP_PASSWORD_CHANGED Password has changed.
457+
STARGIFT_CONVERT_TOO_OLD This gift can no longer be converted into stars.
451458
STARGIFT_INVALID The passed [inputInvoiceStarGift](https://core.telegram.org/constructor/inputInvoiceStarGift) is invalid.
459+
STARGIFT_MESSAGE_INVALID The provided message for this gift is invalid.
452460
STARGIFT_NOT_FOUND The specified star gift was not found.
461+
STARGIFT_NOT_OWNER You cannot control this gift because it does not belong to you.
462+
STARGIFT_RESELL_NOT_ALLOWED You cannot buy this gift. Someone else may have already bought it.
463+
STARGIFT_RESELL_TOO_EARLY_X A wait of {value} seconds is required to resell this gift.
453464
STARGIFT_SLUG_INVALID The provided star gift slug is invalid.
454465
STARGIFT_USAGE_LIMITED The gift is sold out.
455466
STARREF_AWAITING_END The previous referral program was terminated less than 24 hours ago: further changes can be made after the date specified in userFull.starref_program.end_date.
@@ -458,6 +469,7 @@ STARREF_MONTHS_TOO_LOW The ``duration_months`` parameter must be between 0 and 3
458469
STARREF_PERMILLE_INVALID The specified commission_permille is invalid: the minimum and maximum values for this parameter are contained in the [starref_min_commission_permille](https://core.telegram.org/api/config#starref-min-commission-permille) and [starref_max_commission_permille](https://core.telegram.org/api/config#starref-max-commission-permille) client configuration parameters.
459470
STARREF_PERMILLE_TOO_LOW The specified commission_permille is too low: the minimum and maximum values for this parameter are contained in the [starref_min_commission_permille](https://core.telegram.org/api/config#starref-min-commission-permille) and [starref_max_commission_permille](https://core.telegram.org/api/config#starref-max-commission-permille) client configuration parameters.
460471
STARS_AMOUNT_INVALID The specified ``paid_stars`` amount is invalid.
472+
STARS_FORM_AMOUNT_MISMATCH stars form amount mismatch
461473
STARS_INVOICE_INVALID The specified Telegram Star invoice is invalid.
462474
STARS_PAYMENT_REQUIRED To import this chat invite link, you must first [pay for the associated Telegram Star subscription](https://core.telegram.org/api/subscriptions#channel-subscriptions).
463475
START_PARAM_EMPTY The start parameter is empty.
@@ -532,6 +544,8 @@ TTL_MEDIA_INVALID Invalid media Time To Live was provided.
532544
TTL_PERIOD_INVALID The specified TTL period is invalid.
533545
TYPES_EMPTY No top peer type was provided.
534546
TYPE_CONSTRUCTOR_INVALID The type constructor is invalid
547+
UNKNOWN_ERROR Unknown error.
548+
UNSUPPORTED This method is not supported.
535549
UNTIL_DATE_INVALID Invalid until date provided.
536550
URL_INVALID Invalid URL provided.
537551
USAGE_LIMIT_INVALID The specified usage limit is invalid.

compiler/errors/source/403_FORBIDDEN.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
id message
2+
ACCESS_DENIED You cannot perform this request.
23
ALLOW_PAYMENT_REQUIRED_X The user has enabled paid messages with {value} stars.
34
ANONYMOUS_REACTIONS_DISABLED Sorry, anonymous administrators cannot leave reactions or participate in polls.
45
BOT_ACCESS_FORBIDDEN You cannot access this bot.

compiler/errors/source/420_FLOOD.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ADDRESS_INVALID The specified geopoint address is invalid.
44
FLOOD_PREMIUM_WAIT_X Please wait {value} seconds before repeating the action, or purchase a [Telegram Premium subscription](https://core.telegram.org/api/premium) to remove this rate limit.
55
FLOOD_TEST_PHONE_WAIT_X A wait of {value} seconds is required in the test servers
66
FLOOD_WAIT_X Please wait {value} seconds before repeating the action.
7+
FROZEN_METHOD_INVALID The method cannot be used by frozen account. You can appeal via @SpamBot if you believe this was a mistake.
78
PREMIUM_SUB_ACTIVE_UNTIL_X You already have a premium subscription active until unixtime {value} .
89
SLOWMODE_WAIT_X Slowmode is enabled in this chat: wait {value} seconds before sending another message to this chat.
910
STORY_SEND_FLOOD_X A wait of {value} seconds is required to continue posting stories

compiler/errors/source/500_INTERNAL_SERVER_ERROR.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHAT_ID_GENERATE_FAILED Failure while generating the chat ID.
99
CHAT_INVALID Invalid chat.
1010
CHAT_OCCUPY_LOC_FAILED An internal error occurred while creating the chat
1111
CHAT_OCCUPY_USERNAME_FAILED Failure to occupy chat username due to Telegram having internal problems. Please try again later
12+
CHP_BAD_EVENT Telegram is having internal problems. Please try again later.
1213
CHP_CALL_FAIL Telegram is having internal problems. Please try again later
1314
ENCRYPTION_OCCUPY_ADMIN_FAILED Failed occupying memory for admin info due to Telegram having internal problems. Please try again later
1415
ENCRYPTION_OCCUPY_FAILED Internal server error while accepting secret chat

docs/source/releases/changes-in-this-fork.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,23 @@ Changes in this Fork
3232
=====================
3333

3434
+------------------------+
35-
| Scheme layer used: 203 |
36-
+------------------------+
37-
38-
- View `new and changed <https://telegramplayground.github.io/TG-APIs/TL/diff/tdlib.html?from=202&to=203>`__ `raw API methods <https://telegramplayground.github.io/TG-APIs/TL/diff/tdesktop.html?from=202&to=203>`__.
35+
| Scheme layer used: 205 |
36+
+------------------------+
37+
38+
- Added the :obj:`~pyrogram.types.ChecklistTask` representing a task in a checklist.
39+
- Added the :obj:`~pyrogram.types.Checklist` representing a checklist.
40+
- Added the :obj:`~pyrogram.types.InputChecklistTask` representing a task to add to a checklist.
41+
- Added the :obj:`~pyrogram.types.InputChecklist` representing a checklist to create.
42+
- Added the field ``checklist`` to the :obj:`~pyrogram.types.Message` and :obj:`~pyrogram.types.ExternalReplyInfo`, describing a checklist in a message.
43+
- Added the :obj:`~pyrogram.types.ChecklistTasksDone` and the field ``checklist_tasks_done`` to the :obj:`~pyrogram.types.Message`, describing a service message about status changes for tasks in a checklist (i.e., marked as done/not done).
44+
- Added the :obj:`~pyrogram.types.ChecklistTasksAdded` and the field ``checklist_tasks_added`` to the :obj:`~pyrogram.types.Message`, describing a service message about the addition of new tasks to a checklist.
45+
- Added the :meth:`~pyrogram.Client.send_checklist`, allowing bots to send a checklist on behalf of a business account.
46+
- Added the :meth:`~pyrogram.Client.edit_message_checklist`, allowing bots to edit a checklist on behalf of a business account.
47+
- Added the :obj:`~pyrogram.types.DirectMessagePriceChanged` and the field ``direct_message_price_changed`` to the :obj:`~pyrogram.types.Message`, describing a service message about a price change for direct messages sent to the channel chat.
48+
- `Fix conditions for recover_gaps <https://github.com/KurimuzonAkuma/pyrogram/commit/b59ae77>`__.
49+
- Added ``reply_parameters`` in :meth:`~pyrogram.Client.forward_messages`.
50+
- Increased the maximum number of options in a poll to 12.
51+
- View `new and changed <https://telegramplayground.github.io/TG-APIs/TL/diff/tdlib.html?from=202&to=205>`__ `raw API methods <https://telegramplayground.github.io/TG-APIs/TL/diff/tdesktop.html?from=202&to=205>`__.
3952

4053
+------------------------+
4154
| Scheme layer used: 202 |

pyrogram/client.py

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from io import StringIO, BytesIO
3333
from mimetypes import MimeTypes
3434
from pathlib import Path
35-
from typing import Union, Optional, Callable, AsyncGenerator
35+
from typing import AsyncGenerator, Callable, Optional, Tuple, Union
3636

3737
import pyrogram
3838
from pyrogram import __version__, __license__
@@ -53,7 +53,7 @@
5353
from pyrogram.session import Auth, Session
5454
from pyrogram.storage import Storage, FileStorage, MemoryStorage
5555
from pyrogram.types import User, TermsOfService
56-
from pyrogram.utils import ainput
56+
from pyrogram.utils import MIN_MONOFORUM_CHANNEL_ID, ainput
5757
from .connection import Connection
5858
from .connection.transport import TCP, TCPAbridged, TCPFull
5959
from .dispatcher import Dispatcher
@@ -711,18 +711,24 @@ async def handle_updates(self, updates):
711711
elif isinstance(updates, raw.types.UpdatesTooLong):
712712
log.info(updates)
713713

714-
async def recover_gaps(self) -> tuple[int, int]:
714+
async def recover_gaps(self) -> Tuple[int, int]:
715+
if self.skip_updates:
716+
log.info("Recover gaps disabled in client params. Skipping recovery")
717+
return (0, 0)
718+
715719
states = await self.storage.update_state()
716720

721+
if not states:
722+
log.info("No states found, skipping recovery")
723+
return (0, 0)
724+
717725
message_updates_counter = 0
718726
other_updates_counter = 0
719727

720-
if not states:
721-
log.info("No states found, skipping recovery.")
722-
return (message_updates_counter, other_updates_counter)
728+
log.info("Started gaps recovering...")
723729

724-
for state in states:
725-
id, local_pts, _, local_date, _ = state
730+
for local_state in states:
731+
id, local_pts, local_qts, local_date, local_seq = local_state
726732

727733
prev_pts = 0
728734

@@ -735,7 +741,7 @@ async def recover_gaps(self) -> tuple[int, int]:
735741
pts=local_pts,
736742
limit=10000,
737743
force=False
738-
) if id < 0 else
744+
) if id < 0 or id > MIN_MONOFORUM_CHANNEL_ID else
739745
raw.functions.updates.GetDifference(
740746
pts=local_pts,
741747
date=local_date,
@@ -746,29 +752,65 @@ async def recover_gaps(self) -> tuple[int, int]:
746752
break
747753

748754
if isinstance(diff, raw.types.updates.DifferenceEmpty):
755+
await self.storage.update_state(
756+
(
757+
id,
758+
local_pts,
759+
None,
760+
diff.date,
761+
diff.seq
762+
)
763+
)
749764
break
750765
elif isinstance(diff, raw.types.updates.DifferenceTooLong):
751-
break
766+
await self.storage.update_state(
767+
(
768+
id,
769+
diff.pts,
770+
None,
771+
local_date,
772+
local_seq
773+
)
774+
)
775+
continue
752776
elif isinstance(diff, raw.types.updates.Difference):
753777
local_pts = diff.state.pts
778+
local_date = diff.state.date
779+
local_seq = diff.state.seq
754780
elif isinstance(diff, raw.types.updates.DifferenceSlice):
755781
local_pts = diff.intermediate_state.pts
756782
local_date = diff.intermediate_state.date
783+
local_seq = diff.intermediate_state.seq
757784

758785
if prev_pts == local_pts:
759786
break
760787

761788
prev_pts = local_pts
762789
elif isinstance(diff, raw.types.updates.ChannelDifferenceEmpty):
790+
await self.storage.update_state(
791+
(
792+
id,
793+
diff.pts,
794+
None,
795+
local_date,
796+
local_seq
797+
)
798+
)
763799
break
764800
elif isinstance(diff, raw.types.updates.ChannelDifferenceTooLong):
765-
break
801+
await self.storage.update_state(
802+
(
803+
id,
804+
diff.dialog.pts,
805+
None,
806+
local_date,
807+
local_seq
808+
)
809+
)
810+
continue
766811
elif isinstance(diff, raw.types.updates.ChannelDifference):
767812
local_pts = diff.pts
768813

769-
if not diff:
770-
break
771-
772814
users = {i.id: i for i in diff.users}
773815
chats = {i.id: i for i in diff.chats}
774816

@@ -795,9 +837,17 @@ async def recover_gaps(self) -> tuple[int, int]:
795837
if isinstance(diff, (raw.types.updates.Difference, raw.types.updates.ChannelDifference)):
796838
break
797839

798-
await self.storage.update_state(id)
840+
await self.storage.update_state(
841+
(
842+
id,
843+
local_pts,
844+
None,
845+
local_date,
846+
local_seq
847+
)
848+
)
799849

800-
log.info("Recovered %s messages and %s updates.", message_updates_counter, other_updates_counter)
850+
log.info("Recovered %s messages and %s updates", message_updates_counter, other_updates_counter)
801851
return (message_updates_counter, other_updates_counter)
802852

803853
async def load_session(self):

pyrogram/enums/message_media_type.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,9 @@ class MessageMediaType(AutoName):
8383

8484
PAID_MEDIA = auto()
8585
"Paid Media"
86+
87+
CHECKLIST = auto()
88+
"Checklist"
89+
90+
UNKNOWN = auto()
91+
"This message media is unsupported by the current version of Pyrogram"

pyrogram/enums/message_service_type.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,14 @@ class MessageServiceType(AutoName):
150150
PAID_MESSAGES_REFUNDED = auto()
151151
"Refunded paid messages"
152152

153+
DIRECT_MESSAGE_PRICE_CHANGED = auto()
154+
"Direct message price"
155+
156+
CHECKLIST_TASKS_DONE = auto()
157+
"Checklist tasks done"
158+
159+
CHECKLIST_TASKS_ADDED = auto()
160+
"Checklist tasks added"
161+
153162
UNKNOWN = auto()
154163
"This service message is unsupported by the current version of Pyrogram"

0 commit comments

Comments
 (0)