Skip to content

Commit 53a6547

Browse files
authored
Update methods and types for BOT API 9.6
- Enhanced Polls with media and suggested options. - Bots can create and managed other Bots on your behalf.
1 parent 364395b commit 53a6547

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1379
-340
lines changed

compiler/docs/compiler.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ def get_title_list(s: str) -> list:
309309
send_checklist
310310
edit_message_checklist
311311
mark_checklist_tasks_as_done
312+
add_poll_option
313+
delete_poll_option
312314
""",
313315
chats="""
314316
Chats
@@ -635,6 +637,8 @@ def get_title_list(s: str) -> list:
635637
UpgradedGift
636638
WebAppData
637639
MessageAutoDeleteTimerChanged
640+
PollOptionAdded
641+
PollOptionDeleted
638642
ChatBoostAdded
639643
ChatBackground
640644
Game
@@ -656,7 +660,7 @@ def get_title_list(s: str) -> list:
656660
ReactionTypeCustomEmoji
657661
ReactionTypePaid
658662
Thumbnail
659-
TranslatedText
663+
FormattedText
660664
StrippedThumbnail
661665
SponsoredMessage
662666
Sticker
@@ -668,6 +672,8 @@ def get_title_list(s: str) -> list:
668672
ChatOwnerChanged
669673
ChatHasProtectedContentToggled
670674
ChatHasProtectedContentDisableRequested
675+
ManagedBotCreated
676+
ManagedBotUpdated
671677
""",
672678
chat_topics="""
673679
Chat Forum Topics
@@ -706,6 +712,7 @@ def get_title_list(s: str) -> list:
706712
KeyboardButtonPollTypeQuiz
707713
KeyboardButtonRequestChat
708714
KeyboardButtonRequestUsers
715+
KeyboardButtonRequestManagedBot
709716
ReplyKeyboardMarkup
710717
ReplyKeyboardRemove
711718
LoginUrl

