mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-29 09:40:31 +01:00
Merge pull request #57 from ergoz/testing
Add ability for custom filename in send methods and InputFile
This commit is contained in:
commit
ed77afaab9
3 changed files with 43 additions and 1 deletions
|
@ -10,6 +10,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
||||||
|
|
||||||
- `Avanatiker <https://github.com/Avanatiker>`_
|
- `Avanatiker <https://github.com/Avanatiker>`_
|
||||||
- `bimmlerd <https://github.com/bimmlerd>`_
|
- `bimmlerd <https://github.com/bimmlerd>`_
|
||||||
|
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
|
||||||
- `franciscod <https://github.com/franciscod>`_
|
- `franciscod <https://github.com/franciscod>`_
|
||||||
- `JASON0916 <https://github.com/JASON0916>`_
|
- `JASON0916 <https://github.com/JASON0916>`_
|
||||||
- `JRoot3D <https://github.com/JRoot3D>`_
|
- `JRoot3D <https://github.com/JRoot3D>`_
|
||||||
|
|
|
@ -252,6 +252,7 @@ class Bot(TelegramObject):
|
||||||
def sendPhoto(self,
|
def sendPhoto(self,
|
||||||
chat_id,
|
chat_id,
|
||||||
photo,
|
photo,
|
||||||
|
filename=None,
|
||||||
caption=None,
|
caption=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""Use this method to send photos.
|
"""Use this method to send photos.
|
||||||
|
@ -263,6 +264,9 @@ class Bot(TelegramObject):
|
||||||
Photo to send. You can either pass a file_id as String to resend a
|
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 that is already on the Telegram servers, or upload a new
|
||||||
photo using multipart/form-data.
|
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:
|
caption:
|
||||||
Photo caption (may also be used when resending photos by file_id).
|
Photo caption (may also be used when resending photos by file_id).
|
||||||
[Optional]
|
[Optional]
|
||||||
|
@ -282,6 +286,8 @@ class Bot(TelegramObject):
|
||||||
data = {'chat_id': chat_id,
|
data = {'chat_id': chat_id,
|
||||||
'photo': photo}
|
'photo': photo}
|
||||||
|
|
||||||
|
if filename:
|
||||||
|
data['filename'] = filename
|
||||||
if caption:
|
if caption:
|
||||||
data['caption'] = caption
|
data['caption'] = caption
|
||||||
|
|
||||||
|
@ -292,6 +298,7 @@ class Bot(TelegramObject):
|
||||||
def sendAudio(self,
|
def sendAudio(self,
|
||||||
chat_id,
|
chat_id,
|
||||||
audio,
|
audio,
|
||||||
|
filename=None,
|
||||||
duration=None,
|
duration=None,
|
||||||
performer=None,
|
performer=None,
|
||||||
title=None,
|
title=None,
|
||||||
|
@ -314,6 +321,9 @@ class Bot(TelegramObject):
|
||||||
Audio file to send. You can either pass a file_id as String to
|
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
|
resend an audio that is already on the Telegram servers, or upload
|
||||||
a new audio file using multipart/form-data.
|
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:
|
||||||
Duration of sent audio in seconds. [Optional]
|
Duration of sent audio in seconds. [Optional]
|
||||||
performer:
|
performer:
|
||||||
|
@ -336,6 +346,8 @@ class Bot(TelegramObject):
|
||||||
data = {'chat_id': chat_id,
|
data = {'chat_id': chat_id,
|
||||||
'audio': audio}
|
'audio': audio}
|
||||||
|
|
||||||
|
if filename:
|
||||||
|
data['filename'] = filename
|
||||||
if duration:
|
if duration:
|
||||||
data['duration'] = duration
|
data['duration'] = duration
|
||||||
if performer:
|
if performer:
|
||||||
|
@ -350,6 +362,7 @@ class Bot(TelegramObject):
|
||||||
def sendDocument(self,
|
def sendDocument(self,
|
||||||
chat_id,
|
chat_id,
|
||||||
document,
|
document,
|
||||||
|
filename=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""Use this method to send general files.
|
"""Use this method to send general files.
|
||||||
|
|
||||||
|
@ -360,6 +373,9 @@ class Bot(TelegramObject):
|
||||||
File to send. You can either pass a file_id as String to resend a
|
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
|
file that is already on the Telegram servers, or upload a new file
|
||||||
using multipart/form-data.
|
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:
|
reply_to_message_id:
|
||||||
If the message is a reply, ID of the original message. [Optional]
|
If the message is a reply, ID of the original message. [Optional]
|
||||||
reply_markup:
|
reply_markup:
|
||||||
|
@ -376,6 +392,9 @@ class Bot(TelegramObject):
|
||||||
data = {'chat_id': chat_id,
|
data = {'chat_id': chat_id,
|
||||||
'document': document}
|
'document': document}
|
||||||
|
|
||||||
|
if filename:
|
||||||
|
data['filename'] = filename
|
||||||
|
|
||||||
return url, data
|
return url, data
|
||||||
|
|
||||||
@log
|
@log
|
||||||
|
@ -383,6 +402,7 @@ class Bot(TelegramObject):
|
||||||
def sendSticker(self,
|
def sendSticker(self,
|
||||||
chat_id,
|
chat_id,
|
||||||
sticker,
|
sticker,
|
||||||
|
filename=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""Use this method to send .webp stickers.
|
"""Use this method to send .webp stickers.
|
||||||
|
|
||||||
|
@ -393,6 +413,9 @@ class Bot(TelegramObject):
|
||||||
Sticker to send. You can either pass a file_id as String to resend
|
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
|
a sticker that is already on the Telegram servers, or upload a new
|
||||||
sticker using multipart/form-data.
|
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:
|
reply_to_message_id:
|
||||||
If the message is a reply, ID of the original message. [Optional]
|
If the message is a reply, ID of the original message. [Optional]
|
||||||
reply_markup:
|
reply_markup:
|
||||||
|
@ -409,6 +432,9 @@ class Bot(TelegramObject):
|
||||||
data = {'chat_id': chat_id,
|
data = {'chat_id': chat_id,
|
||||||
'sticker': sticker}
|
'sticker': sticker}
|
||||||
|
|
||||||
|
if filename:
|
||||||
|
data['filename'] = filename
|
||||||
|
|
||||||
return url, data
|
return url, data
|
||||||
|
|
||||||
@log
|
@log
|
||||||
|
@ -416,6 +442,7 @@ class Bot(TelegramObject):
|
||||||
def sendVideo(self,
|
def sendVideo(self,
|
||||||
chat_id,
|
chat_id,
|
||||||
video,
|
video,
|
||||||
|
filename=None,
|
||||||
duration=None,
|
duration=None,
|
||||||
caption=None,
|
caption=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
@ -429,6 +456,9 @@ class Bot(TelegramObject):
|
||||||
Video to send. You can either pass a file_id as String to resend a
|
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 that is already on the Telegram servers, or upload a new
|
||||||
video file using multipart/form-data.
|
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:
|
||||||
Duration of sent video in seconds. [Optional]
|
Duration of sent video in seconds. [Optional]
|
||||||
caption:
|
caption:
|
||||||
|
@ -450,6 +480,8 @@ class Bot(TelegramObject):
|
||||||
data = {'chat_id': chat_id,
|
data = {'chat_id': chat_id,
|
||||||
'video': video}
|
'video': video}
|
||||||
|
|
||||||
|
if filename:
|
||||||
|
data['filename'] = filename
|
||||||
if duration:
|
if duration:
|
||||||
data['duration'] = duration
|
data['duration'] = duration
|
||||||
if caption:
|
if caption:
|
||||||
|
@ -462,6 +494,7 @@ class Bot(TelegramObject):
|
||||||
def sendVoice(self,
|
def sendVoice(self,
|
||||||
chat_id,
|
chat_id,
|
||||||
voice,
|
voice,
|
||||||
|
filename=None,
|
||||||
duration=None,
|
duration=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""Use this method to send audio files, if you want Telegram clients to
|
"""Use this method to send audio files, if you want Telegram clients to
|
||||||
|
@ -478,6 +511,9 @@ class Bot(TelegramObject):
|
||||||
Audio file to send. You can either pass a file_id as String to
|
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
|
resend an audio that is already on the Telegram servers, or upload
|
||||||
a new audio file using multipart/form-data.
|
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:
|
||||||
Duration of sent audio in seconds. [Optional]
|
Duration of sent audio in seconds. [Optional]
|
||||||
reply_to_message_id:
|
reply_to_message_id:
|
||||||
|
@ -496,6 +532,8 @@ class Bot(TelegramObject):
|
||||||
data = {'chat_id': chat_id,
|
data = {'chat_id': chat_id,
|
||||||
'voice': voice}
|
'voice': voice}
|
||||||
|
|
||||||
|
if filename:
|
||||||
|
data['filename'] = filename
|
||||||
if duration:
|
if duration:
|
||||||
data['duration'] = duration
|
data['duration'] = duration
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,10 @@ class InputFile(object):
|
||||||
|
|
||||||
if isinstance(self.input_file, file):
|
if isinstance(self.input_file, file):
|
||||||
self.input_file_content = self.input_file.read()
|
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 \
|
self.mimetype = mimetypes.guess_type(self.filename)[0] or \
|
||||||
DEFAULT_MIME_TYPE
|
DEFAULT_MIME_TYPE
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue