From 38c4c21030f31d3e901adcb2c44e76e3a8dca79c Mon Sep 17 00:00:00 2001 From: Vlad Galatskiy Date: Sun, 27 Jun 2021 11:37:27 +0300 Subject: [PATCH 1/5] Add file_name argument to send_data method --- telebot/apihelper.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 867eef8..9566444 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -810,12 +810,15 @@ def send_audio(token, chat_id, audio, caption=None, duration=None, performer=Non def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None, parse_mode=None, disable_notification=None, timeout=None, caption=None, thumb=None, caption_entities=None, - allow_sending_without_reply=None, disable_content_type_detection=None): + allow_sending_without_reply=None, disable_content_type_detection=None, file_name=None): method_url = get_method_by_type(data_type) payload = {'chat_id': chat_id} files = None if not util.is_string(data): - files = {data_type: data} + file_data = data + if file_name is not None: + file_data = (file_name, data) + files = {data_type: file_data} else: payload[data_type] = data if reply_to_message_id: From e56f134a7c27ce01dd61905909af06ecd2115a13 Mon Sep 17 00:00:00 2001 From: Vlad Galatskiy Date: Sun, 27 Jun 2021 11:38:45 +0300 Subject: [PATCH 2/5] Add file_name support to send_document method --- telebot/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index f06ee73..dbe2765 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1114,7 +1114,8 @@ class TeleBot: timeout: Optional[int]=None, thumb: Optional[Union[Any, str]]=None, caption_entities: Optional[List[types.MessageEntity]]=None, - allow_sending_without_reply: Optional[bool]=None) -> types.Message: + allow_sending_without_reply: Optional[bool]=None, + file_name: Optional[str]=None) -> types.Message: """ Use this method to send general files. :param chat_id: @@ -1128,6 +1129,7 @@ class TeleBot: :param thumb: InputFile or String : Thumbnail of the file sent :param caption_entities: :param allow_sending_without_reply: + :param file_name: :return: API reply. """ parse_mode = self.parse_mode if (parse_mode is None) else parse_mode @@ -1136,7 +1138,7 @@ class TeleBot: apihelper.send_data( self.token, chat_id, data, 'document', reply_to_message_id, reply_markup, parse_mode, disable_notification, timeout, caption, thumb, caption_entities, - allow_sending_without_reply)) + allow_sending_without_reply, file_name)) def send_sticker( self, chat_id: Union[int, str], data: Union[Any, str], From a791ff4e46c2496920863fc5f678f1e4df8352ad Mon Sep 17 00:00:00 2001 From: Vlad Galatskiy Date: Sun, 27 Jun 2021 11:58:33 +0300 Subject: [PATCH 3/5] Add tests for file sending with name --- tests/test_telebot.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_telebot.py b/tests/test_telebot.py index a22adcd..377bd72 100644 --- a/tests/test_telebot.py +++ b/tests/test_telebot.py @@ -126,6 +126,16 @@ class TestTeleBot: ret_msg = tb.send_document(CHAT_ID, ret_msg.document.file_id) assert ret_msg.message_id + def test_send_file_with_filename(self): + file_data = open('../examples/detailed_example/kitten.jpg', 'rb') + tb = telebot.TeleBot(TOKEN) + + ret_msg = tb.send_document(CHAT_ID, file_data) + assert ret_msg.message_id + + ret_msg = tb.send_document(CHAT_ID, file_data, file_name="test.jpg") + assert ret_msg.message_id + def test_send_file_dis_noti(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') tb = telebot.TeleBot(TOKEN) From 60bb63ab2b48ae084349eedab854bf62c61d02c4 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Mon, 28 Jun 2021 12:41:15 +0300 Subject: [PATCH 4/5] Release 3.8.1 - bugfix --- telebot/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/version.py b/telebot/version.py index 54c4c5d..b74c7d3 100644 --- a/telebot/version.py +++ b/telebot/version.py @@ -1,3 +1,3 @@ # Versions should comply with PEP440. # This line is parsed in setup.py: -__version__ = '3.8.0' +__version__ = '3.8.1' From a4e73a05c6ea2696483b756c8e135f690f369235 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Tue, 29 Jun 2021 13:30:01 +0300 Subject: [PATCH 5/5] Update file_name to visible_file_name in send_document --- telebot/__init__.py | 6 +++--- telebot/apihelper.py | 6 +++--- tests/test_telebot.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index f1a1e6d..fbd9545 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1124,7 +1124,7 @@ class TeleBot: thumb: Optional[Union[Any, str]]=None, caption_entities: Optional[List[types.MessageEntity]]=None, allow_sending_without_reply: Optional[bool]=None, - file_name: Optional[str]=None) -> types.Message: + visible_file_name: Optional[str]=None) -> types.Message: """ Use this method to send general files. :param chat_id: @@ -1138,7 +1138,7 @@ class TeleBot: :param thumb: InputFile or String : Thumbnail of the file sent :param caption_entities: :param allow_sending_without_reply: - :param file_name: + :param visible_file_name: allows to define file name that will be visible in the Telegram instead of original file name :return: API reply. """ parse_mode = self.parse_mode if (parse_mode is None) else parse_mode @@ -1147,7 +1147,7 @@ class TeleBot: apihelper.send_data( self.token, chat_id, data, 'document', reply_to_message_id, reply_markup, parse_mode, disable_notification, timeout, caption, thumb, caption_entities, - allow_sending_without_reply, file_name)) + allow_sending_without_reply, visible_file_name)) def send_sticker( self, chat_id: Union[int, str], data: Union[Any, str], diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 82f43e4..177279f 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -806,14 +806,14 @@ def send_audio(token, chat_id, audio, caption=None, duration=None, performer=Non def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None, parse_mode=None, disable_notification=None, timeout=None, caption=None, thumb=None, caption_entities=None, - allow_sending_without_reply=None, disable_content_type_detection=None, file_name=None): + allow_sending_without_reply=None, disable_content_type_detection=None, visible_file_name=None): method_url = get_method_by_type(data_type) payload = {'chat_id': chat_id} files = None if not util.is_string(data): file_data = data - if file_name is not None: - file_data = (file_name, data) + if visible_file_name: + file_data = (visible_file_name, data) files = {data_type: file_data} else: payload[data_type] = data diff --git a/tests/test_telebot.py b/tests/test_telebot.py index c50c25a..1a37af8 100644 --- a/tests/test_telebot.py +++ b/tests/test_telebot.py @@ -133,7 +133,7 @@ class TestTeleBot: ret_msg = tb.send_document(CHAT_ID, file_data) assert ret_msg.message_id - ret_msg = tb.send_document(CHAT_ID, file_data, file_name="test.jpg") + ret_msg = tb.send_document(CHAT_ID, file_data, visible_file_name="test.jpg") assert ret_msg.message_id def test_send_file_dis_noti(self):