Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c448bba
Update types.py
coder2020official Apr 12, 2025
805c78f
Add business account methods
coder2020official Apr 12, 2025
1d32718
Added AcceptedGiftTypes and set_business_account_gift_settings
coder2020official Apr 12, 2025
3e0f06a
Add get_business_account_star_balance
coder2020official Apr 12, 2025
af858de
Added transfer_business_account_stars
coder2020official Apr 12, 2025
c012a59
Added get_business_account_gifts, OwnedGiftRegular, OwnedGiftUnique, …
coder2020official Apr 12, 2025
3d238a4
Added convert_gift_to_stars
coder2020official Apr 12, 2025
817f2ad
Added upgrade_gift and transfer_gift methods
coder2020official Apr 12, 2025
b47c73f
Added InputStoryContent
coder2020official Apr 12, 2025
1713909
Stories
coder2020official Apr 12, 2025
1c08163
posting, editing, deleting stories(needs testing)
coder2020official Apr 12, 2025
b05d209
Replaced the field can_send_gift with the field accepted_gift_types …
coder2020official Apr 12, 2025
6fedece
Added unique_gift and gift
coder2020official Apr 12, 2025
e3d7f96
Added gift_premium_subscription
coder2020official Apr 12, 2025
f76cac8
Added premium_subscription_duration to TransactionPartnerUser
coder2020official Apr 12, 2025
0bd9133
Added transaction_type to TransactionPartnerUser
coder2020official Apr 12, 2025
950d7c6
Added paid_message_price_changed
coder2020official Apr 12, 2025
9fb4fdd
Added paid_star_count
coder2020official Apr 12, 2025
0d1e515
Added set_business_account_profile_photo and remove_business_account_…
coder2020official Apr 12, 2025
d63b07a
Fix issues with posting stories
coder2020official Apr 13, 2025
49684b5
Fix stories for async
coder2020official Apr 13, 2025
533b52c
Fix issues related with Bot api 9.0
coder2020official Apr 19, 2025
d4f5ead
Fix typehints
coder2020official Apr 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.</p>
<p align="center">Both synchronous and asynchronous.</p>

## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#february-12-2025"><img src="https://img.shields.io/badge/Bot%20API-8.3-blue?logo=telegram" alt="Supported Bot API version"></a>
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#april-11-2025"><img src="https://img.shields.io/badge/Bot%20API-9.0-blue?logo=telegram" alt="Supported Bot API version"></a>

<h2><a href='https://pytba.readthedocs.io/en/latest/index.html'>Official documentation</a></h2>
<h2><a href='https://pytba.readthedocs.io/ru/latest/index.html'>Official ru documentation</a></h2>
Expand Down
289 changes: 289 additions & 0 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6377,7 +6377,295 @@ def remove_chat_verification(self, chat_id: Union[int, str]) -> bool:
:rtype: :obj:`bool`
"""
return apihelper.remove_chat_verification(self.token, chat_id)

def read_business_message(self, business_connection_id: str, chat_id: Union[int, str], message_id: int) -> bool:
"""
Marks incoming message as read on behalf of a business account. Requires the can_read_messages business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#readbusinessmessage

:param business_connection_id: Unique identifier of the business connection on behalf of which to read the message
:type business_connection_id: :obj:`str`

:param chat_id: Unique identifier of the chat in which the message was received. The chat must have been active in the last 24 hours.
:type chat_id: :obj:`int` | :obj:`str`

:param message_id: Unique identifier of the message to mark as read
:type message_id: :obj:`int`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.read_business_message(self.token, business_connection_id, chat_id, message_id)

