Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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#may-8-2026"><img src="https://img.shields.io/badge/Bot%20API-10.0-blue?logo=telegram" alt="Supported Bot API version"></a>
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#june-11-2026"><img src="https://img.shields.io/badge/Bot%20API-10.1-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
129 changes: 126 additions & 3 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5659,7 +5659,8 @@ def edit_message_text(
reply_markup: Optional[types.InlineKeyboardMarkup]=None,
link_preview_options : Optional[types.LinkPreviewOptions]=None,
business_connection_id: Optional[str]=None,
timeout: Optional[int]=None) -> Union[types.Message, bool]:
timeout: Optional[int]=None,
rich_message: Optional[types.InputRichMessage]=None) -> Union[types.Message, bool]:
"""
Use this method to edit text and game messages.

Expand Down Expand Up @@ -5725,7 +5726,7 @@ def edit_message_text(
result = apihelper.edit_message_text(
self.token, text, chat_id=chat_id, message_id=message_id, inline_message_id=inline_message_id,
parse_mode=parse_mode, entities=entities, reply_markup=reply_markup, link_preview_options=link_preview_options,
business_connection_id=business_connection_id, timeout=timeout)
business_connection_id=business_connection_id, timeout=timeout, rich_message=rich_message)

if isinstance(result, bool): # if edit inline message return is bool not Message.
return result
Expand Down Expand Up @@ -6909,7 +6910,7 @@ def answer_guest_query(self, guest_query_id: str, result: types.InlineQueryResul

:param result: A JSON-serialized object describing the message to be sent
:type result: :obj:`types.InlineQueryResult`

:return: On success, a SentGuestMessage object is returned.
:rtype: :obj:`types.SentGuestMessage`
"""
Expand All @@ -6918,6 +6919,128 @@ def answer_guest_query(self, guest_query_id: str, result: types.InlineQueryResul
)


def send_rich_message(
self, chat_id: Union[int, str],
rich_message: types.InputRichMessage,
message_thread_id: Optional[int]=None,
reply_markup: Optional[types.InlineKeyboardMarkup]=None,
disable_notification: Optional[bool]=None,
protect_content: Optional[bool]=None,
reply_parameters: Optional[types.ReplyParameters]=None,
business_connection_id: Optional[str]=None) -> types.Message:
"""
Use this method to send a rich formatted message. On success, the sent Message is returned.

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

:param chat_id: Unique identifier for the target chat or username of the target channel
:type chat_id: :obj:`int` or :obj:`str`

:param rich_message: A JSON-serialized object for the rich message content
:type rich_message: :class:`telebot.types.InputRichMessage`

:param message_thread_id: Unique identifier for the target message thread
:type message_thread_id: :obj:`int`

:param reply_markup: Additional interface options
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup`

:param disable_notification: Sends the message silently
:type disable_notification: :obj:`bool`

:param protect_content: Protects the contents of the sent message from forwarding and saving
:type protect_content: :obj:`bool`

:param reply_parameters: Description of the message to reply to
:type reply_parameters: :class:`telebot.types.ReplyParameters`

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

:return: On success, the sent Message is returned.
:rtype: :class:`telebot.types.Message`
"""
return types.Message.de_json(
apihelper.send_rich_message(
self.token, chat_id, rich_message,
message_thread_id=message_thread_id,
reply_markup=reply_markup,
disable_notification=disable_notification,
protect_content=protect_content,
reply_parameters=reply_parameters,
business_connection_id=business_connection_id))


def send_rich_message_draft(
self, chat_id: int,
draft_id: int,
rich_message: types.InputRichMessage,
message_thread_id: Optional[int]=None) -> bool:
"""
Use this method to stream a partial rich message to a user while the message is being generated.
Returns True on success.

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

:param chat_id: Unique identifier for the target private chat
:type chat_id: :obj:`int`

:param draft_id: Unique identifier of the message draft; must be non-zero
:type draft_id: :obj:`int`

:param rich_message: A JSON-serialized object for the rich message draft content
:type rich_message: :class:`telebot.types.InputRichMessage`

:param message_thread_id: Unique identifier for the target message thread
:type message_thread_id: :obj:`int`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.send_rich_message_draft(
self.token, chat_id, draft_id, rich_message, message_thread_id=message_thread_id)


def answer_chat_join_request_query(
self, query_id: str,
result: types.InlineQueryResultBase) -> bool:
"""
Use this method to handle a join request query with a custom response. Returns True on success.

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

