Skip to content

Commit 5bd1537

Browse files
Added the method approveSuggestedPost, allowing bots to approve incoming suggested posts. Added the method declineSuggestedPost, allowing bots to decline incoming suggested posts.
1 parent 9a44dba commit 5bd1537

4 files changed

Lines changed: 118 additions & 0 deletions

File tree

telebot/__init__.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,51 @@ def copy_message(
20082008
video_start_timestamp=video_start_timestamp, direct_messages_topic_id=direct_messages_topic_id,
20092009
suggested_post_parameters=suggested_post_parameters
20102010
))
2011+
2012+
2013+
def approve_suggested_post(self, chat_id: Union[int, str], message_id: int, send_date: Optional[int]=None) -> bool:
2014+
"""
2015+
Use this method to approve a suggested post in a direct messages chat. The bot must have the 'can_post_messages' administrator right in the corresponding channel chat. Returns True on success.
2016+
2017+
Telegram documentation: https://core.telegram.org/bots/api#approvesuggestedpost
2018+
2019+
:param chat_id: Unique identifier for the target direct messages chat
2020+
:type chat_id: :obj:`int` or :obj:`str`
2021+
2022+
:param message_id: Identifier of a suggested post message to approve
2023+
:type message_id: :obj:`int`
2024+
2025+
:param send_date: Point in time (Unix timestamp) when the post is expected to be published; omit if the date has already been specified when the suggested post was created.
2026+
If specified, then the date must be not more than 2678400 seconds (30 days) in the future
2027+
:type send_date: :obj:`int`
2028+
2029+
:return: Returns True on success.
2030+
:rtype: :obj:`bool`
2031+
"""
2032+
return apihelper.approve_suggested_post(self.token, chat_id, message_id,
2033+
send_date=send_date)
2034+
2035+
def decline_suggested_post(self, chat_id: Union[int, str], message_id: int, comment: Optional[str]=None) -> bool:
2036+
"""
2037+
Use this method to decline a suggested post in a direct messages chat. The bot must have
2038+
the 'can_manage_direct_messages' administrator right in the corresponding channel chat. Returns True on success.
2039+
2040+
Telegram documentation: https://core.telegram.org/bots/api#declinesuggestedpost
2041+
2042+
:param chat_id: Unique identifier for the target direct messages chat
2043+
:type chat_id: :obj:`int` or :obj:`str`
2044+
2045+
:param message_id: Identifier of a suggested post message to decline
2046+
:type message_id: :obj:`int`
2047+
2048+
:param comment: Comment for the creator of the suggested post; 0-128 characters
2049+
:type comment: :obj:`str`
2050+
2051+
:return: Returns True on success.
2052+
:rtype: :obj:`bool`
2053+
"""
2054+
return apihelper.decline_suggested_post(self.token, chat_id, message_id,
2055+
comment=comment)
20112056

20122057
def delete_message(self, chat_id: Union[int, str], message_id: int,
20132058
timeout: Optional[int]=None) -> bool:

telebot/apihelper.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,20 @@ def edit_message_reply_markup(
16911691
payload['timeout'] = timeout
16921692
return _make_request(token, method_url, params=payload, method='post')
16931693

1694+
def approve_suggested_post(token, chat_id, message_id, send_date=None):
1695+
method_url = r'approveSuggestedPost'
1696+
payload = {'chat_id': chat_id, 'message_id': message_id}
1697+
if send_date is not None:
1698+
payload['send_date'] = send_date
1699+
return _make_request(token, method_url, params=payload, method='post')
1700+
1701+
def decline_suggested_post(token, chat_id, message_id, comment=None):
1702+
method_url = r'declineSuggestedPost'
1703+
payload = {'chat_id': chat_id, 'message_id': message_id}
1704+
if comment is not None:
1705+
payload['comment'] = comment
1706+
return _make_request(token, method_url, params=payload, method='post')
1707+
16941708

16951709
def delete_message(token, chat_id, message_id, timeout=None):
16961710
method_url = r'deleteMessage'

telebot/async_telebot.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3536,6 +3536,50 @@ async def copy_message(
35363536
direct_messages_topic_id=direct_messages_topic_id, suggested_post_parameters=suggested_post_parameters
35373537
)
35383538
)
3539+
3540+
async def approve_suggested_post(self, chat_id: Union[int, str], message_id: int, send_date: Optional[int]=None) -> bool:
3541+
"""
3542+
Use this method to approve a suggested post in a direct messages chat. The bot must have the 'can_post_messages' administrator right in the corresponding channel chat. Returns True on success.
3543+
3544+
Telegram documentation: https://core.telegram.org/bots/api#approvesuggestedpost
3545+
3546+
:param chat_id: Unique identifier for the target direct messages chat
3547+
:type chat_id: :obj:`int` or :obj:`str`
3548+
3549+
:param message_id: Identifier of a suggested post message to approve
3550+
:type message_id: :obj:`int`
3551+
3552+
:param send_date: Point in time (Unix timestamp) when the post is expected to be published; omit if the date has already been specified when the suggested post was created.
3553+
If specified, then the date must be not more than 2678400 seconds (30 days) in the future
3554+
:type send_date: :obj:`int`
3555+
3556+
:return: Returns True on success.
3557+
:rtype: :obj:`bool`
3558+
"""
3559+
return await asyncio_helper.approve_suggested_post(self.token, chat_id, message_id,
3560+
send_date=send_date)
3561+
3562+
async def decline_suggested_post(self, chat_id: Union[int, str], message_id: int, comment: Optional[str]=None) -> bool:
3563+
"""
3564+
Use this method to decline a suggested post in a direct messages chat. The bot must have
3565+
the 'can_manage_direct_messages' administrator right in the corresponding channel chat. Returns True on success.
3566+
3567+
Telegram documentation: https://core.telegram.org/bots/api#declinesuggestedpost
3568+
3569+
:param chat_id: Unique identifier for the target direct messages chat
3570+
:type chat_id: :obj:`int` or :obj:`str`
3571+
3572+
:param message_id: Identifier of a suggested post message to decline
3573+
:type message_id: :obj:`int`
3574+
3575+
:param comment: Comment for the creator of the suggested post; 0-128 characters
3576+
:type comment: :obj:`str`
3577+
3578+
:return: Returns True on success.
3579+
:rtype: :obj:`bool`
3580+
"""
3581+
return await asyncio_helper.decline_suggested_post(self.token, chat_id, message_id,
3582+
comment=comment)
35393583

35403584
async def delete_message(self, chat_id: Union[int, str], message_id: int,
35413585
timeout: Optional[int]=None) -> bool:

telebot/asyncio_helper.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,21 @@ async def edit_message_reply_markup(
16861686
payload['timeout'] = timeout
16871687
return await _process_request(token, method_url, params=payload, method='post')
16881688

1689+
1690+
async def approve_suggested_post(token, chat_id, message_id, send_date=None):
1691+
method_url = r'approveSuggestedPost'
1692+
payload = {'chat_id': chat_id, 'message_id': message_id}
1693+
if send_date is not None:
1694+
payload['send_date'] = send_date
1695+
return await _process_request(token, method_url, params=payload, method='post')
1696+
1697+
1698+
async def decline_suggested_post(token, chat_id, message_id, comment=None):
1699+
method_url = r'declineSuggestedPost'
1700+
payload = {'chat_id': chat_id, 'message_id': message_id}
1701+
if comment is not None:
1702+
payload['comment'] = comment
1703+
return await _process_request(token, method_url, params=payload, method='post')
16891704

16901705
async def delete_message(token, chat_id, message_id, timeout=None):
16911706
method_url = r'deleteMessage'

0 commit comments

Comments
 (0)