compiler/errors/source/400_BAD_REQUEST.tsv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ ADMIN_RANK_EMOJI_NOT_ALLOWED An admin rank cannot contain emojis.
99
ADMIN_RANK_INVALID The specified admin rank is invalid.
1010
ADMIN_RIGHTS_EMPTY The chatAdminRights constructor passed in keyboardButtonRequestPeer.peer_type.user_admin_rights has no rights set (i.e. flags is 0).
1111
AD_EXPIRED The ad has expired (too old or not found).
12+
AI_COMPOSE_TASK_MISSING The text composition style is missing.
1213
ALBUM_PHOTOS_TOO_MANY You have uploaded too many profile photos, delete some before retrying.
14+
ANSWER_X_MEDIA_TYPE_INVALID The option media type at index {value} is invalid.
15+
ANONYMOUS_OPEN_INVALID allow_adding_options is not supported for anonymous polls and quizzes.
1316
API_ID_INVALID API ID invalid.
1417
API_ID_PUBLISHED_FLOOD This API id was published somewhere, you can't use it now.
1518
ARTICLE_TITLE_EMPTY The title of the article is empty.
19+
ATTACH_MEDIA_EMPTY The attached media is empty.
20+
ATTACH_MEDIA_TYPE_INVALID The attached_media is invalid.
1621
AUDIO_CONTENT_URL_EMPTY The remote URL specified in the content field is empty.
1722
AUDIO_TITLE_EMPTY An empty audio title was provided.
1823
AUTH_BYTES_INVALID The provided authorization is invalid.
@@ -26,6 +31,7 @@ BALANCE_TOO_LOW The transaction cannot be completed because the current [Telegra
2631
BANK_CARD_NUMBER_INVALID The specified card number is invalid.
2732
BANNED_RIGHTS_INVALID You provided some invalid flags in the banned rights.
2833
BASE_PORT_LOC_INVALID The base port location is invalid
34+
BIRTHDAY_ALREADY The user has already entered a birthday.
2935
BIRTHDAY_INVALID An invalid age was specified, must be between 0 and 150 years.
3036
BOOSTS_EMPTY No boost slots were specified.
3137
BOOSTS_REQUIRED The specified channel must first be [boosted by its users](https://core.telegram.org/api/boost) in order to perform this action.
@@ -154,6 +160,7 @@ DATA_JSON_INVALID The provided JSON data is invalid.
154160
DATA_TOO_LONG Data too long.
155161
DATE_EMPTY Date empty.
156162
DC_ID_INVALID The provided DC ID is invalid.
163+
DELETE_ANSWER_FORBIDDEN You cannot delete the specified option in this poll.
157164
DH_G_A_INVALID g_a invalid.
158165
DOCUMENT_INVALID The specified document is invalid.
159166
EFFECT_ID_INVALID The specified effect ID is invalid.
@@ -262,6 +269,7 @@ INLINE_RESULT_EXPIRED The inline query expired.
262269
INPUT_CHATLIST_INVALID The specified folder is invalid.
263270
INPUT_CONSTRUCTOR_INVALID The specified TL constructor is invalid.
264271
INPUT_FETCH_ERROR An error occurred while parsing the provided TL constructor.
272+
INPUT_FETCH_ERROR_X An error occurred while parsing the provided TL {value} constructor.
265273
INPUT_FETCH_FAIL An error occurred while parsing the provided TL constructor.
266274
INPUT_FILE_INVALID The specified [InputFile](https://core.telegram.org/type/InputFile) is invalid.
267275
INPUT_FILTER_INVALID The specified filter is invalid.
@@ -294,6 +302,8 @@ LASTNAME_INVALID The last name is invalid.
294302
LIMIT_INVALID The provided limit is invalid.
295303
LINK_NOT_MODIFIED Discussion link not modified.
296304
LOCATION_INVALID The provided location is invalid.
305+
MANAGER_INVALID The provided bot manager is invalid. Bot Management Mode should be enabled for the bot in the @BotFather Mini App.
306+
MANAGER_PERMISSION_MISSING The bot manager permission is missing. Bot Management Mode should be enabled for the bot in the @BotFather Mini App.
297307
MAX_DATE_INVALID The specified maximum date is invalid.
298308
MAX_ID_INVALID The provided max ID is invalid.
299309
MAX_QTS_INVALID The specified max_qts is invalid.
@@ -487,6 +497,8 @@ SLOWMODE_MULTI_MSGS_DISABLED Slowmode is enabled, you cannot forward multiple me
487497
SLUG_INVALID The specified invoice slug is invalid.
488498
SMSJOB_ID_INVALID The specified job ID is invalid.
489499
SMS_CODE_CREATE_FAILED An error occurred while creating the SMS code.
500+
SOLUTION_MEDIA_EMPTY The solution_media is empty.
501+
SOLUTION_MEDIA_TYPE_INVALID The solution_media is invalid.
490502
SRP_A_INVALID The specified inputCheckPasswordSRP.A value is invalid.
491503
SRP_ID_INVALID Invalid SRP ID provided.
492504
SRP_PASSWORD_CHANGED Password has changed.
@@ -618,6 +630,7 @@ USERNAME_NOT_MODIFIED The username was not modified.
618630
USERNAME_NOT_OCCUPIED The provided username is not occupied.
619631
USERNAME_OCCUPIED The provided username is already occupied.
620632
USERNAME_PURCHASE_AVAILABLE The specified username can be purchased on https://fragment.com.
633+
USERNAME_SUFFIX_MISSING Bot username must end in `bot`.
621634
USERPIC_UPLOAD_REQUIRED You must have a profile picture to publish your geolocation.
622635
USERS_TOO_FEW Not enough users (to create a chat, for example).
623636
USERS_TOO_MUCH The maximum number of users has been exceeded (to create a chat, for example).

compiler/errors/source/406_NOT_ACCEPTABLE.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
id message
2+
AICOMPOSE_ERROR_OCCURED The composeTextWithAi method encountered an error.
23
ALLOW_PAYMENT_REQUIRED This peer only accepts [paid messages](https://core.telegram.org/api/paid-messages): this error is only emitted for older layers without paid messages support, so the client must be updated in order to use paid messages. .
34
API_GIFT_RESTRICTED_UPDATE_APP Please update the app to access the gift API.
45
AUTH_KEY_DUPLICATED Concurrent usage of the current session from multiple connections was detected, the current session was invalidated by the server for security reasons!

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ Breaking Changes in this Fork
3131
Changes in this Fork
3232
=====================
3333

34+
+------------------------+
35+
| Scheme layer used: 224 |
36+
+------------------------+
37+
38+
- Added the methods :meth:`~pyrogram.Client.add_poll_option` and :meth:`~pyrogram.Client.delete_poll_option`.
39+
- Added the field ``can_manage_bots`` to the class :obj:`~pyrogram.types.User`.
40+
- Added the class :obj:`~pyrogram.types.KeyboardButtonRequestManagedBot` and the field ``request_managed_bot`` to the class :obj:`~pyrogram.types.KeyboardButton`.
41+
- Added the class :obj:`~pyrogram.types.ManagedBotCreated` and the field ``managed_bot_created`` to the class :obj:`~pyrogram.types.Message`.
42+
- Added updates about the creation of managed bots and the change of their token, represented by the class :obj:`~pyrogram.handlers.ManagedBotUpdateHandler`.
43+
- Added support for quizzes with multiple correct answers.
44+
- Added the fields ``correct_option_ids``, ``allows_revoting``, ``description`` to the class :obj:`~pyrogram.types.Poll`.
45+
- Added the parameters ``correct_option_ids``, ``allows_multiple_answers``, ``allows_revoting``, ``shuffle_options``, ``allow_adding_options``, ``hide_results_until_closes``, ``description`` to the method :meth:`~pyrogram.Client.send_poll`.
46+
- Added the field ``option_persistent_ids`` to the class :obj:`~pyrogram.types.PollAnswer`.
47+
- Added the fields ``persistent_id``, ``addition_date``, ``added_by_user`` and ``added_by_chat`` to the class :obj:`~pyrogram.types.PollOption`.
48+
- Added the classes :obj:`~pyrogram.types.PollOptionAdded` and :obj:`~pyrogram.types.PollOptionDeleted` and the fields ``poll_option_added``, ``poll_option_deleted`` to the class :obj:`~pyrogram.types.Message`.
49+
- Added the field ``poll_option_id`` to the class :obj:`~pyrogram.types.ReplyParameters`, allowing to reply to a specific poll option.
50+
- Added the field ``reply_to_poll_option_id`` to the class :obj:`~pyrogram.types.Message`.
51+
- Added the method :meth:`~pyrogram.Client.send_message_draft` (contributed by @sudo-py-dev in `#231 <https://github.com/TelegramPlayground/pyrogram/pull/231>`__).
52+
- View `new and changed <https://telegramplayground.github.io/TG-APIs/TL/diff/tdlib.html?from=222&to=223>`__ `raw API methods <https://telegramplayground.github.io/TG-APIs/TL/diff/tdesktop.html?from=222&to=223>`__.
53+
3454
+------------------------+
3555
| Scheme layer used: 223 |
3656
+------------------------+

pyrogram/dispatcher.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
ChatJoinRequestHandler,
4242

4343

44+
ManagedBotUpdateHandler,
4445
DeletedMessagesHandler,
4546
UserStatusHandler,
4647
StoryHandler,
@@ -66,6 +67,7 @@
6667
UpdateBusinessBotCallbackQuery,
6768
UpdateBotBusinessConnect,
6869
UpdateBotPurchasedPaidMedia,
70+
UpdateManagedBot,
6971
)
7072

7173
log = logging.getLogger(__name__)
@@ -90,6 +92,7 @@ class Dispatcher:
9092
NEW_STORY_UPDATES = (UpdateStory,)
9193
BOT_BUSINESS_CONNECT_UPDATES = (UpdateBotBusinessConnect,)
9294
PURCHASED_PAID_MEDIA_UPDATES = (UpdateBotPurchasedPaidMedia,)
95+
MANAGED_BOT_UPDATES = (UpdateManagedBot,)
9396

9497
def __init__(self, client: "pyrogram.Client"):
9598
self.client = client
@@ -151,7 +154,7 @@ async def inline_query_parser(update, users, chats):
151154

152155
async def poll_parser(update, users, chats):
153156
return (
154-
pyrogram.types.Poll._parse_update(
157+
await pyrogram.types.Poll._parse_update(
155158
self.client, update, users, chats
156159
),
157160
PollHandler
@@ -233,6 +236,12 @@ async def purchased_paid_media_parser(update, users, chats):
233236
PurchasedPaidMediaHandler
234237
)
235238

239+
async def managed_bot_update_parser(update, users, chats):
240+
return (
241+
pyrogram.types.ManagedBotUpdated._parse(self.client, update, users),
242+
ManagedBotUpdateHandler
243+
)
244+
236245
self.update_parsers = {
237246
Dispatcher.NEW_MESSAGE_UPDATES: message_parser,
238247
Dispatcher.EDIT_MESSAGE_UPDATES: edited_message_parser,
@@ -252,6 +261,7 @@ async def purchased_paid_media_parser(update, users, chats):
252261
Dispatcher.NEW_STORY_UPDATES: story_parser,
253262
Dispatcher.BOT_BUSINESS_CONNECT_UPDATES: bot_business_connect_parser,
254263
Dispatcher.PURCHASED_PAID_MEDIA_UPDATES: purchased_paid_media_parser,
264+
Dispatcher.MANAGED_BOT_UPDATES: managed_bot_update_parser,
255265
}
256266

257267
self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple}

pyrogram/enums/message_entity_type.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,14 @@ class MessageEntityType(AutoName):
8989
DATE_TIME = raw.types.MessageEntityFormattedDate
9090
"for formatted date and time (see ``unix_time`` and ``date_time_format``)"
9191

92+
DIFF_TYPE_INSERT = raw.types.MessageEntityDiffInsert
93+
"Represents a change of a text: Addition of some text"
94+
95+
DIFF_TYPE_REPLACE = raw.types.MessageEntityDiffReplace
96+
"Represents a change of a text: Change of some text"
97+
98+
DIFF_TYPE_DELETE = raw.types.MessageEntityDiffDelete
99+
"Represents a change of a text: Removal of some text"
100+
92101
UNKNOWN = raw.types.MessageEntityUnknown
93102
"Unknown message entity type"

pyrogram/enums/message_service_type.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,14 @@ class MessageServiceType(AutoName):
168168
CHAT_HAS_PROTECTED_CONTENT_DISABLE_REQUESTED = auto()
169169
"Chat has_protected_content setting was requested to be disabled"
170170

171+
MANAGED_BOT_CREATED = auto()
172+
"A bot managed by another bot was created by the user"
173+
174+
POLL_OPTION_ADDED = auto()
175+
"An option was added to a poll"
176+
177+
POLL_OPTION_DELETED = auto()
178+
"A message with information about a deleted poll option"
179+
171180
UNKNOWN = auto()
172181
"This service message is unsupported by the current version of Pyrogram"

pyrogram/handlers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@
3535
from .purchased_paid_media_handler import PurchasedPaidMediaHandler
3636
from .shipping_query_handler import ShippingQueryHandler
3737
from .story_handler import StoryHandler
38+
from .managed_bot_update_handler import ManagedBotUpdateHandler
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Any, Callable
20+
21+
import pyrogram
22+
from pyrogram.filters import Filter
23+
from .handler import Handler
24+
25+
CallbackFunc: Callable = Callable[
26+
[
27+
"pyrogram.Client",
28+
pyrogram.types.ManagedBotUpdated
29+
],
30+
Any
31+
]
32+
33+
34+
class ManagedBotUpdateHandler(Handler):
35+
"""The ManagedBotUpdate handler class.
36+
Used to handle new managed bot creation updates.
37+
38+
It is intended to be used with :meth:`~pyrogram.Client.add_handler`.
39+
40+
For a nicer way to register this handler, have a look at the
41+
:meth:`~pyrogram.Client.on_managed_bot` decorator.
42+
43+
Parameters:
44+
callback (``Callable``):
45+
Pass a function that will be called when a new ManagedBotUpdated event arrives. It takes
46+
*(client, managed_bot)* as positional arguments (look at the section below for a detailed
47+
description).
48+
49+
filters (:obj:`Filters`):
50+
Pass one or more filters to allow only a subset of updates to be passed in your callback function.
51+
52+
Other parameters:
53+
client (:obj:`~pyrogram.Client`):
54+
The Client itself, useful when you want to call other API methods inside the handler.
55+
56+
managed_bot (:obj:`~pyrogram.types.ManagedBotUpdated`):
57+
A new bot was created to be managed by the bot or token of a bot was changed.
58+
59+
"""
60+
61+
def __init__(self, callback: CallbackFunc, filters: Filter = None):
62+
super().__init__(callback, filters)

pyrogram/methods/decorators/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from .on_pre_checkout_query import OnPreCheckoutQuery
3636
from .on_shipping_query import OnShippingQuery
3737
from .on_story import OnStory
38+
from .on_managed_bot import OnManagedBot
3839

3940

4041
class Decorators(
@@ -59,6 +60,7 @@ class Decorators(
5960
OnDisconnect,
6061
OnUserStatus,
6162
OnStory,
63+
OnManagedBot,
6264
OnRawUpdate,
6365
):
6466
pass

0 commit comments

Comments
 (0)