Skip to content

Commit 783e11e

Browse files
feat: Bot API 10.0
1 parent b29885f commit 783e11e

36 files changed

Lines changed: 1482 additions & 77 deletions

compiler/docs/compiler.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def get_title_list(s: str) -> list:
266266
get_messages
267267
get_scheduled_messages
268268
get_stickers
269+
get_user_personal_chat_messages
269270
get_web_app_link_url
270271
get_web_app_url
271272
mark_checklist_tasks_as_done
@@ -328,7 +329,8 @@ def get_title_list(s: str) -> list:
328329
set_administrator_title
329330
set_chat_photo
330331
delete_chat_photo
331-
delete_chat_reactions_by_sender
332+
delete_message_reaction
333+
delete_all_message_reactions
332334
set_chat_title
333335
set_chat_description
334336
set_chat_direct_messages_group
@@ -512,8 +514,11 @@ def get_title_list(s: str) -> list:
512514
Bots
513515
get_inline_bot_results
514516
send_inline_bot_result
517+
get_managed_bot_access_settings
518+
set_managed_bot_access_settings
515519
send_invoice
516520
answer_callback_query
521+
answer_guest_query
517522
answer_inline_query
518523
request_callback_answer
519524
send_game
@@ -716,6 +721,7 @@ def get_title_list(s: str) -> list:
716721
MessageOriginUser
717722
MessageOrigin
718723
Photo
724+
LivePhoto
719725
PollOptionAdded
720726
PollOptionDeleted
721727
Thumbnail
@@ -864,6 +870,7 @@ def get_title_list(s: str) -> list:
864870
ReplyKeyboardMarkup
865871
KeyboardButton
866872
ReplyKeyboardRemove
873+
SentGuestMessage
867874
InlineKeyboardMarkup
868875
InlineKeyboardButton
869876
LoginUrl
@@ -896,6 +903,7 @@ def get_title_list(s: str) -> list:
896903
""",
897904
bot_commands="""
898905
Bot commands
906+
BotAccessSettings
899907
BotCommand
900908
BotCommandScope
901909
BotCommandScopeDefault
@@ -924,12 +932,18 @@ def get_title_list(s: str) -> list:
924932
InputMediaAnimation
925933
InputMediaAudio
926934
InputMediaDocument
935+
InputMediaLocation
936+
InputMediaVenue
927937
InputMediaPhoto
938+
InputMediaLivePhoto
928939
InputMediaVideo
929940
InputMediaSticker
930941
InputMessageContent
931942
InputPhoneContact
932943
InputPollOption
944+
InputPollMedia
945+
InputPollOptionMedia
946+
InputPollOption
933947
InputPrivacyRule
934948
InputPrivacyRuleAllowAll
935949
InputPrivacyRuleAllowBots

pyrogram/dispatcher.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
UpdateNewChannelMessage,
8181
UpdateNewMessage,
8282
UpdateNewScheduledMessage,
83+
UpdateBotGuestChatQuery,
8384
UpdateStory,
8485
UpdateUserStatus,
8586
)
@@ -88,7 +89,7 @@
8889

8990

9091
class Dispatcher:
91-
NEW_MESSAGE_UPDATES = (UpdateNewMessage, UpdateNewChannelMessage, UpdateNewScheduledMessage)
92+
NEW_MESSAGE_UPDATES = (UpdateNewMessage, UpdateNewChannelMessage, UpdateNewScheduledMessage, UpdateBotGuestChatQuery)
9293
EDIT_MESSAGE_UPDATES = (UpdateEditMessage, UpdateEditChannelMessage)
9394
DELETE_MESSAGES_UPDATES = (UpdateDeleteMessages, UpdateDeleteChannelMessages)
9495
CALLBACK_QUERY_UPDATES = (UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery, UpdateBusinessBotCallbackQuery)
@@ -121,8 +122,6 @@ def __init__(self, client: "pyrogram.Client"):
121122
self.groups = OrderedDict()
122123

