X Tutup
Skip to content

Commit f7ede4b

Browse files
committed
Add caption fields to voice and audio
Or at least the methods/classes for sending.
1 parent c3e07b1 commit f7ede4b

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

telegram/bot.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,14 @@ def sendPhoto(self, chat_id, photo, caption=None, **kwargs):
323323

324324
@log
325325
@message
326-
def sendAudio(self, chat_id, audio, duration=None, performer=None, title=None, **kwargs):
326+
def sendAudio(self,
327+
chat_id,
328+
audio,
329+
duration=None,
330+
performer=None,
331+
title=None,
332+
caption=None,
333+
**kwargs):
327334
"""Use this method to send audio files, if you want Telegram clients to
328335
display them in the music player. Your audio must be in an .mp3 format.
329336
On success, the sent Message is returned. Bots can currently send audio
@@ -348,6 +355,8 @@ def sendAudio(self, chat_id, audio, duration=None, performer=None, title=None, *
348355
Performer of sent audio. [Optional]
349356
title:
350357
Title of sent audio. [Optional]
358+
caption:
359+
Audio caption [Optional]
351360
352361
Keyword Args:
353362
disable_notification (Optional[bool]): Sends the message silently.
@@ -381,6 +390,8 @@ def sendAudio(self, chat_id, audio, duration=None, performer=None, title=None, *
381390
data['performer'] = performer
382391
if title:
383392
data['title'] = title
393+
if caption:
394+
data['caption'] = caption
384395

385396
return url, data
386397

@@ -531,7 +542,7 @@ def sendVideo(self, chat_id, video, duration=None, caption=None, **kwargs):
531542

532543
@log
533544
@message
534-
def sendVoice(self, chat_id, voice, duration=None, **kwargs):
545+
def sendVoice(self, chat_id, voice, duration=None, caption=None, **kwargs):
535546
"""Use this method to send audio files, if you want Telegram clients to
536547
display the file as a playable voice message. For this to work, your
537548
audio must be in an .ogg file encoded with OPUS (other formats may be
@@ -548,6 +559,8 @@ def sendVoice(self, chat_id, voice, duration=None, **kwargs):
548559
a new audio file using multipart/form-data.
549560
duration:
550561
Duration of sent audio in seconds. [Optional]
562+
caption:
563+
Voice caption [Optional]
551564
552565
Keyword Args:
553566
disable_notification (Optional[bool]): Sends the message silently.
@@ -577,6 +590,8 @@ def sendVoice(self, chat_id, voice, duration=None, **kwargs):
577590

578591
if duration:
579592
data['duration'] = duration
593+
if caption:
594+
data['caption'] = caption
580595

581596
return url, data
582597

@@ -1443,7 +1458,8 @@ def __reduce__(self):
14431458
return (self.__class__, (self.token, self.base_url.replace(self.token, ''),
14441459
self.base_file_url.replace(self.token, '')))
14451460

1446-
# snake_case (PEP8) aliases
1461+
# snake_case (PEP8) aliases
1462+
14471463
get_me = getMe
14481464
send_message = sendMessage
14491465
forward_message = forwardMessage

telegram/chat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Chat(TelegramObject):
3232
username (str): Username, for private chats and channels if available
3333
first_name (str): First name of the other party in a private chat
3434
last_name (str): Last name of the other party in a private chat
35+
all_members_are_admins (bool): True if a group has ‘All Members Are Admins’ enabled.
3536
3637
Args:
3738
id (int):
@@ -57,6 +58,7 @@ def __init__(self, id, type, bot=None, **kwargs):
5758
self.username = kwargs.get('username', '')
5859
self.first_name = kwargs.get('first_name', '')
5960
self.last_name = kwargs.get('last_name', '')
61+
self.all_members_are_admins = kwargs.get('all_members_are_admins', '')
6062

6163
self.bot = bot
6264

telegram/inlinequeryresultaudio.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class InlineQueryResultAudio(InlineQueryResult):
3333
title (str):
3434
performer (Optional[str]):
3535
audio_duration (Optional[str]):
36+
caption (Optional[str]):
3637
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
3738
input_message_content (Optional[
3839
:class:`telegram.input_message_content`]):
@@ -53,6 +54,7 @@ class InlineQueryResultAudio(InlineQueryResult):
5354
Keyword Args:
5455
performer (Optional[str]):
5556
audio_duration (Optional[str]):
57+
caption (Optional[str]):
5658
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
5759
input_message_content (Optional[
5860
:class:`telegram.input_message_content`]):
@@ -64,6 +66,7 @@ def __init__(self,
6466
title,
6567
performer=None,
6668
audio_duration=None,
69+
caption=None,
6770
reply_markup=None,
6871
input_message_content=None,
6972
**kwargs):
@@ -78,6 +81,8 @@ def __init__(self,
7881
self.performer = performer
7982
if audio_duration:
8083
self.audio_duration = audio_duration
84+
if caption:
85+
self.caption = caption
8186
if reply_markup:
8287
self.reply_markup = reply_markup
8388
if input_message_content:

telegram/inlinequeryresultcachedaudio.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
3131
Attributes:
3232
id (str):
3333
audio_file_id (str):
34+
caption (Optional[str]):
3435
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
3536
input_message_content (Optional[
3637
:class:`telegram.input_message_content`]):
@@ -48,17 +49,26 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
4849
**kwargs: Arbitrary keyword arguments.
4950
5051
Keyword Args:
52+
caption (Optional[str]):
5153
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
5254
input_message_content (Optional[
5355
:class:`telegram.input_message_content`]):
5456
"""
5557

56-
def __init__(self, id, audio_file_id, reply_markup=None, input_message_content=None, **kwargs):
58+
def __init__(self,
59+
id,
60+
audio_file_id,
61+
caption=None,
62+
reply_markup=None,
63+
input_message_content=None,
64+
**kwargs):
5765
# Required
5866
super(InlineQueryResultCachedAudio, self).__init__('audio', id)
5967
self.audio_file_id = audio_file_id
6068

6169
# Optionals
70+
if caption:
71+
self.caption = caption
6272
if reply_markup:
6373
self.reply_markup = reply_markup
6474
if input_message_content:

telegram/inlinequeryresultcachedvoice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self,
2828
id,
2929
voice_file_id,
3030
title,
31-
description=None,
31+
caption=None,
3232
reply_markup=None,
3333
input_message_content=None,
3434
**kwargs):
@@ -38,8 +38,8 @@ def __init__(self,
3838
self.title = title
3939

4040
# Optionals
41-
if description:
42-
self.description = description
41+
if caption:
42+
self.caption = caption
4343
if reply_markup:
4444
self.reply_markup = reply_markup
4545
if input_message_content:

telegram/inlinequeryresultvoice.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self,
2929
voice_url,
3030
title,
3131
voice_duration=None,
32+
caption=None,
3233
reply_markup=None,
3334
input_message_content=None,
3435
**kwargs):
@@ -41,6 +42,8 @@ def __init__(self,
4142
# Optional
4243
if voice_duration:
4344
self.voice_duration = voice_duration
45+
if caption:
46+
self.caption = caption
4447
if reply_markup:
4548
self.reply_markup = reply_markup
4649
if input_message_content:

0 commit comments

Comments
 (0)
X Tutup