Skip to content

Commit

Permalink
Merge branch 'master' into badge
Browse files Browse the repository at this point in the history
  • Loading branch information
coder2020official authored Aug 11, 2024
2 parents a0b0b9b + 96761f8 commit 612eda0
Show file tree
Hide file tree
Showing 8 changed files with 704 additions and 607 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
copyright = f'2022-{datetime.now().year}, {author}'

# The full version, including alpha/beta/rc tags
release = '4.21.0'
release = '4.22.0'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "pyTelegramBotAPI"
version = "4.21.0"
version = "4.22.0"
description = "Python Telegram bot api."
authors = [{name = "eternnoir", email = "[email protected]"}]
license = {text = "GPL2"}
Expand Down
18 changes: 13 additions & 5 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# random module to generate random string
import random
import string
import copy

import ssl

Expand Down Expand Up @@ -4640,7 +4641,7 @@ def set_chat_description(self, chat_id: Union[int, str], description: Optional[s

def pin_chat_message(
self, chat_id: Union[int, str], message_id: int,
disable_notification: Optional[bool]=False) -> bool:
disable_notification: Optional[bool]=False, business_connection_id: Optional[str]=None) -> bool:
"""
Use this method to pin a message in a supergroup.
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Expand All @@ -4659,15 +4660,19 @@ def pin_chat_message(
to all group members about the new pinned message
:type disable_notification: :obj:`bool`
:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`
:return: True on success.
:rtype: :obj:`bool`
"""
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification

return apihelper.pin_chat_message(self.token, chat_id, message_id, disable_notification=disable_notification)
return apihelper.pin_chat_message(self.token, chat_id, message_id, disable_notification=disable_notification,
business_connection_id=business_connection_id)


def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int]=None) -> bool:
def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int]=None, business_connection_id: Optional[str]=None) -> bool:
"""
Use this method to unpin specific pinned message in a supergroup chat.
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Expand All @@ -4682,10 +4687,13 @@ def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int]
:param message_id: Int: Identifier of a message to unpin
:type message_id: :obj:`int`
:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`
:return: True on success.
:rtype: :obj:`bool`
"""
return apihelper.unpin_chat_message(self.token, chat_id, message_id)
return apihelper.unpin_chat_message(self.token, chat_id, message_id, business_connection_id=business_connection_id)


def unpin_all_chat_messages(self, chat_id: Union[int, str]) -> bool:
Expand Down Expand Up @@ -8749,7 +8757,7 @@ def _run_middlewares_and_handler(self, message, handlers, middlewares, update_ty
logger.error("It is not allowed to pass data and values inside data to the handler. Check your handler: {}".format(handler['function']))
return
else:
data_copy = data.copy()
data_copy = copy.deepcopy(data)
for key in list(data_copy):
# remove data from data_copy if handler does not accept it
if key not in params:
Expand Down
8 changes: 6 additions & 2 deletions telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,19 +1386,23 @@ def set_chat_description(token, chat_id, description):
return _make_request(token, method_url, params=payload, method='post')


def pin_chat_message(token, chat_id, message_id, disable_notification=None):
def pin_chat_message(token, chat_id, message_id, disable_notification=None, business_connection_id=None):
method_url = 'pinChatMessage'
payload = {'chat_id': chat_id, 'message_id': message_id}
if disable_notification is not None:
payload['disable_notification'] = disable_notification
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return _make_request(token, method_url, params=payload, method='post')


def unpin_chat_message(token, chat_id, message_id):
def unpin_chat_message(token, chat_id, message_id, business_connection_id=None):
method_url = 'unpinChatMessage'
payload = {'chat_id': chat_id}
if message_id:
payload['message_id'] = message_id
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return _make_request(token, method_url, params=payload, method='post')


Expand Down
18 changes: 12 additions & 6 deletions telebot/async_telebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import string
import random
import ssl

import copy

"""
Module : telebot
Expand Down Expand Up @@ -558,7 +558,7 @@ async def _run_middlewares_and_handlers(self, message, handlers, middlewares, up
logger.error("It is not allowed to pass data and values inside data to the handler. Check your handler: {}".format(handler['function']))
return
else:
data_copy = data.copy()
data_copy = copy.deepcopy(data)
for key in list(data_copy):
# remove data from data_copy if handler does not accept it
if key not in params:
Expand Down Expand Up @@ -6023,7 +6023,7 @@ async def set_chat_description(self, chat_id: Union[int, str], description: Opti

async def pin_chat_message(
self, chat_id: Union[int, str], message_id: int,
disable_notification: Optional[bool]=False) -> bool:
disable_notification: Optional[bool]=False, business_connection_id: Optional[str]=None) -> bool:
"""
Use this method to pin a message in a supergroup.
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Expand All @@ -6042,14 +6042,17 @@ async def pin_chat_message(
to all group members about the new pinned message
:type disable_notification: :obj:`bool`
:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`
:return: True on success.
:rtype: :obj:`bool`
"""
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification

return await asyncio_helper.pin_chat_message(self.token, chat_id, message_id, disable_notification)
return await asyncio_helper.pin_chat_message(self.token, chat_id, message_id, disable_notification, business_connection_id)

async def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int]=None) -> bool:
async def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int]=None, business_connection_id: Optional[str]=None) -> bool:
"""
Use this method to unpin specific pinned message in a supergroup chat.
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Expand All @@ -6064,10 +6067,13 @@ async def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optiona
:param message_id: Int: Identifier of a message to unpin
:type message_id: :obj:`int`
:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`
:return: True on success.
:rtype: :obj:`bool`
"""
return await asyncio_helper.unpin_chat_message(self.token, chat_id, message_id)
return await asyncio_helper.unpin_chat_message(self.token, chat_id, message_id, business_connection_id)

async def unpin_all_chat_messages(self, chat_id: Union[int, str]) -> bool:
"""
Expand Down
8 changes: 6 additions & 2 deletions telebot/asyncio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,19 +1365,23 @@ async def set_chat_description(token, chat_id, description):
return await _process_request(token, method_url, params=payload, method='post')


async def pin_chat_message(token, chat_id, message_id, disable_notification=None):
async def pin_chat_message(token, chat_id, message_id, disable_notification=None, business_connection_id=None):
method_url = 'pinChatMessage'
payload = {'chat_id': chat_id, 'message_id': message_id}
if disable_notification is not None:
payload['disable_notification'] = disable_notification
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return await _process_request(token, method_url, params=payload, method='post')


async def unpin_chat_message(token, chat_id, message_id):
async def unpin_chat_message(token, chat_id, message_id, business_connection_id=None):
method_url = 'unpinChatMessage'
payload = {'chat_id': chat_id}
if message_id:
payload['message_id'] = message_id
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return await _process_request(token, method_url, params=payload, method='post')


Expand Down
Loading

0 comments on commit 612eda0

Please sign in to comment.