2015-07-07 21:50:36 +02:00
|
|
|
#!/usr/bin/env python
|
2015-08-22 04:15:29 +02:00
|
|
|
# pylint: disable=R0902,R0912,R0913
|
2015-08-11 21:58:17 +02:00
|
|
|
#
|
|
|
|
# A library that provides a Python interface to the Telegram Bot API
|
2018-01-04 16:16:06 +01:00
|
|
|
# Copyright (C) 2015-2018
|
2016-01-05 14:12:03 +01:00
|
|
|
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
2015-08-11 21:58:17 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser Public License
|
|
|
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
2016-10-17 00:22:40 +02:00
|
|
|
"""This module contains an object that represents a Telegram Message."""
|
2016-09-07 08:49:09 +02:00
|
|
|
import sys
|
2018-02-22 16:38:54 +01:00
|
|
|
from html import escape
|
2015-07-09 16:40:44 +02:00
|
|
|
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
from telegram import (Animation, Audio, Contact, Document, Chat, Location, PhotoSize, Sticker,
|
|
|
|
TelegramObject, User, Video, Voice, Venue, MessageEntity, Game, Invoice,
|
|
|
|
SuccessfulPayment, VideoNote, PassportData)
|
2018-02-12 14:39:46 +01:00
|
|
|
from telegram import ParseMode
|
2018-02-22 16:38:54 +01:00
|
|
|
from telegram.utils.helpers import escape_markdown, to_timestamp, from_timestamp
|
2015-08-21 19:49:07 +02:00
|
|
|
|
2017-08-07 23:25:19 +02:00
|
|
|
_UNDEFINED = object()
|
|
|
|
|
|
|
|
|
2015-07-20 04:06:04 +02:00
|
|
|
class Message(TelegramObject):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""This object represents a message.
|
2015-08-21 19:49:07 +02:00
|
|
|
|
|
|
|
Note:
|
|
|
|
* In Python `from` is a reserved word, use `from_user` instead.
|
|
|
|
|
|
|
|
Attributes:
|
2017-07-23 22:33:08 +02:00
|
|
|
message_id (:obj:`int`): Unique message identifier inside this chat.
|
|
|
|
from_user (:class:`telegram.User`): Optional. Sender.
|
|
|
|
date (:class:`datetime.datetime`): Date the message was sent.
|
|
|
|
chat (:class:`telegram.Chat`): Conversation the message belongs to.
|
|
|
|
forward_from (:class:`telegram.User`): Optional. Sender of the original message.
|
|
|
|
forward_from_chat (:class:`telegram.Chat`): Optional. Information about the original
|
|
|
|
channel.
|
|
|
|
forward_from_message_id (:obj:`int`): Optional. Identifier of the original message in the
|
|
|
|
channel.
|
|
|
|
forward_date (:class:`datetime.datetime`): Optional. Date the original message was sent.
|
|
|
|
reply_to_message (:class:`telegram.Message`): Optional. The original message.
|
|
|
|
edit_date (:class:`datetime.datetime`): Optional. Date the message was last edited.
|
2017-12-08 22:38:59 +01:00
|
|
|
media_group_id (:obj:`str`): Optional. The unique identifier of a media message group this
|
|
|
|
message belongs to.
|
2017-07-23 22:33:08 +02:00
|
|
|
text (:obj:`str`): Optional. The actual UTF-8 text of the message.
|
|
|
|
entities (List[:class:`telegram.MessageEntity`]): Optional. Special entities like
|
|
|
|
usernames, URLs, bot commands, etc. that appear in the text. See
|
|
|
|
:attr:`Message.parse_entity` and :attr:`parse_entities` methods for how to use
|
|
|
|
properly.
|
2017-10-14 20:03:02 +02:00
|
|
|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. Special entities like
|
|
|
|
usernames, URLs, bot commands, etc. that appear in the caption. See
|
|
|
|
:attr:`Message.parse_caption_entity` and :attr:`parse_caption_entities` methods for how
|
|
|
|
to use properly.
|
2017-07-23 22:33:08 +02:00
|
|
|
audio (:class:`telegram.Audio`): Optional. Information about the file.
|
|
|
|
document (:class:`telegram.Document`): Optional. Information about the file.
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
animation (:class:`telegram.Animation`) Optional. Information about the file.
|
|
|
|
For backward compatibility, when this field is set, the document field will also be
|
|
|
|
set.
|
2017-07-23 22:33:08 +02:00
|
|
|
game (:class:`telegram.Game`): Optional. Information about the game.
|
|
|
|
photo (List[:class:`telegram.PhotoSize`]): Optional. Available sizes of the photo.
|
|
|
|
sticker (:class:`telegram.Sticker`): Optional. Information about the sticker.
|
|
|
|
video (:class:`telegram.Video`): Optional. Information about the video.
|
|
|
|
voice (:class:`telegram.Voice`): Optional. Information about the file.
|
|
|
|
video_note (:class:`telegram.VideoNote`): Optional. Information about the video message.
|
|
|
|
new_chat_members (List[:class:`telegram.User`]): Optional. Information about new members to
|
|
|
|
the chat. (the bot itself may be one of these members).
|
2018-10-16 19:51:57 +02:00
|
|
|
caption (:obj:`str`): Optional. Caption for the document, photo or video, 0-1024
|
|
|
|
characters.
|
2017-07-23 22:33:08 +02:00
|
|
|
contact (:class:`telegram.Contact`): Optional. Information about the contact.
|
|
|
|
location (:class:`telegram.Location`): Optional. Information about the location.
|
|
|
|
venue (:class:`telegram.Venue`): Optional. Information about the venue.
|
|
|
|
left_chat_member (:class:`telegram.User`): Optional. Information about the user that left
|
|
|
|
the group. (this member may be the bot itself).
|
|
|
|
new_chat_title (:obj:`str`): Optional. A chat title was changed to this value.
|
|
|
|
new_chat_photo (List[:class:`telegram.PhotoSize`]): Optional. A chat photo was changed to
|
|
|
|
this value.
|
|
|
|
delete_chat_photo (:obj:`bool`): Optional. The chat photo was deleted.
|
|
|
|
group_chat_created (:obj:`bool`): Optional. The group has been created.
|
|
|
|
supergroup_chat_created (:obj:`bool`): Optional. The supergroup has been created.
|
|
|
|
channel_chat_created (:obj:`bool`): Optional. The channel has been created.
|
|
|
|
migrate_to_chat_id (:obj:`int`): Optional. The group has been migrated to a supergroup with
|
|
|
|
the specified identifier.
|
|
|
|
migrate_from_chat_id (:obj:`int`): Optional. The supergroup has been migrated from a group
|
|
|
|
with the specified identifier.
|
|
|
|
pinned_message (:class:`telegram.message`): Optional. Specified message was pinned.
|
|
|
|
invoice (:class:`telegram.Invoice`): Optional. Information about the invoice.
|
|
|
|
successful_payment (:class:`telegram.SuccessfulPayment`): Optional. Information about the
|
|
|
|
payment.
|
2018-02-18 16:11:04 +01:00
|
|
|
connected_website (:obj:`str`): Optional. The domain name of the website on which the user
|
|
|
|
has logged in.
|
2017-09-01 08:40:05 +02:00
|
|
|
forward_signature (:obj:`str`): Optional. Signature of the post author for messages
|
|
|
|
forwarded from channels.
|
|
|
|
author_signature (:obj:`str`): Optional. Signature of the post author for messages
|
|
|
|
in channels.
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
passport_data (:class:`telegram.PassportData`): Optional. Telegram Passport data
|
2017-07-23 22:33:08 +02:00
|
|
|
bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
message_id (:obj:`int`): Unique message identifier inside this chat.
|
|
|
|
from_user (:class:`telegram.User`, optional): Sender, can be empty for messages sent
|
|
|
|
to channels.
|
|
|
|
date (:class:`datetime.datetime`): Date the message was sent in Unix time. Converted to
|
|
|
|
:class:`datetime.datetime`.
|
|
|
|
chat (:class:`telegram.Chat`): Conversation the message belongs to.
|
|
|
|
forward_from (:class:`telegram.User`, optional): For forwarded messages, sender of
|
|
|
|
the original message.
|
|
|
|
forward_from_chat (:class:`telegram.Chat`, optional): For messages forwarded from a
|
|
|
|
channel, information about the original channel.
|
|
|
|
forward_from_message_id (:obj:`int`, optional): For forwarded channel posts, identifier of
|
|
|
|
the original message in the channel.
|
|
|
|
forward_date (:class:`datetime.datetime`, optional): For forwarded messages, date the
|
|
|
|
original message was sent in Unix time. Converted to :class:`datetime.datetime`.
|
|
|
|
reply_to_message (:class:`telegram.Message`, optional): For replies, the original message.
|
|
|
|
Note that the Message object in this field will not contain further
|
|
|
|
``reply_to_message`` fields even if it itself is a reply.
|
|
|
|
edit_date (:class:`datetime.datetime`, optional): Date the message was last edited in Unix
|
|
|
|
time. Converted to :class:`datetime.datetime`.
|
2017-12-08 22:38:59 +01:00
|
|
|
media_group_id (:obj:`str`, optional): The unique identifier of a media message group this
|
|
|
|
message belongs to.
|
2017-07-23 22:33:08 +02:00
|
|
|
text (str, optional): For text messages, the actual UTF-8 text of the message, 0-4096
|
|
|
|
characters. Also found as :attr:`telegram.constants.MAX_MESSAGE_LENGTH`.
|
|
|
|
entities (List[:class:`telegram.MessageEntity`], optional): For text messages, special
|
|
|
|
entities like usernames, URLs, bot commands, etc. that appear in the text. See
|
|
|
|
attr:`parse_entity` and attr:`parse_entities` methods for how to use properly.
|
2017-10-14 20:03:02 +02:00
|
|
|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. For Messages with a
|
|
|
|
Caption. Special entities like usernames, URLs, bot commands, etc. that appear in the
|
|
|
|
caption. See :attr:`Message.parse_caption_entity` and :attr:`parse_caption_entities`
|
|
|
|
methods for how to use properly.
|
2017-07-23 22:33:08 +02:00
|
|
|
audio (:class:`telegram.Audio`, optional): Message is an audio file, information
|
|
|
|
about the file.
|
|
|
|
document (:class:`telegram.Document`, optional): Message is a general file, information
|
|
|
|
about the file.
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
animation (:class:`telegram.Animation`, optional): Message is an animation, information
|
|
|
|
about the animation. For backward compatibility, when this field is set, the document
|
|
|
|
field will also be set.
|
2017-07-23 22:33:08 +02:00
|
|
|
game (:class:`telegram.Game`, optional): Message is a game, information about the game.
|
|
|
|
photo (List[:class:`telegram.PhotoSize`], optional): Message is a photo, available
|
|
|
|
sizes of the photo.
|
|
|
|
sticker (:class:`telegram.Sticker`, optional): Message is a sticker, information
|
|
|
|
about the sticker.
|
|
|
|
video (:class:`telegram.Video`, optional): Message is a video, information about the video.
|
|
|
|
voice (:class:`telegram.Voice`, optional): Message is a voice message, information about
|
|
|
|
the file.
|
|
|
|
video_note (:class:`telegram.VideoNote`, optional): Message is a video note, information
|
|
|
|
about the video message.
|
|
|
|
new_chat_members (List[:class:`telegram.User`], optional): New members that were added to
|
|
|
|
the group or supergroup and information about them (the bot itself may be one of these
|
|
|
|
members).
|
2018-10-16 19:51:57 +02:00
|
|
|
caption (:obj:`str`, optional): Caption for the document, photo or video, 0-1024
|
|
|
|
characters.
|
2017-07-23 22:33:08 +02:00
|
|
|
contact (:class:`telegram.Contact`, optional): Message is a shared contact, information
|
|
|
|
about the contact.
|
|
|
|
location (:class:`telegram.Location`, optional): Message is a shared location, information
|
|
|
|
about the location.
|
|
|
|
venue (:class:`telegram.Venue`, optional): Message is a venue, information about the venue.
|
|
|
|
left_chat_member (:class:`telegram.User`, optional): A member was removed from the group,
|
|
|
|
information about them (this member may be the bot itself).
|
|
|
|
new_chat_title (:obj:`str`, optional): A chat title was changed to this value.
|
|
|
|
new_chat_photo (List[:class:`telegram.PhotoSize`], optional): A chat photo was change to
|
|
|
|
this value.
|
|
|
|
delete_chat_photo (:obj:`bool`, optional): Service message: The chat photo was deleted.
|
|
|
|
group_chat_created (:obj:`bool`, optional): Service message: The group has been created.
|
|
|
|
supergroup_chat_created (:obj:`bool`, optional): Service message: The supergroup has been
|
|
|
|
created. This field can't be received in a message coming through updates, because bot
|
|
|
|
can't be a member of a supergroup when it is created. It can only be found in
|
|
|
|
:attr:`reply_to_message` if someone replies to a very first message in a directly
|
|
|
|
created supergroup.
|
|
|
|
channel_chat_created (:obj:`bool`, optional): Service message: The channel has been
|
|
|
|
created. This field can't be received in a message coming through updates, because bot
|
|
|
|
can't be a member of a channel when it is created. It can only be found in
|
|
|
|
attr:`reply_to_message` if someone replies to a very first message in a channel.
|
|
|
|
migrate_to_chat_id (:obj:`int`, optional): The group has been migrated to a supergroup with
|
|
|
|
the specified identifier. This number may be greater than 32 bits and some programming
|
|
|
|
languages may have difficulty/silent defects in interpreting it. But it is smaller than
|
|
|
|
52 bits, so a signed 64 bit integer or double-precision float type are safe for storing
|
|
|
|
this identifier.
|
|
|
|
migrate_from_chat_id (:obj:`int`, optional): The supergroup has been migrated from a group
|
|
|
|
with the specified identifier. This number may be greater than 32 bits and some
|
|
|
|
programming languages may have difficulty/silent defects in interpreting it. But it is
|
|
|
|
smaller than 52 bits, so a signed 64 bit integer or double-precision float type are
|
|
|
|
safe for storing this identifier.
|
|
|
|
pinned_message (:class:`telegram.message`, optional): Specified message was pinned. Note
|
|
|
|
that the Message object in this field will not contain further attr:`reply_to_message`
|
|
|
|
fields even if it is itself a reply.
|
|
|
|
invoice (:class:`telegram.Invoice`, optional): Message is an invoice for a payment,
|
|
|
|
information about the invoice.
|
|
|
|
successful_payment (:class:`telegram.SuccessfulPayment`, optional): Message is a service
|
|
|
|
message about a successful payment, information about the payment.
|
2018-02-18 16:11:04 +01:00
|
|
|
connected_website (:obj:`str`, optional): The domain name of the website on which the user
|
|
|
|
has logged in.
|
2017-09-01 08:40:05 +02:00
|
|
|
forward_signature (:obj:`str`, optional): Signature of the post author for messages
|
|
|
|
forwarded from channels.
|
|
|
|
author_signature (:obj:`str`, optional): Signature of the post author for messages
|
|
|
|
in channels.
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
passport_data (:class:`telegram.PassportData`, optional): Telegram Passport data
|
2015-08-21 19:49:07 +02:00
|
|
|
"""
|
2017-09-01 10:38:04 +02:00
|
|
|
|
2017-08-07 23:25:19 +02:00
|
|
|
_effective_attachment = _UNDEFINED
|
2015-08-21 19:49:07 +02:00
|
|
|
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
ATTACHMENT_TYPES = ['audio', 'game', 'animation', 'document', 'photo', 'sticker', 'video',
|
|
|
|
'voice', 'video_note', 'contact', 'location', 'venue', 'invoice',
|
2018-02-15 10:21:19 +01:00
|
|
|
'successful_payment']
|
|
|
|
MESSAGE_TYPES = ['text', 'new_chat_members', 'new_chat_title', 'new_chat_photo',
|
|
|
|
'delete_chat_photo', 'group_chat_created', 'supergroup_chat_created',
|
|
|
|
'channel_chat_created', 'migrate_to_chat_id', 'migrate_from_chat_id',
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
'pinned_message', 'passport_data'] + ATTACHMENT_TYPES
|
2018-02-15 10:21:19 +01:00
|
|
|
|
2016-10-16 16:24:13 +02:00
|
|
|
def __init__(self,
|
|
|
|
message_id,
|
|
|
|
from_user,
|
|
|
|
date,
|
|
|
|
chat,
|
|
|
|
forward_from=None,
|
|
|
|
forward_from_chat=None,
|
2017-07-23 22:33:08 +02:00
|
|
|
forward_from_message_id=None,
|
2016-10-16 16:24:13 +02:00
|
|
|
forward_date=None,
|
|
|
|
reply_to_message=None,
|
|
|
|
edit_date=None,
|
2016-12-30 13:57:59 +01:00
|
|
|
text=None,
|
2016-10-16 16:24:13 +02:00
|
|
|
entities=None,
|
2017-10-14 20:03:02 +02:00
|
|
|
caption_entities=None,
|
2016-10-16 16:24:13 +02:00
|
|
|
audio=None,
|
|
|
|
document=None,
|
2017-07-23 22:33:08 +02:00
|
|
|
game=None,
|
2016-10-16 16:24:13 +02:00
|
|
|
photo=None,
|
|
|
|
sticker=None,
|
|
|
|
video=None,
|
|
|
|
voice=None,
|
2017-07-23 22:33:08 +02:00
|
|
|
video_note=None,
|
|
|
|
new_chat_members=None,
|
2016-12-30 13:57:59 +01:00
|
|
|
caption=None,
|
2016-10-16 16:24:13 +02:00
|
|
|
contact=None,
|
|
|
|
location=None,
|
|
|
|
venue=None,
|
|
|
|
left_chat_member=None,
|
2016-12-30 13:57:59 +01:00
|
|
|
new_chat_title=None,
|
2016-10-16 16:24:13 +02:00
|
|
|
new_chat_photo=None,
|
|
|
|
delete_chat_photo=False,
|
|
|
|
group_chat_created=False,
|
|
|
|
supergroup_chat_created=False,
|
2017-07-23 22:33:08 +02:00
|
|
|
channel_chat_created=False,
|
2017-01-11 19:41:39 +01:00
|
|
|
migrate_to_chat_id=None,
|
|
|
|
migrate_from_chat_id=None,
|
2016-10-16 16:24:13 +02:00
|
|
|
pinned_message=None,
|
2017-05-19 20:06:58 +02:00
|
|
|
invoice=None,
|
|
|
|
successful_payment=None,
|
2017-09-01 08:40:05 +02:00
|
|
|
forward_signature=None,
|
|
|
|
author_signature=None,
|
2017-12-08 22:38:59 +01:00
|
|
|
media_group_id=None,
|
2018-02-18 16:11:04 +01:00
|
|
|
connected_website=None,
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
animation=None,
|
|
|
|
passport_data=None,
|
2016-10-16 16:24:13 +02:00
|
|
|
bot=None,
|
|
|
|
**kwargs):
|
2015-08-22 04:15:29 +02:00
|
|
|
# Required
|
|
|
|
self.message_id = int(message_id)
|
2015-07-09 02:58:13 +02:00
|
|
|
self.from_user = from_user
|
|
|
|
self.date = date
|
|
|
|
self.chat = chat
|
2015-08-22 04:15:29 +02:00
|
|
|
# Optionals
|
2016-10-16 16:24:13 +02:00
|
|
|
self.forward_from = forward_from
|
|
|
|
self.forward_from_chat = forward_from_chat
|
|
|
|
self.forward_date = forward_date
|
|
|
|
self.reply_to_message = reply_to_message
|
|
|
|
self.edit_date = edit_date
|
|
|
|
self.text = text
|
2016-10-17 00:11:20 +02:00
|
|
|
self.entities = entities or list()
|
2017-10-14 20:03:02 +02:00
|
|
|
self.caption_entities = caption_entities or list()
|
2016-10-16 16:24:13 +02:00
|
|
|
self.audio = audio
|
2017-06-14 13:48:45 +02:00
|
|
|
self.game = game
|
2016-10-16 16:24:13 +02:00
|
|
|
self.document = document
|
2017-08-11 23:58:41 +02:00
|
|
|
self.photo = photo or list()
|
2016-10-16 16:24:13 +02:00
|
|
|
self.sticker = sticker
|
|
|
|
self.video = video
|
|
|
|
self.voice = voice
|
2017-05-20 19:30:07 +02:00
|
|
|
self.video_note = video_note
|
2016-10-16 16:24:13 +02:00
|
|
|
self.caption = caption
|
|
|
|
self.contact = contact
|
|
|
|
self.location = location
|
|
|
|
self.venue = venue
|
2017-08-11 23:58:41 +02:00
|
|
|
self.new_chat_members = new_chat_members or list()
|
2016-10-16 16:24:13 +02:00
|
|
|
self.left_chat_member = left_chat_member
|
|
|
|
self.new_chat_title = new_chat_title
|
2017-08-11 23:58:41 +02:00
|
|
|
self.new_chat_photo = new_chat_photo or list()
|
2016-10-16 16:24:13 +02:00
|
|
|
self.delete_chat_photo = bool(delete_chat_photo)
|
|
|
|
self.group_chat_created = bool(group_chat_created)
|
|
|
|
self.supergroup_chat_created = bool(supergroup_chat_created)
|
2017-01-11 19:41:39 +01:00
|
|
|
self.migrate_to_chat_id = migrate_to_chat_id
|
|
|
|
self.migrate_from_chat_id = migrate_from_chat_id
|
2016-10-16 16:24:13 +02:00
|
|
|
self.channel_chat_created = bool(channel_chat_created)
|
|
|
|
self.pinned_message = pinned_message
|
2016-12-11 22:44:52 +01:00
|
|
|
self.forward_from_message_id = forward_from_message_id
|
2017-05-19 20:06:58 +02:00
|
|
|
self.invoice = invoice
|
|
|
|
self.successful_payment = successful_payment
|
2018-02-18 16:11:04 +01:00
|
|
|
self.connected_website = connected_website
|
2017-09-01 08:40:05 +02:00
|
|
|
self.forward_signature = forward_signature
|
|
|
|
self.author_signature = author_signature
|
2017-12-08 22:38:59 +01:00
|
|
|
self.media_group_id = media_group_id
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
self.animation = animation
|
|
|
|
self.passport_data = passport_data
|
2015-07-08 14:55:06 +02:00
|
|
|
|
2016-09-20 06:36:55 +02:00
|
|
|
self.bot = bot
|
|
|
|
|
2017-05-14 23:29:31 +02:00
|
|
|
self._id_attrs = (self.message_id,)
|
|
|
|
|
2015-07-08 14:37:25 +02:00
|
|
|
@property
|
|
|
|
def chat_id(self):
|
2017-09-01 08:43:08 +02:00
|
|
|
""":obj:`int`: Shortcut for :attr:`telegram.Chat.id` for :attr:`chat`."""
|
2015-07-08 14:37:25 +02:00
|
|
|
return self.chat.id
|
2015-07-07 21:50:36 +02:00
|
|
|
|
2018-05-09 11:42:12 +02:00
|
|
|
@property
|
|
|
|
def link(self):
|
|
|
|
""":obj:`str`: Convenience property. If the chat of the message is a supergroup or a
|
|
|
|
channel and has a :attr:`Chat.username`, returns a t.me link of the message."""
|
|
|
|
if self.chat.type in (Chat.SUPERGROUP, Chat.CHANNEL) and self.chat.username:
|
|
|
|
return "https://t.me/{}/{}".format(self.chat.username, self.message_id)
|
|
|
|
return None
|
|
|
|
|
2017-07-23 21:14:38 +02:00
|
|
|
@classmethod
|
|
|
|
def de_json(cls, data, bot):
|
2015-08-22 04:15:29 +02:00
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
2017-07-23 21:14:38 +02:00
|
|
|
data = super(Message, cls).de_json(data, bot)
|
2016-12-19 23:07:35 +01:00
|
|
|
|
2016-09-20 06:36:55 +02:00
|
|
|
data['from_user'] = User.de_json(data.get('from'), bot)
|
2017-07-01 17:08:45 +02:00
|
|
|
data['date'] = from_timestamp(data['date'])
|
2016-09-20 06:36:55 +02:00
|
|
|
data['chat'] = Chat.de_json(data.get('chat'), bot)
|
|
|
|
data['entities'] = MessageEntity.de_list(data.get('entities'), bot)
|
2017-10-14 20:03:02 +02:00
|
|
|
data['caption_entities'] = MessageEntity.de_list(data.get('caption_entities'), bot)
|
2016-09-20 06:36:55 +02:00
|
|
|
data['forward_from'] = User.de_json(data.get('forward_from'), bot)
|
|
|
|
data['forward_from_chat'] = Chat.de_json(data.get('forward_from_chat'), bot)
|
2017-07-01 17:08:45 +02:00
|
|
|
data['forward_date'] = from_timestamp(data.get('forward_date'))
|
2016-09-20 06:36:55 +02:00
|
|
|
data['reply_to_message'] = Message.de_json(data.get('reply_to_message'), bot)
|
2017-07-01 17:08:45 +02:00
|
|
|
data['edit_date'] = from_timestamp(data.get('edit_date'))
|
2016-09-20 06:36:55 +02:00
|
|
|
data['audio'] = Audio.de_json(data.get('audio'), bot)
|
|
|
|
data['document'] = Document.de_json(data.get('document'), bot)
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
data['animation'] = Animation.de_json(data.get('animation'), bot)
|
2016-10-03 20:22:57 +02:00
|
|
|
data['game'] = Game.de_json(data.get('game'), bot)
|
2016-09-20 06:36:55 +02:00
|
|
|
data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
|
|
|
|
data['sticker'] = Sticker.de_json(data.get('sticker'), bot)
|
|
|
|
data['video'] = Video.de_json(data.get('video'), bot)
|
|
|
|
data['voice'] = Voice.de_json(data.get('voice'), bot)
|
2017-05-20 19:30:07 +02:00
|
|
|
data['video_note'] = VideoNote.de_json(data.get('video_note'), bot)
|
2016-09-20 06:36:55 +02:00
|
|
|
data['contact'] = Contact.de_json(data.get('contact'), bot)
|
|
|
|
data['location'] = Location.de_json(data.get('location'), bot)
|
|
|
|
data['venue'] = Venue.de_json(data.get('venue'), bot)
|
2017-05-21 14:32:36 +02:00
|
|
|
data['new_chat_members'] = User.de_list(data.get('new_chat_members'), bot)
|
2016-09-20 06:36:55 +02:00
|
|
|
data['left_chat_member'] = User.de_json(data.get('left_chat_member'), bot)
|
|
|
|
data['new_chat_photo'] = PhotoSize.de_list(data.get('new_chat_photo'), bot)
|
|
|
|
data['pinned_message'] = Message.de_json(data.get('pinned_message'), bot)
|
2017-05-19 20:06:58 +02:00
|
|
|
data['invoice'] = Invoice.de_json(data.get('invoice'), bot)
|
|
|
|
data['successful_payment'] = SuccessfulPayment.de_json(data.get('successful_payment'), bot)
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
data['passport_data'] = PassportData.de_json(data.get('passport_data'), bot)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
2017-07-23 21:14:38 +02:00
|
|
|
return cls(bot=bot, **data)
|
2015-07-09 16:40:44 +02:00
|
|
|
|
2017-08-07 23:25:19 +02:00
|
|
|
@property
|
|
|
|
def effective_attachment(self):
|
|
|
|
"""
|
|
|
|
:class:`telegram.Audio`
|
|
|
|
or :class:`telegram.Contact`
|
|
|
|
or :class:`telegram.Document`
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
or :class:`telegram.Animation`
|
2017-08-07 23:25:19 +02:00
|
|
|
or :class:`telegram.Game`
|
|
|
|
or :class:`telegram.Invoice`
|
|
|
|
or :class:`telegram.Location`
|
|
|
|
or List[:class:`telegram.PhotoSize`]
|
|
|
|
or :class:`telegram.Sticker`
|
|
|
|
or :class:`telegram.SuccessfulPayment`
|
|
|
|
or :class:`telegram.Venue`
|
|
|
|
or :class:`telegram.Video`
|
|
|
|
or :class:`telegram.VideoNote`
|
|
|
|
or :class:`telegram.Voice`: The attachment that this message was sent with. May be
|
|
|
|
``None`` if no attachment was sent.
|
|
|
|
|
|
|
|
"""
|
|
|
|
if self._effective_attachment is not _UNDEFINED:
|
|
|
|
return self._effective_attachment
|
|
|
|
|
2018-02-15 10:21:19 +01:00
|
|
|
for i in Message.ATTACHMENT_TYPES:
|
|
|
|
if getattr(self, i, None):
|
|
|
|
self._effective_attachment = getattr(self, i)
|
2017-08-07 23:25:19 +02:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
self._effective_attachment = None
|
|
|
|
|
|
|
|
return self._effective_attachment
|
|
|
|
|
2015-09-07 04:55:00 +02:00
|
|
|
def __getitem__(self, item):
|
|
|
|
if item in self.__dict__.keys():
|
|
|
|
return self.__dict__[item]
|
|
|
|
elif item == 'chat_id':
|
|
|
|
return self.chat.id
|
|
|
|
|
2015-07-20 04:25:44 +02:00
|
|
|
def to_dict(self):
|
2015-08-28 22:45:44 +02:00
|
|
|
data = super(Message, self).to_dict()
|
2015-08-22 04:15:29 +02:00
|
|
|
|
|
|
|
# Required
|
2017-07-01 17:08:45 +02:00
|
|
|
data['date'] = to_timestamp(self.date)
|
2015-08-22 04:15:29 +02:00
|
|
|
# Optionals
|
2015-08-21 19:49:07 +02:00
|
|
|
if self.forward_date:
|
2017-07-01 17:08:45 +02:00
|
|
|
data['forward_date'] = to_timestamp(self.forward_date)
|
2016-05-24 01:28:36 +02:00
|
|
|
if self.edit_date:
|
2017-07-01 17:08:45 +02:00
|
|
|
data['edit_date'] = to_timestamp(self.edit_date)
|
2015-07-09 16:40:44 +02:00
|
|
|
if self.photo:
|
2015-07-20 04:25:44 +02:00
|
|
|
data['photo'] = [p.to_dict() for p in self.photo]
|
2016-04-18 21:35:39 +02:00
|
|
|
if self.entities:
|
|
|
|
data['entities'] = [e.to_dict() for e in self.entities]
|
2017-10-14 20:03:02 +02:00
|
|
|
if self.caption_entities:
|
|
|
|
data['caption_entities'] = [e.to_dict() for e in self.caption_entities]
|
2015-07-09 16:40:44 +02:00
|
|
|
if self.new_chat_photo:
|
2015-08-19 20:41:09 +02:00
|
|
|
data['new_chat_photo'] = [p.to_dict() for p in self.new_chat_photo]
|
2017-05-21 14:32:36 +02:00
|
|
|
if self.new_chat_members:
|
|
|
|
data['new_chat_members'] = [u.to_dict() for u in self.new_chat_members]
|
2015-08-21 19:49:07 +02:00
|
|
|
|
2015-07-20 04:06:04 +02:00
|
|
|
return data
|
2015-08-14 20:47:31 +02:00
|
|
|
|
2016-09-23 17:44:09 +02:00
|
|
|
def _quote(self, kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Modify kwargs for replying with or without quoting."""
|
2016-09-23 17:44:09 +02:00
|
|
|
if 'reply_to_message_id' in kwargs:
|
|
|
|
if 'quote' in kwargs:
|
|
|
|
del kwargs['quote']
|
|
|
|
|
|
|
|
elif 'quote' in kwargs:
|
|
|
|
if kwargs['quote']:
|
|
|
|
kwargs['reply_to_message_id'] = self.message_id
|
|
|
|
|
|
|
|
del kwargs['quote']
|
|
|
|
|
|
|
|
else:
|
|
|
|
if self.chat.type != Chat.PRIVATE:
|
|
|
|
kwargs['reply_to_message_id'] = self.message_id
|
|
|
|
|
2016-09-20 06:36:55 +02:00
|
|
|
def reply_text(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
bot.send_message(update.message.chat_id, *args, **kwargs)
|
2016-09-23 17:44:09 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the message is sent as an actual
|
|
|
|
reply to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this
|
|
|
|
parameter will be ignored. Default: ``True`` in group chats and ``False`` in
|
|
|
|
private chats.
|
2016-09-23 17:44:09 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-23 17:44:09 +02:00
|
|
|
self._quote(kwargs)
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.send_message(self.chat_id, *args, **kwargs)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
2018-02-12 14:39:46 +01:00
|
|
|
def reply_markdown(self, *args, **kwargs):
|
|
|
|
"""Shortcut for::
|
|
|
|
|
|
|
|
bot.send_message(update.message.chat_id, parse_mode=ParseMode.MARKDOWN, *args,
|
|
|
|
**kwargs)
|
|
|
|
|
|
|
|
Sends a message with markdown formatting.
|
|
|
|
|
|
|
|
Keyword Args:
|
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the message is sent as an actual
|
|
|
|
reply to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this
|
|
|
|
parameter will be ignored. Default: ``True`` in group chats and ``False`` in
|
|
|
|
private chats.
|
|
|
|
"""
|
|
|
|
|
|
|
|
kwargs['parse_mode'] = ParseMode.MARKDOWN
|
|
|
|
|
|
|
|
self._quote(kwargs)
|
|
|
|
|
|
|
|
return self.bot.send_message(self.chat_id, *args, **kwargs)
|
|
|
|
|
|
|
|
def reply_html(self, *args, **kwargs):
|
|
|
|
"""Shortcut for::
|
|
|
|
|
|
|
|
bot.send_message(update.message.chat_id, parse_mode=ParseMode.HTML, *args, **kwargs)
|
|
|
|
|
|
|
|
Sends a message with HTML formatting.
|
|
|
|
|
|
|
|
Keyword Args:
|
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the message is sent as an actual
|
|
|
|
reply to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this
|
|
|
|
parameter will be ignored. Default: ``True`` in group chats and ``False`` in
|
|
|
|
private chats.
|
|
|
|
"""
|
|
|
|
|
|
|
|
kwargs['parse_mode'] = ParseMode.HTML
|
|
|
|
|
|
|
|
self._quote(kwargs)
|
|
|
|
|
|
|
|
return self.bot.send_message(self.chat_id, *args, **kwargs)
|
|
|
|
|
2018-02-12 14:51:18 +01:00
|
|
|
def reply_media_group(self, *args, **kwargs):
|
|
|
|
"""Shortcut for::
|
|
|
|
|
|
|
|
bot.reply_media_group(update.message.chat_id, *args, **kwargs)
|
|
|
|
|
|
|
|
Keyword Args:
|
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the media group is sent as an
|
|
|
|
actual reply to this message. If ``reply_to_message_id`` is passed in ``kwargs``,
|
|
|
|
this parameter will be ignored. Default: ``True`` in group chats and ``False`` in
|
|
|
|
private chats.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
List[:class:`telegram.Message`]: An array of the sent Messages.
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
:class:`telegram.TelegramError`
|
|
|
|
"""
|
|
|
|
self._quote(kwargs)
|
|
|
|
return self.bot.send_media_group(self.chat_id, *args, **kwargs)
|
|
|
|
|
2016-09-20 06:36:55 +02:00
|
|
|
def reply_photo(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
bot.send_photo(update.message.chat_id, *args, **kwargs)
|
2016-09-23 17:44:09 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
2016-09-23 17:44:09 +02:00
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
2016-12-11 22:44:52 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
2016-09-23 17:44:09 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-23 17:44:09 +02:00
|
|
|
self._quote(kwargs)
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.send_photo(self.chat_id, *args, **kwargs)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
|
|
|
def reply_audio(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
bot.send_audio(update.message.chat_id, *args, **kwargs)
|
2016-09-23 17:44:09 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
2016-09-23 17:44:09 +02:00
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
2016-12-11 22:44:52 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
2016-09-23 17:44:09 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-23 17:44:09 +02:00
|
|
|
self._quote(kwargs)
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.send_audio(self.chat_id, *args, **kwargs)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
|
|
|
def reply_document(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
bot.send_document(update.message.chat_id, *args, **kwargs)
|
2016-09-23 17:44:09 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
2016-09-23 17:44:09 +02:00
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
2016-12-11 22:44:52 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
2016-09-23 17:44:09 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-23 17:44:09 +02:00
|
|
|
self._quote(kwargs)
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.send_document(self.chat_id, *args, **kwargs)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
def reply_animation(self, *args, **kwargs):
|
|
|
|
"""Shortcut for::
|
|
|
|
|
|
|
|
bot.send_animation(update.message.chat_id, *args, **kwargs)
|
|
|
|
|
|
|
|
Keyword Args:
|
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
|
|
|
|
|
|
|
"""
|
|
|
|
self._quote(kwargs)
|
|
|
|
return self.bot.send_animation(self.chat_id, *args, **kwargs)
|
|
|
|
|
2016-09-20 06:36:55 +02:00
|
|
|
def reply_sticker(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
bot.send_sticker(update.message.chat_id, *args, **kwargs)
|
2016-09-23 17:44:09 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
2016-09-23 17:44:09 +02:00
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
2016-12-11 22:44:52 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
2016-09-23 17:44:09 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-23 17:44:09 +02:00
|
|
|
self._quote(kwargs)
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.send_sticker(self.chat_id, *args, **kwargs)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
|
|
|
def reply_video(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
bot.send_video(update.message.chat_id, *args, **kwargs)
|
2016-09-23 17:44:09 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
2016-09-23 17:44:09 +02:00
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
2016-12-11 22:44:52 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
2016-09-23 17:44:09 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-23 17:44:09 +02:00
|
|
|
self._quote(kwargs)
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.send_video(self.chat_id, *args, **kwargs)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
2017-05-21 13:51:27 +02:00
|
|
|
def reply_video_note(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
bot.send_video_note(update.message.chat_id, *args, **kwargs)
|
2017-05-21 13:51:27 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
2017-05-21 13:51:27 +02:00
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2017-05-21 13:51:27 +02:00
|
|
|
self._quote(kwargs)
|
|
|
|
return self.bot.send_video_note(self.chat_id, *args, **kwargs)
|
|
|
|
|
2016-09-20 06:36:55 +02:00
|
|
|
def reply_voice(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
bot.send_voice(update.message.chat_id, *args, **kwargs)
|
2016-09-23 17:44:09 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
2016-09-23 17:44:09 +02:00
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
2016-12-11 22:44:52 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
2016-09-23 17:44:09 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-23 17:44:09 +02:00
|
|
|
self._quote(kwargs)
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.send_voice(self.chat_id, *args, **kwargs)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
|
|
|
def reply_location(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
bot.send_location(update.message.chat_id, *args, **kwargs)
|
2016-09-23 17:44:09 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
2016-09-23 17:44:09 +02:00
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
2016-12-11 22:44:52 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
2016-09-23 17:44:09 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-23 17:44:09 +02:00
|
|
|
self._quote(kwargs)
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.send_location(self.chat_id, *args, **kwargs)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
|
|
|
def reply_venue(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
bot.send_venue(update.message.chat_id, *args, **kwargs)
|
2016-09-23 17:44:09 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
2016-09-23 17:44:09 +02:00
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
2016-12-11 22:44:52 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
2016-09-23 17:44:09 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-23 17:44:09 +02:00
|
|
|
self._quote(kwargs)
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.send_venue(self.chat_id, *args, **kwargs)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
|
|
|
def reply_contact(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-07-23 22:33:08 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
bot.send_contact(update.message.chat_id, *args, **kwargs)
|
2016-09-23 17:44:09 +02:00
|
|
|
|
|
|
|
Keyword Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
|
|
|
to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
2016-09-23 17:44:09 +02:00
|
|
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
2016-12-11 22:44:52 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message posted.
|
2016-09-23 17:44:09 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-23 17:44:09 +02:00
|
|
|
self._quote(kwargs)
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.send_contact(self.chat_id, *args, **kwargs)
|
2016-09-20 06:36:55 +02:00
|
|
|
|
|
|
|
def forward(self, chat_id, disable_notification=False):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2016-09-20 06:36:55 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
bot.forward_message(chat_id=chat_id,
|
|
|
|
from_chat_id=update.message.chat_id,
|
|
|
|
disable_notification=disable_notification,
|
|
|
|
message_id=update.message.message_id)
|
2016-12-11 22:44:52 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the message forwarded.
|
2017-07-23 22:33:08 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2017-06-14 00:07:03 +02:00
|
|
|
return self.bot.forward_message(
|
2016-09-20 06:36:55 +02:00
|
|
|
chat_id=chat_id,
|
|
|
|
from_chat_id=self.chat_id,
|
|
|
|
disable_notification=disable_notification,
|
|
|
|
message_id=self.message_id)
|
|
|
|
|
2016-09-25 15:50:58 +02:00
|
|
|
def edit_text(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2016-11-01 06:53:51 +01:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
bot.edit_message_text(chat_id=message.chat_id,
|
|
|
|
message_id=message.message_id,
|
|
|
|
*args,
|
|
|
|
**kwargs)
|
2016-09-25 15:50:58 +02:00
|
|
|
|
|
|
|
Note:
|
|
|
|
You can only edit messages that the bot sent itself,
|
|
|
|
therefore this method can only be used on the
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
return value of the ``bot.send_*`` family of methods.
|
2016-12-11 22:44:52 +01:00
|
|
|
|
2017-07-23 22:33:08 +02:00
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the edited message.
|
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-25 15:50:58 +02:00
|
|
|
return self.bot.edit_message_text(
|
|
|
|
chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs)
|
|
|
|
|
|
|
|
def edit_caption(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2016-11-01 06:53:51 +01:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
bot.edit_message_caption(chat_id=message.chat_id,
|
|
|
|
message_id=message.message_id,
|
|
|
|
*args,
|
|
|
|
**kwargs)
|
2016-09-25 15:50:58 +02:00
|
|
|
|
|
|
|
Note:
|
|
|
|
You can only edit messages that the bot sent itself,
|
|
|
|
therefore this method can only be used on the
|
2016-11-01 06:53:51 +01:00
|
|
|
return value of the ``bot.send_*`` family of methods.
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the edited message.
|
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-25 15:50:58 +02:00
|
|
|
return self.bot.edit_message_caption(
|
|
|
|
chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs)
|
|
|
|
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
def edit_media(self, media, *args, **kwargs):
|
|
|
|
"""Shortcut for::
|
|
|
|
|
|
|
|
bot.edit_message_media(chat_id=message.chat_id,
|
|
|
|
message_id=message.message_id,
|
|
|
|
*args,
|
|
|
|
**kwargs)
|
|
|
|
|
|
|
|
Note:
|
|
|
|
You can only edit messages that the bot sent itself,
|
|
|
|
therefore this method can only be used on the
|
|
|
|
return value of the ``bot.send_*`` family of methods.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the edited
|
|
|
|
message.
|
|
|
|
|
|
|
|
"""
|
|
|
|
return self.bot.edit_message_media(
|
|
|
|
chat_id=self.chat_id, message_id=self.message_id, media=media, *args, **kwargs)
|
|
|
|
|
2016-09-25 15:50:58 +02:00
|
|
|
def edit_reply_markup(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2016-11-01 06:53:51 +01:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
bot.edit_message_reply_markup(chat_id=message.chat_id,
|
|
|
|
message_id=message.message_id,
|
|
|
|
*args,
|
|
|
|
**kwargs)
|
2016-09-25 15:50:58 +02:00
|
|
|
|
|
|
|
Note:
|
|
|
|
You can only edit messages that the bot sent itself,
|
|
|
|
therefore this method can only be used on the
|
2016-11-01 06:53:51 +01:00
|
|
|
return value of the ``bot.send_*`` family of methods.
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.Message`: On success, instance representing the edited message.
|
2016-09-25 15:50:58 +02:00
|
|
|
"""
|
2016-12-08 13:23:51 +01:00
|
|
|
return self.bot.edit_message_reply_markup(
|
2016-09-25 15:50:58 +02:00
|
|
|
chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs)
|
2017-05-12 17:40:57 +02:00
|
|
|
|
|
|
|
def delete(self, *args, **kwargs):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Shortcut for::
|
2017-05-12 17:40:57 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
bot.delete_message(chat_id=message.chat_id,
|
|
|
|
message_id=message.message_id,
|
|
|
|
*args,
|
|
|
|
**kwargs)
|
2017-05-12 17:40:57 +02:00
|
|
|
|
|
|
|
Returns:
|
2017-07-23 22:33:08 +02:00
|
|
|
:obj:`bool`: On success, ``True`` is returned.
|
2017-05-12 17:40:57 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
return self.bot.delete_message(
|
|
|
|
chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs)
|
2016-09-25 15:50:58 +02:00
|
|
|
|
2016-09-07 08:49:09 +02:00
|
|
|
def parse_entity(self, entity):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Returns the text from a given :class:`telegram.MessageEntity`.
|
2016-09-07 08:49:09 +02:00
|
|
|
|
|
|
|
Note:
|
|
|
|
This method is present because Telegram calculates the offset and length in
|
|
|
|
UTF-16 codepoint pairs, which some versions of Python don't handle automatically.
|
|
|
|
(That is, you can't just slice ``Message.text`` with the offset and length.)
|
|
|
|
|
|
|
|
Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
entity (:class:`telegram.MessageEntity`): The entity to extract the text from. It must
|
|
|
|
be an entity that belongs to this message.
|
2016-09-07 08:49:09 +02:00
|
|
|
|
|
|
|
Returns:
|
2017-10-14 20:03:02 +02:00
|
|
|
:obj:`str`: The text of the given entity
|
2017-07-23 22:33:08 +02:00
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-07 08:49:09 +02:00
|
|
|
# Is it a narrow build, if so we don't need to convert
|
|
|
|
if sys.maxunicode == 0xffff:
|
|
|
|
return self.text[entity.offset:entity.offset + entity.length]
|
|
|
|
else:
|
|
|
|
entity_text = self.text.encode('utf-16-le')
|
|
|
|
entity_text = entity_text[entity.offset * 2:(entity.offset + entity.length) * 2]
|
|
|
|
|
|
|
|
return entity_text.decode('utf-16-le')
|
|
|
|
|
2017-10-14 20:03:02 +02:00
|
|
|
def parse_caption_entity(self, entity):
|
|
|
|
"""Returns the text from a given :class:`telegram.MessageEntity`.
|
|
|
|
|
|
|
|
Note:
|
|
|
|
This method is present because Telegram calculates the offset and length in
|
|
|
|
UTF-16 codepoint pairs, which some versions of Python don't handle automatically.
|
|
|
|
(That is, you can't just slice ``Message.caption`` with the offset and length.)
|
|
|
|
|
|
|
|
Args:
|
|
|
|
entity (:class:`telegram.MessageEntity`): The entity to extract the text from. It must
|
|
|
|
be an entity that belongs to this message.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`str`: The text of the given entity
|
|
|
|
|
|
|
|
"""
|
|
|
|
# Is it a narrow build, if so we don't need to convert
|
|
|
|
if sys.maxunicode == 0xffff:
|
|
|
|
return self.caption[entity.offset:entity.offset + entity.length]
|
|
|
|
else:
|
|
|
|
entity_text = self.caption.encode('utf-16-le')
|
|
|
|
entity_text = entity_text[entity.offset * 2:(entity.offset + entity.length) * 2]
|
|
|
|
|
|
|
|
return entity_text.decode('utf-16-le')
|
|
|
|
|
2016-09-07 08:49:09 +02:00
|
|
|
def parse_entities(self, types=None):
|
|
|
|
"""
|
2017-07-23 22:33:08 +02:00
|
|
|
Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`.
|
|
|
|
It contains entities from this message filtered by their
|
|
|
|
:attr:`telegram.MessageEntity.type` attribute as the key, and the text that each entity
|
|
|
|
belongs to as the value of the :obj:`dict`.
|
2016-09-07 08:49:09 +02:00
|
|
|
|
|
|
|
Note:
|
2017-07-23 22:33:08 +02:00
|
|
|
This method should always be used instead of the :attr:`entities` attribute, since it
|
2016-09-07 08:49:09 +02:00
|
|
|
calculates the correct substring from the message text based on UTF-16 codepoints.
|
2017-07-23 22:33:08 +02:00
|
|
|
See :attr:`parse_entity` for more info.
|
2016-09-07 08:49:09 +02:00
|
|
|
|
|
|
|
Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
types (List[:obj:`str`], optional): List of :class:`telegram.MessageEntity` types as
|
|
|
|
strings. If the ``type`` attribute of an entity is contained in this list, it will
|
|
|
|
be returned. Defaults to a list of all types. All types can be found as constants
|
|
|
|
in :class:`telegram.MessageEntity`.
|
2016-09-07 08:49:09 +02:00
|
|
|
|
|
|
|
Returns:
|
2017-07-23 22:33:08 +02:00
|
|
|
Dict[:class:`telegram.MessageEntity`, :obj:`str`]: A dictionary of entities mapped to
|
|
|
|
the text that belongs to them, calculated based on UTF-16 codepoints.
|
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2016-09-07 08:49:09 +02:00
|
|
|
if types is None:
|
|
|
|
types = MessageEntity.ALL_TYPES
|
|
|
|
|
2016-10-12 22:56:57 +02:00
|
|
|
return {
|
|
|
|
entity: self.parse_entity(entity)
|
|
|
|
for entity in self.entities if entity.type in types
|
|
|
|
}
|
2017-01-20 20:13:58 +01:00
|
|
|
|
2017-10-14 20:03:02 +02:00
|
|
|
def parse_caption_entities(self, types=None):
|
|
|
|
"""
|
|
|
|
Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`.
|
|
|
|
It contains entities from this message's caption filtered by their
|
|
|
|
:attr:`telegram.MessageEntity.type` attribute as the key, and the text that each entity
|
|
|
|
belongs to as the value of the :obj:`dict`.
|
|
|
|
|
|
|
|
Note:
|
|
|
|
This method should always be used instead of the :attr:`caption_entities` attribute,
|
|
|
|
since it calculates the correct substring from the message text based on UTF-16
|
|
|
|
codepoints. See :attr:`parse_entity` for more info.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
types (List[:obj:`str`], optional): List of :class:`telegram.MessageEntity` types as
|
|
|
|
strings. If the ``type`` attribute of an entity is contained in this list, it will
|
|
|
|
be returned. Defaults to a list of all types. All types can be found as constants
|
|
|
|
in :class:`telegram.MessageEntity`.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Dict[:class:`telegram.MessageEntity`, :obj:`str`]: A dictionary of entities mapped to
|
|
|
|
the text that belongs to them, calculated based on UTF-16 codepoints.
|
|
|
|
|
|
|
|
"""
|
|
|
|
if types is None:
|
|
|
|
types = MessageEntity.ALL_TYPES
|
|
|
|
|
|
|
|
return {
|
|
|
|
entity: self.parse_caption_entity(entity)
|
|
|
|
for entity in self.caption_entities if entity.type in types
|
|
|
|
}
|
|
|
|
|
2018-02-22 16:38:54 +01:00
|
|
|
@staticmethod
|
|
|
|
def _parse_html(message_text, entities, urled=False):
|
2018-03-16 21:42:39 +01:00
|
|
|
if message_text is None:
|
|
|
|
return None
|
|
|
|
|
2017-05-21 14:00:07 +02:00
|
|
|
if not sys.maxunicode == 0xffff:
|
|
|
|
message_text = message_text.encode('utf-16-le')
|
|
|
|
|
2017-08-07 23:10:48 +02:00
|
|
|
html_text = ''
|
2017-01-20 20:13:58 +01:00
|
|
|
last_offset = 0
|
|
|
|
|
|
|
|
for entity, text in sorted(entities.items(), key=(lambda item: item[0].offset)):
|
2018-02-22 16:38:54 +01:00
|
|
|
text = escape(text)
|
2017-01-20 20:13:58 +01:00
|
|
|
|
|
|
|
if entity.type == MessageEntity.TEXT_LINK:
|
|
|
|
insert = '<a href="{}">{}</a>'.format(entity.url, text)
|
2018-09-25 20:07:55 +02:00
|
|
|
elif entity.type == MessageEntity.TEXT_MENTION and entity.user:
|
|
|
|
insert = '<a href="tg://user?id={}">{}</a>'.format(entity.user.id, text)
|
|
|
|
elif entity.type == MessageEntity.URL and urled:
|
2017-06-24 00:12:55 +02:00
|
|
|
insert = '<a href="{0}">{0}</a>'.format(text)
|
2017-01-20 20:13:58 +01:00
|
|
|
elif entity.type == MessageEntity.BOLD:
|
|
|
|
insert = '<b>' + text + '</b>'
|
|
|
|
elif entity.type == MessageEntity.ITALIC:
|
|
|
|
insert = '<i>' + text + '</i>'
|
|
|
|
elif entity.type == MessageEntity.CODE:
|
|
|
|
insert = '<code>' + text + '</code>'
|
|
|
|
elif entity.type == MessageEntity.PRE:
|
|
|
|
insert = '<pre>' + text + '</pre>'
|
|
|
|
else:
|
|
|
|
insert = text
|
|
|
|
|
2017-05-21 14:00:07 +02:00
|
|
|
if sys.maxunicode == 0xffff:
|
2018-02-22 16:38:54 +01:00
|
|
|
html_text += escape(message_text[last_offset:entity.offset]) + insert
|
2017-05-21 14:00:07 +02:00
|
|
|
else:
|
2018-02-22 16:38:54 +01:00
|
|
|
html_text += escape(message_text[last_offset * 2:entity.offset * 2]
|
|
|
|
.decode('utf-16-le')) + insert
|
2017-05-21 14:00:07 +02:00
|
|
|
|
2017-01-20 20:13:58 +01:00
|
|
|
last_offset = entity.offset + entity.length
|
|
|
|
|
2017-05-21 14:00:07 +02:00
|
|
|
if sys.maxunicode == 0xffff:
|
2018-02-22 16:38:54 +01:00
|
|
|
html_text += escape(message_text[last_offset:])
|
2017-05-21 14:00:07 +02:00
|
|
|
else:
|
2018-02-22 16:38:54 +01:00
|
|
|
html_text += escape(message_text[last_offset * 2:].decode('utf-16-le'))
|
2017-08-07 23:10:48 +02:00
|
|
|
return html_text
|
2017-01-20 20:13:58 +01:00
|
|
|
|
|
|
|
@property
|
2017-08-07 23:10:48 +02:00
|
|
|
def text_html(self):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Creates an HTML-formatted string from the markup entities found in the message.
|
2017-01-20 20:13:58 +01:00
|
|
|
|
2017-08-07 23:10:48 +02:00
|
|
|
Use this if you want to retrieve the message text with the entities formatted as HTML in
|
|
|
|
the same way the original message was formatted.
|
2017-01-20 20:13:58 +01:00
|
|
|
|
|
|
|
Returns:
|
2017-08-07 23:10:48 +02:00
|
|
|
:obj:`str`: Message text with entities formatted as HTML.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2017-08-07 23:10:48 +02:00
|
|
|
"""
|
2018-02-22 16:38:54 +01:00
|
|
|
return self._parse_html(self.text, self.parse_entities(), urled=False)
|
2017-08-07 23:10:48 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def text_html_urled(self):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Creates an HTML-formatted string from the markup entities found in the message.
|
2017-08-07 23:10:48 +02:00
|
|
|
|
|
|
|
Use this if you want to retrieve the message text with the entities formatted as HTML.
|
|
|
|
This also formats :attr:`telegram.MessageEntity.URL` as a hyperlink.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`str`: Message text with entities formatted as HTML.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2017-01-20 20:13:58 +01:00
|
|
|
"""
|
2018-02-22 16:38:54 +01:00
|
|
|
return self._parse_html(self.text, self.parse_entities(), urled=True)
|
2017-07-23 22:33:08 +02:00
|
|
|
|
2018-02-22 16:38:54 +01:00
|
|
|
@property
|
|
|
|
def caption_html(self):
|
|
|
|
"""Creates an HTML-formatted string from the markup entities found in the message's
|
|
|
|
caption.
|
|
|
|
|
|
|
|
Use this if you want to retrieve the message caption with the caption entities formatted as
|
|
|
|
HTML in the same way the original message was formatted.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`str`: Message caption with captionentities formatted as HTML.
|
|
|
|
|
|
|
|
"""
|
|
|
|
return self._parse_html(self.caption, self.parse_caption_entities(), urled=False)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def caption_html_urled(self):
|
|
|
|
"""Creates an HTML-formatted string from the markup entities found in the message's
|
|
|
|
caption.
|
|
|
|
|
|
|
|
Use this if you want to retrieve the message caption with the caption entities formatted as
|
|
|
|
HTML. This also formats :attr:`telegram.MessageEntity.URL` as a hyperlink.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`str`: Message caption with caption entities formatted as HTML.
|
|
|
|
|
|
|
|
"""
|
|
|
|
return self._parse_html(self.caption, self.parse_caption_entities(), urled=True)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _parse_markdown(message_text, entities, urled=False):
|
2018-03-16 21:42:39 +01:00
|
|
|
if message_text is None:
|
|
|
|
return None
|
|
|
|
|
2017-05-21 14:00:07 +02:00
|
|
|
if not sys.maxunicode == 0xffff:
|
|
|
|
message_text = message_text.encode('utf-16-le')
|
|
|
|
|
2017-01-20 20:13:58 +01:00
|
|
|
markdown_text = ''
|
|
|
|
last_offset = 0
|
|
|
|
|
|
|
|
for entity, text in sorted(entities.items(), key=(lambda item: item[0].offset)):
|
2017-05-19 19:11:40 +02:00
|
|
|
text = escape_markdown(text)
|
2017-01-20 20:13:58 +01:00
|
|
|
|
|
|
|
if entity.type == MessageEntity.TEXT_LINK:
|
|
|
|
insert = '[{}]({})'.format(text, entity.url)
|
2018-09-25 20:07:55 +02:00
|
|
|
elif entity.type == MessageEntity.TEXT_MENTION and entity.user:
|
|
|
|
insert = '[{}](tg://user?id={})'.format(text, entity.user.id)
|
|
|
|
elif entity.type == MessageEntity.URL and urled:
|
2017-06-24 00:12:55 +02:00
|
|
|
insert = '[{0}]({0})'.format(text)
|
2017-01-20 20:13:58 +01:00
|
|
|
elif entity.type == MessageEntity.BOLD:
|
|
|
|
insert = '*' + text + '*'
|
|
|
|
elif entity.type == MessageEntity.ITALIC:
|
|
|
|
insert = '_' + text + '_'
|
|
|
|
elif entity.type == MessageEntity.CODE:
|
|
|
|
insert = '`' + text + '`'
|
|
|
|
elif entity.type == MessageEntity.PRE:
|
|
|
|
insert = '```' + text + '```'
|
|
|
|
else:
|
|
|
|
insert = text
|
2017-05-21 14:00:07 +02:00
|
|
|
if sys.maxunicode == 0xffff:
|
|
|
|
markdown_text += escape_markdown(message_text[last_offset:entity.offset]) + insert
|
|
|
|
else:
|
|
|
|
markdown_text += escape_markdown(message_text[last_offset * 2:entity.offset * 2]
|
|
|
|
.decode('utf-16-le')) + insert
|
2017-01-20 20:13:58 +01:00
|
|
|
|
|
|
|
last_offset = entity.offset + entity.length
|
|
|
|
|
2017-05-21 14:00:07 +02:00
|
|
|
if sys.maxunicode == 0xffff:
|
|
|
|
markdown_text += escape_markdown(message_text[last_offset:])
|
|
|
|
else:
|
|
|
|
markdown_text += escape_markdown(message_text[last_offset * 2:].decode('utf-16-le'))
|
2017-01-20 20:13:58 +01:00
|
|
|
return markdown_text
|
2017-05-25 14:02:41 +02:00
|
|
|
|
2017-08-07 23:10:48 +02:00
|
|
|
@property
|
|
|
|
def text_markdown(self):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Creates an Markdown-formatted string from the markup entities found in the message.
|
2017-08-07 23:10:48 +02:00
|
|
|
|
|
|
|
Use this if you want to retrieve the message text with the entities formatted as Markdown
|
|
|
|
in the same way the original message was formatted.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`str`: Message text with entities formatted as Markdown.
|
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2018-02-22 16:38:54 +01:00
|
|
|
return self._parse_markdown(self.text, self.parse_entities(), urled=False)
|
2017-08-07 23:10:48 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def text_markdown_urled(self):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Creates an Markdown-formatted string from the markup entities found in the message.
|
2017-08-07 23:10:48 +02:00
|
|
|
|
|
|
|
Use this if you want to retrieve the message text with the entities formatted as Markdown.
|
|
|
|
This also formats :attr:`telegram.MessageEntity.URL` as a hyperlink.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`str`: Message text with entities formatted as Markdown.
|
|
|
|
|
2017-09-01 08:43:08 +02:00
|
|
|
"""
|
2018-02-22 16:38:54 +01:00
|
|
|
return self._parse_markdown(self.text, self.parse_entities(), urled=True)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def caption_markdown(self):
|
|
|
|
"""Creates an Markdown-formatted string from the markup entities found in the message's
|
|
|
|
caption.
|
|
|
|
|
|
|
|
Use this if you want to retrieve the message caption with the caption entities formatted as
|
|
|
|
Markdown in the same way the original message was formatted.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`str`: Message caption with caption entities formatted as Markdown.
|
|
|
|
|
|
|
|
"""
|
|
|
|
return self._parse_markdown(self.caption, self.parse_caption_entities(), urled=False)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def caption_markdown_urled(self):
|
|
|
|
"""Creates an Markdown-formatted string from the markup entities found in the message's
|
|
|
|
caption.
|
|
|
|
|
|
|
|
Use this if you want to retrieve the message caption with the caption entities formatted as
|
|
|
|
Markdown. This also formats :attr:`telegram.MessageEntity.URL` as a hyperlink.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`str`: Message caption with caption entities formatted as Markdown.
|
|
|
|
|
|
|
|
"""
|
|
|
|
return self._parse_markdown(self.caption, self.parse_caption_entities(), urled=True)
|