:param query_id: Unique identifier of the join request query
:type query_id: :obj:`str`

:param result: A JSON-serialized object describing the response to send
:type result: :class:`telebot.types.InlineQueryResultBase`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.answer_chat_join_request_query(self.token, query_id, result)


def send_chat_join_request_web_app(
self, query_id: str,
web_app_url: str) -> bool:
"""
Use this method to trigger a Web App in response to a join request query. Returns True on success.

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

:param query_id: Unique identifier of the join request query
:type query_id: :obj:`str`

:param web_app_url: URL of the Web App to be opened
:type web_app_url: :obj:`str`

:return: Returns True on success.
:rtype: :obj:`bool`
"""
return apihelper.send_chat_join_request_web_app(self.token, query_id, web_app_url)


def get_user_chat_boosts(self, chat_id: Union[int, str], user_id: int) -> types.UserChatBoosts:
"""
Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object.
Expand Down
45 changes: 44 additions & 1 deletion telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ def unpin_all_chat_messages(token, chat_id):

def edit_message_text(
token, text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, entities = None,
reply_markup=None, link_preview_options=None, business_connection_id=None, timeout=None):
reply_markup=None, link_preview_options=None, business_connection_id=None, timeout=None, rich_message=None):
method_url = r'editMessageText'
payload = {'text': text}
if chat_id:
Expand All @@ -1758,6 +1758,8 @@ def edit_message_text(
payload['business_connection_id'] = business_connection_id
if timeout:
payload['timeout'] = timeout
if rich_message is not None:
payload['rich_message'] = rich_message.to_json()
return _make_request(token, method_url, params=payload, method='post')


Expand Down Expand Up @@ -2136,6 +2138,47 @@ def answer_guest_query(token, guest_query_id, result):
payload = {'guest_query_id': guest_query_id, 'result': result.to_json()}
return _make_request(token, method_url, params=payload, method='post')


def send_rich_message(token, chat_id, rich_message, message_thread_id=None,
reply_markup=None, disable_notification=None, protect_content=None,
reply_parameters=None, business_connection_id=None):
method_url = 'sendRichMessage'
payload = {'chat_id': chat_id, 'rich_message': rich_message.to_json()}
if message_thread_id is not None:
payload['message_thread_id'] = message_thread_id
if reply_markup:
payload['reply_markup'] = _convert_markup(reply_markup)
if disable_notification is not None:
payload['disable_notification'] = disable_notification
if protect_content is not None:
payload['protect_content'] = protect_content
if reply_parameters is not None:
payload['reply_parameters'] = reply_parameters.to_json()
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return _make_request(token, method_url, params=payload, method='post')


def send_rich_message_draft(token, chat_id, draft_id, rich_message, message_thread_id=None):
method_url = 'sendRichMessageDraft'
payload = {'chat_id': chat_id, 'draft_id': draft_id, 'rich_message': rich_message.to_json()}
if message_thread_id is not None:
payload['message_thread_id'] = message_thread_id
return _make_request(token, method_url, params=payload, method='post')


def answer_chat_join_request_query(token, query_id, result):
method_url = 'answerChatJoinRequestQuery'
payload = {'query_id': query_id, 'result': result.to_json()}
return _make_request(token, method_url, params=payload, method='post')


def send_chat_join_request_web_app(token, query_id, web_app_url):
method_url = 'sendChatJoinRequestWebApp'
payload = {'query_id': query_id, 'web_app_url': web_app_url}
return _make_request(token, method_url, params=payload, method='post')


def get_user_chat_boosts(token, chat_id, user_id):
method_url = 'getUserChatBoosts'
payload = {'chat_id': chat_id, 'user_id': user_id}
Expand Down
107 changes: 105 additions & 2 deletions telebot/async_telebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7260,7 +7260,8 @@ async def edit_message_text(
reply_markup: Optional[types.InlineKeyboardMarkup]=None,
link_preview_options: Optional[types.LinkPreviewOptions]=None,
business_connection_id: Optional[str]=None,
timeout: Optional[int]=None) -> Union[types.Message, bool]:
timeout: Optional[int]=None,
rich_message: Optional[types.InputRichMessage]=None) -> Union[types.Message, bool]:
"""
Use this method to edit text and game messages.
Expand Down Expand Up @@ -7325,7 +7326,7 @@ async def edit_message_text(

result = await asyncio_helper.edit_message_text(
self.token, text, chat_id, message_id, inline_message_id, parse_mode, entities, reply_markup,
link_preview_options, business_connection_id, timeout)
link_preview_options, business_connection_id, timeout, rich_message)
if isinstance(result, bool): # if edit inline message return is bool not Message.
return result
return types.Message.de_json(result)
Expand Down Expand Up @@ -8475,6 +8476,108 @@ async def answer_guest_query(self, guest_query_id: str, result: types.InlineQuer
"""
return types.SentGuestMessage.de_json(await asyncio_helper.answer_guest_query(self.token, guest_query_id, result))


async def send_rich_message(
self, chat_id: Union[int, str],
rich_message: types.InputRichMessage,
message_thread_id: Optional[int]=None,
reply_markup: Optional[types.InlineKeyboardMarkup]=None,
disable_notification: Optional[bool]=None,
protect_content: Optional[bool]=None,
reply_parameters: Optional[types.ReplyParameters]=None,
business_connection_id: Optional[str]=None) -> types.Message:
"""
Use this method to send a rich formatted message. On success, the sent Message is returned.
Telegram documentation: https://core.telegram.org/bots/api#sendrichmessage
:param chat_id: Unique identifier for the target chat or username of the target channel
:type chat_id: :obj:`int` or :obj:`str`
:param rich_message: A JSON-serialized object for the rich message content
:type rich_message: :class:`telebot.types.InputRichMessage`
:return: On success, the sent Message is returned.
:rtype: :class:`telebot.types.Message`
"""
return types.Message.de_json(
await asyncio_helper.send_rich_message(
self.token, chat_id, rich_message,
message_thread_id=message_thread_id,
reply_markup=reply_markup,
disable_notification=disable_notification,
protect_content=protect_content,
reply_parameters=reply_parameters,
business_connection_id=business_connection_id))


async def send_rich_message_draft(
self, chat_id: int,
draft_id: int,
rich_message: types.InputRichMessage,
message_thread_id: Optional[int]=None) -> bool:
"""
Use this method to stream a partial rich message to a user while the message is being generated.
Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#sendrichmessagedraft
:param chat_id: Unique identifier for the target private chat
:type chat_id: :obj:`int`
:param draft_id: Unique identifier of the message draft; must be non-zero
:type draft_id: :obj:`int`
:param rich_message: A JSON-serialized object for the rich message draft content
:type rich_message: :class:`telebot.types.InputRichMessage`
:return: Returns True on success.
:rtype: :obj:`bool`
"""
return await asyncio_helper.send_rich_message_draft(
self.token, chat_id, draft_id, rich_message, message_thread_id=message_thread_id)


async def answer_chat_join_request_query(
self, query_id: str,
result: types.InlineQueryResultBase) -> bool:
"""
Use this method to handle a join request query with a custom response. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#answerchatjoinrequestquery
:param query_id: Unique identifier of the join request query
:type query_id: :obj:`str`
:param result: A JSON-serialized object describing the response to send
:type result: :class:`telebot.types.InlineQueryResultBase`
:return: Returns True on success.
:rtype: :obj:`bool`
"""
return await asyncio_helper.answer_chat_join_request_query(self.token, query_id, result)


async def send_chat_join_request_web_app(
self, query_id: str,
web_app_url: str) -> bool:
"""
Use this method to trigger a Web App in response to a join request query. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#sendchatjoinrequestwebapp
:param query_id: Unique identifier of the join request query
:type query_id: :obj:`str`
:param web_app_url: URL of the Web App to be opened
:type web_app_url: :obj:`str`
:return: Returns True on success.
:rtype: :obj:`bool`
"""
return await asyncio_helper.send_chat_join_request_web_app(self.token, query_id, web_app_url)


async def get_user_chat_boosts(self, chat_id: Union[int, str], user_id: int) -> types.UserChatBoosts:
"""
Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object.
Expand Down
Loading