Skip to content

Commit c152d65

Browse files
spontanurlaubtsnoam
authored andcommitted
Support v3.6 API (python-telegram-bot#1006)
* Added support for new field `telegram.Message.connected_message` * Added support for new field `telegram.Message.connected_message` * Added support for parse_mode in captions * Added parse_mode parameter for captions in InlineQueryResult* * Added supports_streaming parameter in telegram.Bot.send_video and telegram.InputMediaVideo Fixed Docstrings for parse_mode in captions * pypy3.5 unitests are now running with a new version due internal errors on travis. closes python-telegram-bot#1005
1 parent 9338dc4 commit c152d65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+379
-30
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ python:
55
- "3.5"
66
- "3.6"
77
- "pypy-5.7.1"
8-
- "pypy3.5-5.8.0"
8+
- "pypy3.5-5.10.0"
99

1010
dist: trusty
1111
sudo: false
@@ -35,4 +35,4 @@ script:
3535

3636
after_success:
3737
- coverage combine
38-
- codecov -F Travis
38+
- codecov -F Travis

telegram/bot.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ def send_photo(self,
339339
reply_to_message_id=None,
340340
reply_markup=None,
341341
timeout=20,
342+
parse_mode=None,
342343
**kwargs):
343344
"""Use this method to send photos.
344345
@@ -356,6 +357,9 @@ def send_photo(self,
356357
an existing :class:`telegram.PhotoSize` object to send.
357358
caption (:obj:`str`, optional): Photo caption (may also be used when resending photos
358359
by file_id), 0-200 characters.
360+
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
361+
show bold, italic, fixed-width text or inline URLs in the media caption. See the
362+
constants in :class:`telegram.ParseMode` for the available modes.
359363
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
360364
receive a notification with no sound.
361365
reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
@@ -382,6 +386,8 @@ def send_photo(self,
382386

383387
if caption:
384388
data['caption'] = caption
389+
if parse_mode:
390+
data['parse_mode'] = parse_mode
385391

386392
return url, data
387393

@@ -398,6 +404,7 @@ def send_audio(self,
398404
reply_to_message_id=None,
399405
reply_markup=None,
400406
timeout=20,
407+
parse_mode=None,
401408
**kwargs):
402409
"""
403410
Use this method to send audio files, if you want Telegram clients to display them in the
@@ -420,6 +427,9 @@ def send_audio(self,
420427
the Internet, or upload a new one using multipart/form-data. Lastly you can pass
421428
an existing :class:`telegram.Audio` object to send.
422429
caption (:obj:`str`, optional): Audio caption, 0-200 characters.
430+
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
431+
show bold, italic, fixed-width text or inline URLs in the media caption. See the
432+
constants in :class:`telegram.ParseMode` for the available modes.
423433
duration (:obj:`int`, optional): Duration of sent audio in seconds.
424434
performer (:obj:`str`, optional): Performer.
425435
title (:obj:`str`, optional): Track name.
@@ -455,6 +465,8 @@ def send_audio(self,
455465
data['title'] = title
456466
if caption:
457467
data['caption'] = caption
468+
if parse_mode:
469+
data['parse_mode'] = parse_mode
458470

459471
return url, data
460472

@@ -469,6 +481,7 @@ def send_document(self,
469481
reply_to_message_id=None,
470482
reply_markup=None,
471483
timeout=20,
484+
parse_mode=None,
472485
**kwargs):
473486
"""Use this method to send general files.
474487
@@ -488,6 +501,9 @@ def send_document(self,
488501
when you send file generated by temp module, for example). Undocumented.
489502
caption (:obj:`str`, optional): Document caption (may also be used when resending
490503
documents by file_id), 0-200 characters.
504+
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
505+
show bold, italic, fixed-width text or inline URLs in the media caption. See the
506+
constants in :class:`telegram.ParseMode` for the available modes.
491507
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
492508
receive a notification with no sound.
493509
reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
@@ -516,6 +532,8 @@ def send_document(self,
516532
data['filename'] = filename
517533
if caption:
518534
data['caption'] = caption
535+
if parse_mode:
536+
data['parse_mode'] = parse_mode
519537

520538
return url, data
521539

@@ -582,6 +600,8 @@ def send_video(self,
582600
timeout=20,
583601
width=None,
584602
height=None,
603+
parse_mode=None,
604+
supports_streaming=None,
585605
**kwargs):
586606
"""
587607
Use this method to send video files, Telegram clients support mp4 videos
@@ -604,6 +624,11 @@ def send_video(self,
604624
height (:obj:`int`, optional): Video height.
605625
caption (:obj:`str`, optional): Video caption (may also be used when resending videos
606626
by file_id), 0-200 characters.
627+
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
628+
show bold, italic, fixed-width text or inline URLs in the media caption. See the
629+
constants in :class:`telegram.ParseMode` for the available modes.
630+
supports_streaming (:obj:`bool`, optional): Pass True, if the uploaded video is
631+
suitable for streaming.
607632
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
608633
receive a notification with no sound.
609634
reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
@@ -632,6 +657,10 @@ def send_video(self,
632657
data['duration'] = duration
633658
if caption:
634659
data['caption'] = caption
660+
if parse_mode:
661+
data['parse_mode'] = parse_mode
662+
if supports_streaming:
663+
data['supports_streaming'] = supports_streaming
635664
if width:
636665
data['width'] = width
637666
if height:
@@ -650,6 +679,7 @@ def send_voice(self,
650679
reply_to_message_id=None,
651680
reply_markup=None,
652681
timeout=20,
682+
parse_mode=None,
653683
**kwargs):
654684
"""
655685
Use this method to send audio files, if you want Telegram clients to display the file
@@ -669,6 +699,9 @@ def send_voice(self,
669699
the Internet, or upload a new one using multipart/form-data. Lastly you can pass
670700
an existing :class:`telegram.Voice` object to send.
671701
caption (:obj:`str`, optional): Voice message caption, 0-200 characters.
702+
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
703+
show bold, italic, fixed-width text or inline URLs in the media caption. See the
704+
constants in :class:`telegram.ParseMode` for the available modes.
672705
duration (:obj:`int`, optional): Duration of the voice message in seconds.
673706
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
674707
receive a notification with no sound.
@@ -698,6 +731,8 @@ def send_voice(self,
698731
data['duration'] = duration
699732
if caption:
700733
data['caption'] = caption
734+
if parse_mode:
735+
data['parse_mode'] = parse_mode
701736

702737
return url, data
703738

@@ -1504,6 +1539,8 @@ def edit_message_text(self,
15041539
parse_mode (:obj:`str`): Send Markdown or HTML, if you want Telegram apps to show bold,
15051540
italic, fixed-width text or inline URLs in your bot's message. See the constants in
15061541
:class:`telegram.ParseMode` for the available modes.
1542+
disable_web_page_preview (:obj:`bool`, optional): Disables link previews for links in
1543+
this message.
15071544
reply_markup (:class:`telegram.ReplyMarkup`, optional): Additional interface options. A
15081545
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
15091546
to remove reply keyboard or to force a reply from the user.
@@ -1546,6 +1583,7 @@ def edit_message_caption(self,
15461583
caption=None,
15471584
reply_markup=None,
15481585
timeout=None,
1586+
parse_mode=None,
15491587
**kwargs):
15501588
"""
15511589
Use this method to edit captions of messages sent by the bot or via the bot
@@ -1559,6 +1597,9 @@ def edit_message_caption(self,
15591597
inline_message_id (:obj:`str`, optional): Required if chat_id and message_id are not
15601598
specified. Identifier of the inline message.
15611599
caption (:obj:`str`, optional): New caption of the message.
1600+
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
1601+
show bold, italic, fixed-width text or inline URLs in the media caption. See the
1602+
constants in :class:`telegram.ParseMode` for the available modes.
15621603
reply_markup (:class:`telegram.ReplyMarkup`, optional): Additional interface options. A
15631604
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
15641605
to remove reply keyboard or to force a reply from the user.
@@ -1586,6 +1627,8 @@ def edit_message_caption(self,
15861627

15871628
if caption:
15881629
data['caption'] = caption
1630+
if parse_mode:
1631+
data['parse_mode'] = parse_mode
15891632
if chat_id:
15901633
data['chat_id'] = chat_id
15911634
if message_id:

telegram/ext/filters.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,23 @@ def filter(self, message):
346346
pinned_message = _PinnedMessage()
347347
""":obj:`Filter`: Messages that contain :attr:`telegram.Message.pinned_message`."""
348348

349+
class _ConnectedWebsite(BaseFilter):
350+
name = 'Filters.status_update.connected_website'
351+
352+
def filter(self, message):
353+
return bool(message.connected_website)
354+
355+
connected_website = _ConnectedWebsite()
356+
""":obj:`Filter`: Messages that contain :attr:`telegram.Message.connected_website`."""
357+
349358
name = 'Filters.status_update'
350359

351360
def filter(self, message):
352361
return bool(self.new_chat_members(message) or self.left_chat_member(message) or
353362
self.new_chat_title(message) or self.new_chat_photo(message) or
354363
self.delete_chat_photo(message) or self.chat_created(message) or
355-
self.migrate(message) or self.pinned_message(message))
364+
self.migrate(message) or self.pinned_message(message) or
365+
self.connected_website(message))
356366

357367
status_update = _StatusUpdate()
358368
"""Subset for messages containing a status update.

telegram/files/inputmediaphoto.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,26 @@ class InputMediaPhoto(InputMedia):
2929
Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the
3030
Internet. Lastly you can pass an existing :class:`telegram.PhotoSize` object to send.
3131
caption (:obj:`str`): Optional. Caption of the photo to be sent, 0-200 characters.
32+
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
33+
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
34+
in :class:`telegram.ParseMode` for the available modes.
3235
3336
Args:
3437
media (:obj:`str`): File to send. Pass a file_id to send a file that exists on the
3538
Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the
3639
Internet. Lastly you can pass an existing :class:`telegram.PhotoSize` object to send.
3740
caption (:obj:`str`, optional ): Caption of the photo to be sent, 0-200 characters.
41+
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
42+
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
43+
in :class:`telegram.ParseMode` for the available modes.
3844
3945
Note:
4046
At the moment using a new file is not yet supported.
4147
"""
4248

4349
# TODO: Make InputMediaPhoto, InputMediaVideo and send_media_group work with new files
4450

45-
def __init__(self, media, caption=None):
51+
def __init__(self, media, caption=None, parse_mode=None):
4652
self.type = 'photo'
4753

4854
if isinstance(media, PhotoSize):
@@ -55,3 +61,5 @@ def __init__(self, media, caption=None):
5561

5662
if caption:
5763
self.caption = caption
64+
if parse_mode:
65+
self.parse_mode = parse_mode

telegram/files/inputmediavideo.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,28 @@ class InputMediaVideo(InputMedia):
2929
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
3030
Lastly you can pass an existing :class:`telegram.Video` object to send.
3131
caption (:obj:`str`): Optional. Caption of the video to be sent, 0-200 characters.
32+
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
33+
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
34+
in :class:`telegram.ParseMode` for the available modes.
3235
width (:obj:`int`): Optional. Video width.
3336
height (:obj:`int`): Optional. Video height.
3437
duration (:obj:`int`): Optional. Video duration.
38+
supports_streaming (:obj:`bool`): Optional. Pass True, if the uploaded video is suitable
39+
for streaming.
3540
3641
Args:
3742
media (:obj:`str`): File to send. Pass a file_id to send a file that exists on the Telegram
3843
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
3944
Lastly you can pass an existing :class:`telegram.Video` object to send.
4045
caption (:obj:`str`, optional): Caption of the video to be sent, 0-200 characters.
46+
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
47+
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
48+
in :class:`telegram.ParseMode` for the available modes.
4149
width (:obj:`int`, optional): Video width.
4250
height (:obj:`int`, optional): Video height.
4351
duration (:obj:`int`, optional): Video duration.
52+
supports_streaming (:obj:`bool`, optional): Pass True, if the uploaded video is suitable
53+
for streaming.
4454
4555
Note:
4656
When using a :class:`telegram.Video` for the :attr:`media` attribute. It will take the
@@ -51,7 +61,8 @@ class InputMediaVideo(InputMedia):
5161

5262
# TODO: Make InputMediaPhoto, InputMediaVideo and send_media_group work with new files
5363

54-
def __init__(self, media, caption=None, width=None, height=None, duration=None):
64+
def __init__(self, media, caption=None, width=None, height=None, duration=None,
65+
supports_streaming=None, parse_mode=None):
5566
self.type = 'video'
5667

5768
if isinstance(media, Video):
@@ -66,9 +77,13 @@ def __init__(self, media, caption=None, width=None, height=None, duration=None):
6677

6778
if caption:
6879
self.caption = caption
80+
if parse_mode:
81+
self.parse_mode = parse_mode
6982
if width:
7083
self.width = width
7184
if height:
7285
self.height = height
7386
if duration:
7487
self.duration = duration
88+
if supports_streaming:
89+
self.supports_streaming = supports_streaming

telegram/inline/inlinequeryresultaudio.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class InlineQueryResultAudio(InlineQueryResult):
3535
performer (:obj:`str`): Optional. Caption, 0-200 characters.
3636
audio_duration (:obj:`str`): Optional. Performer.
3737
caption (:obj:`str`): Optional. Audio duration in seconds.
38+
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
39+
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
40+
in :class:`telegram.ParseMode` for the available modes.
3841
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
3942
to the message.
4043
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -47,6 +50,9 @@ class InlineQueryResultAudio(InlineQueryResult):
4750
performer (:obj:`str`, optional): Caption, 0-200 characters.
4851
audio_duration (:obj:`str`, optional): Performer.
4952
caption (:obj:`str`, optional): Audio duration in seconds.
53+
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
54+
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
55+
in :class:`telegram.ParseMode` for the available modes.
5056
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
5157
to the message.
5258
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -64,6 +70,7 @@ def __init__(self,
6470
caption=None,
6571
reply_markup=None,
6672
input_message_content=None,
73+
parse_mode=None,
6774
**kwargs):
6875

6976
# Required
@@ -78,6 +85,8 @@ def __init__(self,
7885
self.audio_duration = audio_duration
7986
if caption:
8087
self.caption = caption
88+
if parse_mode:
89+
self.parse_mode = parse_mode
8190
if reply_markup:
8291
self.reply_markup = reply_markup
8392
if input_message_content:

telegram/inline/inlinequeryresultcachedaudio.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
3232
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
3333
audio_file_id (:obj:`str`): A valid file identifier for the audio file.
3434
caption (:obj:`str`): Optional. Caption, 0-200 characters
35+
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
36+
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
37+
in :class:`telegram.ParseMode` for the available modes.
3538
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
3639
to the message.
3740
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -41,6 +44,9 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
4144
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
4245
audio_file_id (:obj:`str`): A valid file identifier for the audio file.
4346
caption (:obj:`str`, optional): Caption, 0-200 characters
47+
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
48+
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
49+
in :class:`telegram.ParseMode` for the available modes.
4450
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
4551
to the message.
4652
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -55,6 +61,7 @@ def __init__(self,
5561
caption=None,
5662
reply_markup=None,
5763
input_message_content=None,
64+
parse_mode=None,
5865
**kwargs):
5966
# Required
6067
super(InlineQueryResultCachedAudio, self).__init__('audio', id)
@@ -63,6 +70,8 @@ def __init__(self,
6370
# Optionals
6471
if caption:
6572
self.caption = caption
73+
if parse_mode:
74+
self.parse_mode = parse_mode
6675
if reply_markup:
6776
self.reply_markup = reply_markup
6877
if input_message_content:

0 commit comments

Comments
 (0)