telegram.TelegramObject¶
- class telegram.TelegramObject(*args, **kwargs)[source]¶
Bases:
object
Base class for most Telegram objects.
Objects of this type are subscriptable with strings, where
telegram_object[attribute_name]
is equivalent totelegram_object.attribute_name
. If the object does not have an attribute with the appropriate name, aKeyError
will be raised.When objects of this type are pickled, the
Bot
attribute associated with the object will be removed. However, when copying the object viacopy.deepcopy()
, the copy will have the same bot instance associated with it, i.e:assert telegram_object.get_bot() is copy.deepcopy(telegram_object).get_bot()
Changed in version 20.0:
telegram_object['from']
will look up the keyfrom_user
. This is to account for special cases likeMessage.from_user
that deviate from the official Bot API.- classmethod de_json(data, bot)[source]¶
Converts JSON data to a Telegram object.
- Parameters
bot (
telegram.Bot
) – The bot associated with this object.
- Returns
The Telegram object.
- classmethod de_list(data, bot)[source]¶
Converts JSON data to a list of Telegram objects.
- Parameters
bot (
telegram.Bot
) – The bot associated with these objects.
- Returns
A list of Telegram objects.
- get_bot()[source]¶
Returns the
telegram.Bot
instance associated with this object.See also
- Raises
RuntimeError – If no
telegram.Bot
instance was set for this object.
- set_bot(bot)[source]¶
Sets the
telegram.Bot
instance associated with this object.See also
- Parameters
bot (
telegram.Bot
|None
) – The bot instance.