Skip to content

Commit 469b742

Browse files
authored
Update API Scheme to Layer 201 from TDLib
* Add BusinessBotRights * Add get_business_account_star_balance * Add PaidMessagePriceChanged * Rename paid_message_star_count to paid_star_count, in Message * Add paid_messages_refunded
1 parent 1ea5e79 commit 469b742

File tree

13 files changed

+394
-25
lines changed

13 files changed

+394
-25
lines changed

compiler/api/source/main_api.tl

Lines changed: 27 additions & 12 deletions
Large diffs are not rendered by default.

compiler/docs/compiler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def get_title_list(s: str) -> list:
409409
send_gift
410410
toggle_gift_is_saved
411411
get_owned_star_count
412+
get_business_account_star_balance
412413
""",
413414
advanced="""
414415
Advanced
@@ -481,6 +482,8 @@ def get_title_list(s: str) -> list:
481482
VideoChatStarted
482483
VideoChatEnded
483484
VideoChatParticipantsInvited
485+
PaidMessagePriceChanged
486+
PaidMessagesRefunded
484487
Dialog
485488
EmojiStatus
486489
GroupCallParticipant
@@ -666,6 +669,7 @@ def get_title_list(s: str) -> list:
666669
""",
667670
payments="""
668671
Payments
672+
BusinessBotRights
669673
BusinessConnection
670674
BusinessIntro
671675
BusinessLocation

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ Breaking Changes in this Fork
3030
Changes in this Fork
3131
=====================
3232

33+
+------------------------+
34+
| Scheme layer used: 201 |
35+
+------------------------+
36+
37+
- Renamed the field ``paid_message_star_count`` to ``paid_star_count`` in the :obj:`~pyrogram.types.Message`, containing the number of Telegram Stars that were paid to send the message.
38+
- Added the classes :obj:`~pyrogram.types.PaidMessagePriceChanged` and :obj:`~pyrogram.types.PaidMessagesRefunded` and the fields ``paid_message_price_changed`` and ``paid_messages_refunded`` to the :obj:`~pyrogram.types.Message`, describing the appropriate service message.
39+
- Added the :meth:`~pyrogram.Client.get_business_account_star_balance`, allowing bots to check the current Telegram Star balance of a managed business account.
40+
- Added the :obj:`~pyrogram.types.BusinessBotRights` and replaced the field ``can_reply`` with the field ``rights`` of the type :obj:`~pyrogram.types.BusinessBotRights` in the :obj:`~pyrogram.types.BusinessConnection`.
41+
- View `new and changed <https://telegramplayground.github.io/TG-APIs/TL/diff/tdlib.html?from=200&to=201>`__ `raw API methods <https://telegramplayground.github.io/TG-APIs/TL/diff/tdesktop.html?from=200&to=201>`__.
42+
3343
+------------------------+
3444
| Scheme layer used: 200 |
3545
+------------------------+

pyrogram/enums/message_service_type.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,11 @@ class MessageServiceType(AutoName):
144144
RECEIVED_GIFT = auto()
145145
"Owner Received gift"
146146

147+
PAID_MESSAGE_PRICE_CHANGED = auto()
148+
"The price for paid messages has changed in the chat"
149+
150+
PAID_MESSAGES_REFUNDED = auto()
151+
"Refunded paid messages"
152+
147153
UNKNOWN = auto()
148154
"This service message is unsupported by the current version of Pyrogram"

pyrogram/methods/business/get_owned_star_count.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,38 @@ async def get_owned_star_count(
6262
)
6363

6464
return types.StarAmount._parse(self, r)
65+
66+
67+
async def get_business_account_star_balance(
68+
self: "pyrogram.Client",
69+
business_connection_id: str,
70+
) -> "types.StarAmount":
71+
"""Returns the amount of Telegram Stars owned by a managed business account. Requires the can_view_gifts_and_stars business bot right.
72+
73+
.. include:: /_includes/usable-by/bots.rst
74+
75+
Parameters:
76+
business_connection_id (``str``):
77+
Unique identifier of the business connection
78+
79+
Returns:
80+
:obj:`~pyrogram.types.StarAmount`: On success, the current stars balance is returned.
81+
82+
"""
83+
if not business_connection_id:
84+
raise ValueError("business_connection_id is required")
85+
86+
business_connection = self.business_user_connection_cache[business_connection_id]
87+
if not business_connection:
88+
business_connection = await self.get_business_connection(business_connection_id)
89+
r = await self.invoke(
90+
raw.functions.InvokeWithBusinessConnection(
91+
query=raw.functions.payments.GetStarsStatus(
92+
peer=await self.resolve_peer(
93+
business_connection.user_chat_id
94+
)
95+
),
96+
connection_id=business_connection_id
97+
)
98+
)
99+
return types.StarAmount._parse(self, r)