def delete_business_messages(self, business_connection_id: str, message_ids: List[int]) -> bool:
"""
Delete messages on behalf of a business account. Requires the can_delete_outgoing_messages business bot right to delete messages sent by the bot itself, or the can_delete_all_messages business bot right to delete any message. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#deletebusinessmessages

:param business_connection_id: Unique identifier of the business connection on behalf of which to delete the messages
:type business_connection_id: :obj:`str`

:param message_ids: A JSON-serialized list of 1-100 identifiers of messages to delete. All messages must be from the same chat. See deleteMessage for limitations on which messages can be deleted
:type message_ids: :obj:`list` of :obj:`int`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.delete_business_messages(self.token, business_connection_id, message_ids)

def set_business_account_name(self, business_connection_id: str, first_name: str, last_name: Optional[str]=None) -> bool:
"""
Changes the first and last name of a managed business account. Requires the can_change_name business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setbusinessaccountname

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param first_name: The new value of the first name for the business account; 1-64 characters
:type first_name: :obj:`str`

:param last_name: The new value of the last name for the business account; 0-64 characters
:type last_name: :obj:`str`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.set_business_account_name(self.token, business_connection_id, first_name, last_name)

def set_business_account_username(self, business_connection_id: str, username: Optional[str]=None) -> bool:
"""
Changes the username of a managed business account. Requires the can_change_username business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setbusinessaccountusername

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param username: The new value of the username for the business account; 0-32 characters
:type username: :obj:`str`

:return: Returns True on success.
:rtype: :obj:`bool`

"""
return apihelper.set_business_account_username(self.token, business_connection_id, username)

def set_business_account_bio(self, business_connection_id: str, bio: Optional[str]=None) -> bool:
"""
Changes the bio of a managed business account. Requires the can_change_bio business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setbusinessaccountbio

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param bio: The new value of the bio for the business account; 0-140 characters
:type bio: :obj:`str`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.set_business_account_bio(self.token, business_connection_id, bio)

def set_business_account_gift_settings(
self, business_connection_id: str, show_gift_button: bool, accepted_gift_types: types.AcceptedGiftTypes) -> bool:
"""
Changes the privacy settings pertaining to incoming gifts in a managed business account. Requires the can_change_gift_settings business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setbusinessaccountgiftsettings

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param show_gift_button: Pass True, if a button for sending a gift to the user or by the business account must always be shown in the input field
:type show_gift_button: :obj:`bool`

:param accepted_gift_types: Types of gifts accepted by the business account
:type accepted_gift_types: :class:`telebot.types.AcceptedGiftTypes`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.set_business_account_gift_settings(self.token, business_connection_id, show_gift_button, accepted_gift_types)


def get_business_account_star_balance(self, business_connection_id: str) -> types.StarAmount:
"""
Returns the amount of Telegram Stars owned by a managed business account. Requires the can_view_gifts_and_stars business bot right. Returns StarAmount on success.

Telegram documentation: https://core.telegram.org/bots/api#getbusinessaccountstarbalance

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:return: On success, a StarAmount object is returned.
:rtype: :class:`telebot.types.StarAmount`
"""
return types.StarAmount.de_json(
apihelper.get_business_account_star_balance(self.token, business_connection_id)
)

def transfer_business_account_stars(self, business_connection_id: str, star_count: int) -> bool:
"""
Transfers Telegram Stars from the business account balance to the bot's balance. Requires the can_transfer_stars business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#transferbusinessaccountstars

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param star_count: Number of Telegram Stars to transfer; 1-10000
:type star_count: :obj:`int`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.transfer_business_account_stars(self.token, business_connection_id, star_count)

def get_business_account_gifts(
self, business_connection_id: str,
exclude_unsaved: Optional[bool]=None,
exclude_saved: Optional[bool]=None,
exclude_unlimited: Optional[bool]=None,
exclude_limited: Optional[bool]=None,
exclude_unique: Optional[bool]=None,
sort_by_price: Optional[bool]=None,
offset: Optional[str]=None,
limit: Optional[int]=None) -> types.OwnedGifts:
"""
Returns the gifts received and owned by a managed business account. Requires the can_view_gifts_and_stars business bot right. Returns OwnedGifts on success.

Telegram documentation: https://core.telegram.org/bots/api#getbusinessaccountgifts

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param exclude_unsaved: Pass True to exclude gifts that aren't saved to the account's profile page
:type exclude_unsaved: :obj:`bool`

:param exclude_saved: Pass True to exclude gifts that are saved to the account's profile page
:type exclude_saved: :obj:`bool`

