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
58 changes: 58 additions & 0 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ def send_message(
timeout: float = None,
api_kwargs: JSONDict = None,
allow_sending_without_reply: bool = None,
entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
) -> Optional[Message]:
"""Use this method to send text messages.

Expand All @@ -416,6 +417,8 @@ def send_message(
parse_mode (:obj:`str`): Send Markdown or HTML, if you want Telegram apps to show bold,
italic, fixed-width text or inline URLs in your bot's message. See the constants in
:class:`telegram.ParseMode` for the available modes.
entities (List[:class:`telegram.MessageEntity`], optional): List of special entities
that appear in message text, which can be specified instead of :attr:`parse_mode`.
disable_web_page_preview (:obj:`bool`, optional): Disables link previews for links in
this message.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
Expand Down Expand Up @@ -444,6 +447,8 @@ def send_message(

if parse_mode:
data['parse_mode'] = parse_mode
if entities:
data['entities'] = [me.to_dict() for me in entities]
if disable_web_page_preview:
data['disable_web_page_preview'] = disable_web_page_preview

Expand Down Expand Up @@ -566,6 +571,7 @@ def send_photo(
parse_mode: str = None,
api_kwargs: JSONDict = None,
allow_sending_without_reply: bool = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
) -> Optional[Message]:
"""Use this method to send photos.

