Skip to content

Commit ce24aa2

Browse files
committed
1 parent a0f2508 commit ce24aa2

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

telebot/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def send_voice(self, chat_id, voice, duration=None, reply_to_message_id=None, re
365365
apihelper.send_voice(self.token, chat_id, voice, duration, reply_to_message_id, reply_markup,
366366
disable_notification, timeout))
367367

368-
def send_document(self, chat_id, data, reply_to_message_id=None, reply_markup=None, disable_notification=None, timeout=None):
368+
def send_document(self, chat_id, data, reply_to_message_id=None, caption=None, reply_markup=None, disable_notification=None, timeout=None):
369369
"""
370370
Use this method to send general files.
371371
:param chat_id:
@@ -376,7 +376,7 @@ def send_document(self, chat_id, data, reply_to_message_id=None, reply_markup=No
376376
"""
377377
return types.Message.de_json(
378378
apihelper.send_data(self.token, chat_id, data, 'document', reply_to_message_id, reply_markup,
379-
disable_notification, timeout))
379+
disable_notification, timeout, caption=caption))
380380

381381
def send_sticker(self, chat_id, data, reply_to_message_id=None, reply_markup=None, disable_notification=None, timeout=None):
382382
"""

telebot/apihelper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ def send_audio(token, chat_id, audio, duration=None, performer=None, title=None,
298298
return _make_request(token, method_url, params=payload, files=files, method='post')
299299

300300

301-
def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None, disable_notification=None, timeout=None):
301+
def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None, disable_notification=None,
302+
timeout=None, caption=None):
302303
method_url = get_method_by_type(data_type)
303304
payload = {'chat_id': chat_id}
304305
files = None
@@ -314,6 +315,8 @@ def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_m
314315
payload['disable_notification'] = disable_notification
315316
if timeout:
316317
payload['connect-timeout'] = timeout
318+
if caption:
319+
payload['caption'] = caption
317320
return _make_request(token, method_url, params=payload, files=files, method='post')
318321

319322

tests/test_telebot.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ def test_send_file_dis_noti(self):
129129
ret_msg = tb.send_document(CHAT_ID, ret_msg.document.file_id)
130130
assert ret_msg.message_id
131131

132+
def test_send_file_caption(self):
133+
file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
134+
tb = telebot.TeleBot(TOKEN)
135+
ret_msg = tb.send_document(CHAT_ID, file_data, caption="Test")
136+
assert ret_msg.message_id
137+
138+
ret_msg = tb.send_document(CHAT_ID, ret_msg.document.file_id)
139+
assert ret_msg.message_id
140+
132141
def test_send_video(self):
133142
file_data = open('./test_data/test_video.mp4', 'rb')
134143
tb = telebot.TeleBot(TOKEN)

0 commit comments

Comments
 (0)