pyrogram/methods/chats/set_chat_photo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727

2828
class SetChatPhoto:
29+
# TODO: FIXME!
2930
async def set_chat_photo(
3031
self: "pyrogram.Client",
3132
chat_id: Union[int, str],

pyrogram/types/business/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from .business_bot_rights import BusinessBotRights
1920
from .business_connection import BusinessConnection
2021
from .business_intro import BusinessIntro
2122
from .business_location import BusinessLocation
@@ -40,6 +41,7 @@
4041
from .refunded_payment import RefundedPayment
4142

4243
__all__ = [
44+
"BusinessBotRights",
4345
"BusinessConnection",
4446
"BusinessIntro",
4547
"BusinessLocation",
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present <https://github.com/TelegramPlayGround>
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 Optional
20+
21+
import pyrogram
22+
from pyrogram import raw
23+
24+
from ..object import Object
25+
26+
27+
class BusinessBotRights(Object):
28+
"""Represents the rights of a business bot.
29+
30+
Parameters:
31+
can_reply (``bool``, *optional*):
32+
True, if the bot can send and edit messages in the private chats that had incoming messages in the last 24 hours.
33+
34+
can_read_messages (``bool``, *optional*):
35+
True, if the bot can mark incoming private messages as read.
36+
37+
can_delete_outgoing_messages (``bool``, *optional*):
38+
True, if the bot can delete messages sent by the bot.
39+
40+
can_delete_all_messages (``bool``, *optional*):
41+
True, if the bot can delete all private messages in managed chats.
42+
43+
can_edit_name (``bool``, *optional*):
44+
True, if the bot can edit the first and last name of the business account.
45+
46+
can_edit_bio (``bool``, *optional*):
47+
True, if the bot can edit the bio of the business account.
48+
49+
can_edit_profile_photo (``bool``, *optional*):
50+
True, if the bot can edit the profile photo of the business account.
51+
52+
can_edit_username (``bool``, *optional*):
53+
True, if the bot can edit the username of the business account.
54+
55+
can_change_gift_settings (``bool``, *optional*):
56+
True, if the bot can change the privacy settings pertaining to gifts for the business account.
57+
58+
can_view_gifts_and_stars (``bool``, *optional*):
59+
True, if the bot can view gifts and the amount of Telegram Stars owned by the business account.
60+
61+
can_convert_gifts_to_stars (``bool``, *optional*):
62+
True, if the bot can convert regular gifts owned by the business account to Telegram Stars.
63+
64+
can_transfer_and_upgrade_gifts (``bool``, *optional*):
65+
True, if the bot can transfer and upgrade gifts owned by the business account.
66+
67+
can_transfer_stars (``bool``, *optional*):
68+
True, if the bot can transfer Telegram Stars received by the business account to its own account, or use them to upgrade and transfer gifts.
69+
70+
can_manage_stories (``bool``, *optional*):
71+
True, if the bot can post, edit and delete stories on behalf of the business account.
72+
73+
"""
74+
75+
def __init__(
76+
self,
77+
*,
78+
can_reply: Optional[bool] = None,
79+
can_read_messages: Optional[bool] = None,
80+
can_delete_outgoing_messages: Optional[bool] = None,
81+
can_delete_all_messages: Optional[bool] = None,
82+
can_edit_name: Optional[bool] = None,
83+
can_edit_bio: Optional[bool] = None,
84+
can_edit_profile_photo: Optional[bool] = None,
85+
can_edit_username: Optional[bool] = None,
86+
can_change_gift_settings: Optional[bool] = None,
87+
can_view_gifts_and_stars: Optional[bool] = None,
88+
can_convert_gifts_to_stars: Optional[bool] = None,
89+
can_transfer_and_upgrade_gifts: Optional[bool] = None,
90+
can_transfer_stars: Optional[bool] = None,
91+
can_manage_stories: Optional[bool] = None,
92+
):
93+
super().__init__()
94+
95+
self.can_reply = can_reply
96+
self.can_read_messages = can_read_messages
97+
self.can_delete_outgoing_messages = can_delete_outgoing_messages
98+
self.can_delete_all_messages = can_delete_all_messages
99+
self.can_edit_name = can_edit_name
100+
self.can_edit_bio = can_edit_bio
101+
self.can_edit_profile_photo = can_edit_profile_photo
102+
self.can_edit_username = can_edit_username
103+
self.can_change_gift_settings = can_change_gift_settings
104+
self.can_view_gifts_and_stars = can_view_gifts_and_stars
105+
self.can_convert_gifts_to_stars = can_convert_gifts_to_stars
106+
self.can_transfer_and_upgrade_gifts = can_transfer_and_upgrade_gifts
107+
self.can_transfer_stars = can_transfer_stars
108+
self.can_manage_stories = can_manage_stories
109+
110+
111+
@staticmethod
112+
def _parse(
113+
client,
114+
business_bot_rights: "raw.types.BusinessBotRights"
115+
) -> "BusinessBotRights":
116+
if not business_bot_rights:
117+
return None
118+
return BusinessBotRights(
119+
can_reply=business_bot_rights.reply,
120+
can_read_messages=business_bot_rights.read_messages,
121+
can_delete_outgoing_messages=business_bot_rights.delete_sent_messages,
122+
can_delete_all_messages=business_bot_rights.delete_received_messages,
123+
can_edit_name=business_bot_rights.edit_name,
124+
can_edit_bio=business_bot_rights.edit_bio,
125+
can_edit_profile_photo=business_bot_rights.edit_profile_photo,
126+
can_edit_username=business_bot_rights.edit_username,
127+
can_change_gift_settings=business_bot_rights.change_gift_settings,
128+
can_view_gifts_and_stars=business_bot_rights.view_gifts,
129+
can_convert_gifts_to_stars=business_bot_rights.sell_gifts,
130+
can_transfer_and_upgrade_gifts=business_bot_rights.transfer_and_upgrade_gifts,
131+
can_transfer_stars=business_bot_rights.transfer_stars,
132+
can_manage_stories=business_bot_rights.manage_stories,
133+
)

pyrogram/types/business/business_connection.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Pyrogram - Telegram MTProto API Client Library for Python
2-
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
2+
# Copyright (C) 2017-present <https://github.com/TelegramPlayGround>
33
#
44
# This file is part of Pyrogram.
55
#
@@ -16,14 +16,19 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
import logging
1920
from datetime import datetime
21+
from typing import Optional
2022

2123
import pyrogram
2224
from pyrogram import raw, types, utils
2325

2426
from ..object import Object
2527

2628

29+
log = logging.getLogger(__name__)
30+
31+
2732
class BusinessConnection(Object):
2833
"""Describes the connection of the bot with a business account.
2934
@@ -40,8 +45,8 @@ class BusinessConnection(Object):
4045
date (:py:obj:`~datetime.datetime`):
4146
Date the connection was established in Unix time
4247
43-
can_reply (``bool``):
44-
True, if the bot can act on behalf of the business account in chats that were active in the last 24 hours
48+
rights (:obj:`~pyrogram.types.BusinessBotRights`, *optional*):
49+
Rights of the business bot.
4550
4651
is_enabled (``bool``):
4752
True, if the connection is active
@@ -55,17 +60,17 @@ def __init__(
5560
user: "types.User" = None,
5661
user_chat_id: int = None,
5762
date: datetime,
58-
can_reply: bool = None,
63+
rights: Optional["types.BusinessBotRights"] = None,
5964
is_enabled: bool = None,
60-
_raw: "raw.types.UpdateBotBusinessConnect" = None
65+
_raw: "raw.types.UpdateBotBusinessConnect" = None,
6166
):
6267
super().__init__()
6368

6469
self.id = id
6570
self.user = user
6671
self.user_chat_id = user_chat_id
6772
self.date = date
68-
self.can_reply = can_reply
73+
self.rights = rights
6974
self.is_enabled = is_enabled
7075
self._raw = _raw
7176

@@ -88,6 +93,20 @@ def _parse(
8893
),
8994
user_chat_id=business_connect_update.connection.user_id,
9095
date=utils.timestamp_to_datetime(business_connect_update.connection.date),
91-
can_reply=getattr(business_connect_update.connection, "can_reply", False),
96+
rights=types.BusinessBotRights._parse(
97+
client,
98+
business_connect_update.connection.rights
99+
),
92100
is_enabled=not bool(getattr(business_connect_update.connection, "disabled", None))
93101
)
102+
103+
104+
@property
105+
def can_reply(self) -> str:
106+
log.warning(
107+
"This property is deprecated. "
108+
"Please use rights instead"
109+
)
110+
if self.rights:
111+
return self.rights.can_reply
112+
return False

pyrogram/types/messages_and_media/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
from .translated_text import TranslatedText
7171
from .message_auto_delete_timer_changed import MessageAutoDeleteTimerChanged
7272
from .write_access_allowed import WriteAccessAllowed
73+
from .paid_message_price_changed import PaidMessagePriceChanged
74+
from .paid_messages_refunded import PaidMessagesRefunded
7375

7476
__all__ = [
7577
"AlternativeVideo",
@@ -124,4 +126,6 @@
124126
"WriteAccessAllowed",
125127
"ScreenshotTaken",
126128
"TranslatedText",
129+
"PaidMessagePriceChanged",
130+
"PaidMessagesRefunded",
127131
]

0 commit comments

Comments
 (0)