123124
async def message_parser(update, users, chats):
124-
connection_id = getattr(update, "connection_id", None)
125-
126125
return (
127126
await pyrogram.types.Message._parse(
128127
self.client,
@@ -131,7 +130,7 @@ async def message_parser(update, users, chats):
131130
chats,
132131
is_scheduled=isinstance(update, UpdateNewScheduledMessage),
133132
replies=0 if getattr(update, "connection_id", None) else 1,
134-
business_connection_id=connection_id,
133+
business_connection_id=getattr(update, "connection_id", None),
135134
raw_reply_to_message=getattr(update, "reply_to_message", None)
136135
),
137136
MessageHandler

pyrogram/enums/message_media_type.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class MessageMediaType(AutoName):
3636
PHOTO = auto()
3737
"Photo media"
3838

39+
LIVE_PHOTO = auto()
40+
"Live photo media"
41+
3942
STICKER = auto()
4043
"Sticker media"
4144

pyrogram/filters.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818

1919
import inspect
2020
import re
21-
from typing import Callable, Union, List, Pattern, Optional
21+
from typing import Callable, List, Optional, Pattern, Union
2222

2323
import pyrogram
2424
from pyrogram import enums
2525
from pyrogram.types import (
26-
Message,
2726
CallbackQuery,
2827
ChosenInlineResult,
28+
InlineKeyboardMarkup,
2929
InlineQuery,
30+
Message,
3031
PreCheckoutQuery,
31-
InlineKeyboardMarkup,
3232
ReplyKeyboardMarkup,
3333
Update,
3434
)
@@ -894,6 +894,17 @@ async def media_filter(_, __, m: Message):
894894
"""
895895

896896

897+
# endregion
898+
899+
# region guest_message_filter
900+
async def guest_message_filter(_, __, m: Message):
901+
return bool(m.guest_query_id)
902+
903+
904+
guest_message = create(guest_message_filter)
905+
"""Filter messages that has been sent by a guest bot."""
906+
907+
897908
# endregion
898909

899910
# region scheduled_filter

pyrogram/methods/bots/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
from .answer_callback_query import AnswerCallbackQuery
20+
from .answer_guest_query import AnswerGuestQuery
2021
from .answer_inline_query import AnswerInlineQuery
2122
from .answer_pre_checkout_query import AnswerPreCheckoutQuery
2223
from .answer_shipping_query import AnswerShippingQuery
@@ -36,6 +37,7 @@
3637
from .get_chat_menu_button import GetChatMenuButton
3738
from .get_game_high_scores import GetGameHighScores
3839
from .get_inline_bot_results import GetInlineBotResults
40+
from .get_managed_bot_access_settings import GetManagedBotAccessSettings
3941
from .get_owned_bots import GetOwnedBots
4042
from .refund_star_payment import RefundStarPayment
4143
from .request_callback_answer import RequestCallbackAnswer
@@ -49,15 +51,18 @@
4951
from .set_bot_name import SetBotName
5052
from .set_chat_menu_button import SetChatMenuButton
5153
from .set_game_score import SetGameScore
54+
from .set_managed_bot_access_settings import SetManagedBotAccessSettings
5255

5356

5457
class Bots(
5558
AnswerCallbackQuery,
59+
AnswerGuestQuery,
5660
AnswerInlineQuery,
5761
AnswerPreCheckoutQuery,
5862
AnswerShippingQuery,
5963
CreateInvoiceLink,
6064
GetInlineBotResults,
65+
GetManagedBotAccessSettings,
6166
GetOwnedBots,
6267
RefundStarPayment,
6368
RequestCallbackAnswer,
@@ -84,6 +89,7 @@ class Bots(
8489
GetChatMenuButton,
8590
AnswerWebAppQuery,
8691
CheckBotUsername,
87-
CreateBot
92+
CreateBot,
93+
SetManagedBotAccessSettings
8894
):
8995
pass
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 Iterable
20+
21+
import pyrogram
22+
from pyrogram import raw, types
23+
24+
25+
class AnswerGuestQuery:
26+
async def answer_guest_query(
27+
self: "pyrogram.Client", guest_query_id: str, result: "types.InlineQueryResult"
28+
):
29+
"""Use this method to reply to a received guest message.
30+
31+
.. include:: /_includes/usable-by/bots.rst
32+
33+
Parameters:
34+
guest_query_id (``str``):
35+
Unique identifier for the answered query.
36+
37+
result (:obj:`~pyrogram.types.InlineQueryResult`):
38+
A result for the guest query.
39+
40+
Returns:
41+
:obj:`~pyrogram.types.SentGuestMessage`: On success, a :obj:`~pyrogram.types.SentGuestMessage` object is returned.
42+
43+
Example:
44+
.. code-block:: python
45+
46+
from pyrogram.types import InlineQueryResultArticle, InputTextMessageContent
47+
48+
await app.answer_guest_query(
49+
guest_query_id,
50+
results=[
51+
InlineQueryResultArticle(
52+
"Title",
53+
InputTextMessageContent("Message content"))])
54+
"""
55+
r = await self.invoke(
56+
raw.functions.messages.SetBotGuestChatResult(
57+
query_id=int(guest_query_id),
58+
result=await result.write(self),
59+
)
60+
)
61+
62+
return types.SentGuestMessage._parse(r)

pyrogram/methods/chats/delete_chat_reactions_by_sender.py renamed to pyrogram/methods/bots/get_managed_bot_access_settings.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,29 @@
1919
from typing import Union
2020

2121
import pyrogram
22-
from pyrogram import raw
22+
from pyrogram import raw, types
2323

2424

25-
class DeleteChatReactionsBySender:
26-
async def delete_chat_reactions_by_sender(
25+
class GetManagedBotAccessSettings:
26+
async def get_managed_bot_access_settings(
2727
self: "pyrogram.Client",
28-
chat_id: Union[int, str],
29-
sender_id: Union[int, str],
30-
) -> bool:
31-
"""Delete all reactions sent by a certain user in a chat.
28+
user_id: Union[int, str],
29+
) -> "types.BotAccessSettings":
30+
"""Use this method to get the access settings of a managed bot.
3231
33-
.. include:: /_includes/usable-by/users.rst
32+
.. include:: /_includes/usable-by/users-bots.rst
3433
3534
Parameters:
36-
chat_id (``int`` | ``str``):
37-
Unique identifier (int) or username (str) of the target chat.
38-
39-
sender_id (``int`` | ``str``):
40-
Unique identifier (int) or username (str) of the user whose reactions will be deleted.
35+
user_id (``int`` | ``str``):
36+
Unique identifier (int) or username (str) of the managed bot whose access settings will be returned.
4137
4238
Returns:
43-
``bool``: True on success, False otherwise.
39+
:obj:`~pyrogram.types.BotAccessSettings`: On success, bot token is returned.
4440
"""
45-
46-
return await self.invoke(
47-
raw.functions.messages.DeleteParticipantReactions(
48-
peer=await self.resolve_peer(chat_id),
49-
participant=await self.resolve_peer(sender_id),
41+
r = await self.invoke(
42+
raw.functions.bots.GetAccessSettings(
43+
bot=await self.resolve_peer(user_id),
5044
)
5145
)
46+
47+
return types.BotAccessSettings._parse(self, r)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 List, Optional, Union
20+
21+
import pyrogram
22+
from pyrogram import raw
23+
24+
25+
class SetManagedBotAccessSettings:
26+
async def set_managed_bot_access_settings(
27+
self: "pyrogram.Client",
28+
user_id: Union[int, str],
29+
is_access_restricted: bool,
30+
added_user_ids: Optional[List[Union[int, str]]] = None,
31+
) -> bool:
32+
"""Use this method to get the access settings of a managed bot.
33+
34+
.. include:: /_includes/usable-by/users-bots.rst
35+
36+
Parameters:
37+
user_id (``int`` | ``str``):
38+
Unique identifier (int) or username (str) of the managed bot whose access settings will be changed.
39+
40+
is_access_restricted (``bool``):
41+
Pass True, if only selected users can access the bot.
42+
The bot's owner can always access it.
43+
44+
added_user_ids (List of ``int`` | ``str``, *optional*):
45+
List of up to 10 identifiers of users who will have access to the bot in addition to its owner.
46+
Ignored if is_access_restricted is False.
47+
48+
Returns:
49+
``bool``: On success, True is returned.
50+
"""
51+
if is_access_restricted is False:
52+
added_user_ids = None
53+
54+
return await self.invoke(
55+
raw.functions.bots.EditAccessSettings(
56+
bot=await self.resolve_peer(user_id),
57+
restricted=is_access_restricted,
58+
add_users=[await self.resolve_peer(i) for i in added_user_ids] if added_user_ids is not None else None,
59+
)
60+
)

0 commit comments

Comments
 (0)