:param exclude_unlimited: Pass True to exclude gifts that can be purchased an unlimited number of times
:type exclude_unlimited: :obj:`bool`

:param exclude_limited: Pass True to exclude gifts that can be purchased a limited number of times
:type exclude_limited: :obj:`bool`

:param exclude_unique: Pass True to exclude unique gifts
:type exclude_unique: :obj:`bool`

:param sort_by_price: Pass True to sort results by gift price instead of send date. Sorting is applied before pagination.
:type sort_by_price: :obj:`bool`

:param offset: Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results
:type offset: :obj:`str`

:param limit: The maximum number of gifts to be returned; 1-100. Defaults to 100
:type limit: :obj:`int`

:return: On success, a OwnedGifts object is returned.
:rtype: :class:`telebot.types.OwnedGifts`
"""
return types.OwnedGifts.de_json(
apihelper.get_business_account_gifts(
self.token, business_connection_id,
exclude_unsaved=exclude_unsaved,
exclude_saved=exclude_saved,
exclude_unlimited=exclude_unlimited,
exclude_limited=exclude_limited,
exclude_unique=exclude_unique,
sort_by_price=sort_by_price,
offset=offset,
limit=limit
)
)

def convert_gift_to_stars(self, business_connection_id: str, owned_gift_id: str) -> bool:
"""
Converts a given regular gift to Telegram Stars. Requires the can_convert_gifts_to_stars business bot right. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#convertgifttostars

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param owned_gift_id: Unique identifier of the regular gift that should be converted to Telegram Stars
:type owned_gift_id: :obj:`str`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.convert_gift_to_stars(self.token, business_connection_id, owned_gift_id)

def upgrade_gift(
self, business_connection_id: str, owned_gift_id: str,
keep_original_details: Optional[bool]=None,
star_count: Optional[int]=None) -> bool:
"""
Upgrades a given regular gift to a unique gift. Requires the can_transfer_and_upgrade_gifts business bot right.
Additionally requires the can_transfer_stars business bot right if the upgrade is paid. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#upgradegift

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param owned_gift_id: Unique identifier of the regular gift that should be upgraded to a unique one
:type owned_gift_id: :obj:`str`

:param keep_original_details: Pass True to keep the original gift text, sender and receiver in the upgraded gift
:type keep_original_details: :obj:`bool`

:param star_count: The amount of Telegram Stars that will be paid for the upgrade from the business account balance.
If gift.prepaid_upgrade_star_count > 0, then pass 0, otherwise, the can_transfer_stars business bot right is required and gift.upgrade_star_count must be passed.
:type star_count: :obj:`int`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.upgrade_gift(
self.token, business_connection_id, owned_gift_id,
keep_original_details=keep_original_details,
star_count=star_count
)

def transfer_gift(
self, business_connection_id: str, owned_gift_id: str,
new_owner_chat_id: Union[int, str],
star_count: Optional[int]=None) -> bool:
"""
Transfers an owned unique gift to another user. Requires the can_transfer_and_upgrade_gifts business bot right.
Requires can_transfer_stars business bot right if the transfer is paid. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#transfergift

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:param owned_gift_id: Unique identifier of the regular gift that should be transferred
:type owned_gift_id: :obj:`str`

:param new_owner_chat_id: Unique identifier of the chat which will own the gift. The chat must be active in the last 24 hours.
:type new_owner_chat_id: :obj:`int` | :obj:`str`

:param star_count: The amount of Telegram Stars that will be paid for the transfer from the business account balance.
If positive, then the can_transfer_stars business bot right is required.
:type star_count: :obj:`int`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.transfer_gift(
self.token, business_connection_id, owned_gift_id,
new_owner_chat_id=new_owner_chat_id,
star_count=star_count
)


def get_available_gifts(self) -> types.Gifts:
"""
Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a Gifts object.
Expand Down Expand Up @@ -9363,3 +9651,4 @@ def _notify_command_handlers(self, handlers, new_messages, update_type):
handlers=handlers,
middlewares=middlewares,
update_type=update_type)

Loading