Expand All @@ -586,6 +592,9 @@ def send_photo(
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in the media caption. See the
constants in :class:`telegram.ParseMode` for the available modes.
caption_entities (List[:class:`telegram.MessageEntity`], optional): List of special
entities that appear in message text, which can be specified instead of
:attr:`parse_mode`.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
receive a notification with no sound.
reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
Expand Down Expand Up @@ -618,6 +627,8 @@ def send_photo(
data['caption'] = caption
if parse_mode:
data['parse_mode'] = parse_mode
if caption_entities:
data['caption_entities'] = [me.to_dict() for me in caption_entities]

return self._message( # type: ignore[return-value]
'sendPhoto',
Expand Down Expand Up @@ -647,6 +658,7 @@ def send_audio(
thumb: FileLike = None,
api_kwargs: JSONDict = None,
allow_sending_without_reply: bool = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
) -> Optional[Message]:
"""
Use this method to send audio files, if you want Telegram clients to display them in the
Expand Down Expand Up @@ -674,6 +686,9 @@ def send_audio(
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in the media caption. See the
constants in :class:`telegram.ParseMode` for the available modes.
caption_entities (List[:class:`telegram.MessageEntity`], optional): List of special
entities that appear in message text, which can be specified instead of
:attr:`parse_mode`.
duration (:obj:`int`, optional): Duration of sent audio in seconds.
performer (:obj:`str`, optional): Performer.
title (:obj:`str`, optional): Track name.
Expand Down Expand Up @@ -720,6 +735,8 @@ def send_audio(
data['caption'] = caption
if parse_mode:
data['parse_mode'] = parse_mode
if caption_entities:
data['caption_entities'] = [me.to_dict() for me in caption_entities]
if thumb:
if InputFile.is_file(thumb):
thumb = cast(IO, thumb)
Expand Down Expand Up @@ -753,6 +770,7 @@ def send_document(
api_kwargs: JSONDict = None,
disable_content_type_detection: bool = None,
allow_sending_without_reply: bool = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
) -> Optional[Message]:
"""
Use this method to send general files.
Expand Down Expand Up @@ -781,6 +799,9 @@ def send_document(
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in the media caption. See the
constants in :class:`telegram.ParseMode` for the available modes.
caption_entities (List[:class:`telegram.MessageEntity`], optional): List of special
entities that appear in message text, which can be specified instead of
:attr:`parse_mode`.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
receive a notification with no sound.
reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
Expand Down Expand Up @@ -818,6 +839,8 @@ def send_document(
data['caption'] = caption
if parse_mode:
data['parse_mode'] = parse_mode
if caption_entities:
data['caption_entities'] = [me.to_dict() for me in caption_entities]
if disable_content_type_detection is not None:
data['disable_content_type_detection'] = disable_content_type_detection
if thumb:
Expand Down Expand Up @@ -921,6 +944,7 @@ def send_video(
thumb: FileLike = None,
api_kwargs: JSONDict = None,
allow_sending_without_reply: bool = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
) -> Optional[Message]:
"""
Use this method to send video files, Telegram clients support mp4 videos
Expand Down Expand Up @@ -952,6 +976,9 @@ def send_video(
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in the media caption. See the
constants in :class:`telegram.ParseMode` for the available modes.
caption_entities (List[:class:`telegram.MessageEntity`], optional): List of special
entities that appear in message text, which can be specified instead of
:attr:`parse_mode`.
supports_streaming (:obj:`bool`, optional): Pass :obj:`True`, if the uploaded video is
suitable for streaming.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
Expand Down Expand Up @@ -993,6 +1020,8 @@ def send_video(
data['caption'] = caption
if parse_mode:
data['parse_mode'] = parse_mode
if caption_entities:
data['caption_entities'] = [me.to_dict() for me in caption_entities]
if supports_streaming:
data['supports_streaming'] = supports_streaming
if width:
Expand Down Expand Up @@ -1124,6 +1153,7 @@ def send_animation(
timeout: float = 20,
api_kwargs: JSONDict = None,
allow_sending_without_reply: bool = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
) -> Optional[Message]:
"""
Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).
Expand Down Expand Up @@ -1156,6 +1186,9 @@ def send_animation(
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in the media caption. See the
constants in :class:`telegram.ParseMode` for the available modes.
caption_entities (List[:class:`telegram.MessageEntity`], optional): List of special
entities that appear in message text, which can be specified instead of
:attr:`parse_mode`.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
receive a notification with no sound.
reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
Expand Down Expand Up @@ -1199,6 +1232,8 @@ def send_animation(
data['caption'] = caption
if parse_mode:
data['parse_mode'] = parse_mode
if caption_entities:
data['caption_entities'] = [me.to_dict() for me in caption_entities]

return self._message( # type: ignore[return-value]
'sendAnimation',
Expand All @@ -1225,6 +1260,7 @@ def send_voice(
parse_mode: str = None,
api_kwargs: JSONDict = None,
allow_sending_without_reply: bool = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
) -> Optional[Message]:
"""
Use this method to send audio files, if you want Telegram clients to display the file
Expand All @@ -1249,6 +1285,9 @@ def send_voice(
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in the media caption. See the
constants in :class:`telegram.ParseMode` for the available modes.
caption_entities (List[:class:`telegram.MessageEntity`], optional): List of special
entities that appear in message text, which can be specified instead of
:attr:`parse_mode`.
duration (:obj:`int`, optional): Duration of the voice message in seconds.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
receive a notification with no sound.
Expand Down Expand Up @@ -1284,6 +1323,8 @@ def send_voice(
data['caption'] = caption
if parse_mode:
data['parse_mode'] = parse_mode
if caption_entities:
data['caption_entities'] = [me.to_dict() for me in caption_entities]

return self._message( # type: ignore[return-value]
'sendVoice',
Expand Down Expand Up @@ -2290,6 +2331,7 @@ def edit_message_text(
reply_markup: ReplyMarkup = None,
timeout: float = None,
api_kwargs: JSONDict = None,
entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
) -> Union[Optional[Message], bool]:
"""
Use this method to edit text and game messages.
Expand All @@ -2306,6 +2348,8 @@ def edit_message_text(
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in your bot's message. See the
constants in :class:`telegram.ParseMode` for the available modes.
entities (List[:class:`telegram.MessageEntity`], optional): List of special entities
that appear in message text, which can be specified instead of :attr:`parse_mode`.
disable_web_page_preview (:obj:`bool`, optional): Disables link previews for links in
this message.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): A JSON-serialized
Expand Down Expand Up @@ -2334,6 +2378,8 @@ def edit_message_text(
data['inline_message_id'] = inline_message_id
if parse_mode:
data['parse_mode'] = parse_mode
if entities:
data['entities'] = [me.to_dict() for me in entities]
if disable_web_page_preview:
data['disable_web_page_preview'] = disable_web_page_preview

Expand All @@ -2356,6 +2402,7 @@ def edit_message_caption(
timeout: float = None,
parse_mode: str = None,
api_kwargs: JSONDict = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
) -> Union[Message, bool]:
"""
Use this method to edit captions of messages.
Expand All @@ -2373,6 +2420,9 @@ def edit_message_caption(
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in the media caption. See the
constants in :class:`telegram.ParseMode` for the available modes.
caption_entities (List[:class:`telegram.MessageEntity`], optional): List of special
entities that appear in message text, which can be specified instead of
:attr:`parse_mode`.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): A JSON-serialized
object for an inline keyboard.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
Expand Down Expand Up @@ -2401,6 +2451,8 @@ def edit_message_caption(
data['caption'] = caption
if parse_mode:
data['parse_mode'] = parse_mode
if caption_entities:
data['caption_entities'] = [me.to_dict() for me in caption_entities]
if chat_id:
data['chat_id'] = chat_id
if message_id:
Expand Down Expand Up @@ -4283,6 +4335,7 @@ def send_poll(
close_date: Union[int, datetime] = None,
api_kwargs: JSONDict = None,
allow_sending_without_reply: bool = None,
explanation_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
) -> Message:
"""
Use this method to send a native poll.
Expand All @@ -4306,6 +4359,9 @@ def send_poll(
explanation_parse_mode (:obj:`str`, optional): Mode for parsing entities in the
explanation. See the constants in :class:`telegram.ParseMode` for the available
modes.
explanation_entities (List[:class:`telegram.MessageEntity`], optional): List of special
entities that appear in message text, which can be specified instead of
:attr:`parse_mode`.
open_period (:obj:`int`, optional): Amount of time in seconds the poll will be active
after creation, 5-600. Can't be used together with :attr:`close_date`.
close_date (:obj:`int` | :obj:`datetime.datetime`, optional): Point in time (Unix
Expand Down Expand Up @@ -4360,6 +4416,8 @@ def send_poll(
data['explanation'] = explanation
if explanation_parse_mode:
data['explanation_parse_mode'] = explanation_parse_mode
if explanation_entities:
data['explanation_entities'] = [me.to_dict() for me in explanation_entities]
if open_period:
data['open_period'] = open_period
if close_date:
Expand Down
Loading