X Tutup
Skip to content
Merged
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The following wonderful people contributed directly or indirectly to this projec

- `Avanatiker <https://github.com/Avanatiker>`_
- `bimmlerd <https://github.com/bimmlerd>`_
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
- `franciscod <https://github.com/franciscod>`_
- `JASON0916 <https://github.com/JASON0916>`_
- `JRoot3D <https://github.com/JRoot3D>`_
Expand Down
38 changes: 38 additions & 0 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def forwardMessage(self,
def sendPhoto(self,
chat_id,
photo,
filename=None,
caption=None,
**kwargs):
"""Use this method to send photos.
Expand All @@ -263,6 +264,9 @@ def sendPhoto(self,
Photo to send. You can either pass a file_id as String to resend a
photo that is already on the Telegram servers, or upload a new
photo using multipart/form-data.
filename:
File name that shows in telegram message (it is usefull when you
send file generated by temp module, for example). [Optional]
caption:
Photo caption (may also be used when resending photos by file_id).
[Optional]
Expand All @@ -282,6 +286,8 @@ def sendPhoto(self,
data = {'chat_id': chat_id,
'photo': photo}

if filename:
data['filename'] = filename
if caption:
data['caption'] = caption

Expand All @@ -292,6 +298,7 @@ def sendPhoto(self,
def sendAudio(self,
chat_id,
audio,
filename=None,
duration=None,
performer=None,
title=None,
Expand All @@ -314,6 +321,9 @@ def sendAudio(self,
Audio file to send. You can either pass a file_id as String to
resend an audio that is already on the Telegram servers, or upload
a new audio file using multipart/form-data.
filename:
File name that shows in telegram message (it is usefull when you
send file generated by temp module, for example). [Optional]
duration:
Duration of sent audio in seconds. [Optional]
performer:
Expand All @@ -336,6 +346,8 @@ def sendAudio(self,
data = {'chat_id': chat_id,
'audio': audio}

if filename:
data['filename'] = filename
if duration:
data['duration'] = duration
if performer:
Expand All @@ -350,6 +362,7 @@ def sendAudio(self,
def sendDocument(self,
chat_id,
document,
filename=None,
**kwargs):
"""Use this method to send general files.

Expand All @@ -360,6 +373,9 @@ def sendDocument(self,
File to send. You can either pass a file_id as String to resend a
file that is already on the Telegram servers, or upload a new file
using multipart/form-data.
filename:
File name that shows in telegram message (it is usefull when you
send file generated by temp module, for example). [Optional]
reply_to_message_id:
If the message is a reply, ID of the original message. [Optional]
reply_markup:
Expand All @@ -376,13 +392,17 @@ def sendDocument(self,
data = {'chat_id': chat_id,
'document': document}

if filename:
data['filename'] = filename

return url, data

@log
@message
def sendSticker(self,
chat_id,
sticker,
filename=None,
**kwargs):
"""Use this method to send .webp stickers.

Expand All @@ -393,6 +413,9 @@ def sendSticker(self,
Sticker to send. You can either pass a file_id as String to resend
a sticker that is already on the Telegram servers, or upload a new
sticker using multipart/form-data.
filename:
File name that shows in telegram message (it is usefull when you
send file generated by temp module, for example). [Optional]
reply_to_message_id:
If the message is a reply, ID of the original message. [Optional]
reply_markup:
Expand All @@ -409,13 +432,17 @@ def sendSticker(self,
data = {'chat_id': chat_id,
'sticker': sticker}

if filename:
data['filename'] = filename

return url, data

@log
@message
def sendVideo(self,
chat_id,
video,
filename=None,
duration=None,
caption=None,
**kwargs):
Expand All @@ -429,6 +456,9 @@ def sendVideo(self,
Video to send. You can either pass a file_id as String to resend a
video that is already on the Telegram servers, or upload a new
video file using multipart/form-data.
filename:
File name that shows in telegram message (it is usefull when you
send file generated by temp module, for example). [Optional]
duration:
Duration of sent video in seconds. [Optional]
caption:
Expand All @@ -450,6 +480,8 @@ def sendVideo(self,
data = {'chat_id': chat_id,
'video': video}

if filename:
data['filename'] = filename
if duration:
data['duration'] = duration
if caption:
Expand All @@ -462,6 +494,7 @@ def sendVideo(self,
def sendVoice(self,
chat_id,
voice,
filename=None,
duration=None,
**kwargs):
"""Use this method to send audio files, if you want Telegram clients to
Expand All @@ -478,6 +511,9 @@ def sendVoice(self,
Audio file to send. You can either pass a file_id as String to
resend an audio that is already on the Telegram servers, or upload
a new audio file using multipart/form-data.
filename:
File name that shows in telegram message (it is usefull when you
send file generated by temp module, for example). [Optional]
duration:
Duration of sent audio in seconds. [Optional]
reply_to_message_id:
Expand All @@ -496,6 +532,8 @@ def sendVoice(self,
data = {'chat_id': chat_id,
'voice': voice}

if filename:
data['filename'] = filename
if duration:
data['duration'] = duration

Expand Down
5 changes: 4 additions & 1 deletion telegram/inputfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ def __init__(self,

if isinstance(self.input_file, file):
self.input_file_content = self.input_file.read()
self.filename = os.path.basename(self.input_file.name)
if 'filename' in self.data:
self.filename = self.data.pop('filename')
else:
self.filename = os.path.basename(self.input_file.name)
self.mimetype = mimetypes.guess_type(self.filename)[0] or \
DEFAULT_MIME_TYPE

Expand Down
X Tutup