diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index fdae5c5c..bcdc2dea 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -376,6 +376,9 @@ class Message(Object, Update): reactions (List of :obj:`~pyrogram.types.Reaction`): List of the reactions to this message. + raw (``pyrogram.raw.types.Message``, *optional*): + The raw message object, as received from the Telegram API. + link (``str``, *property*): Generate a link to this message, only for groups and channels. """ @@ -483,7 +486,8 @@ class Message(Object, Update): "types.ReplyKeyboardRemove", "types.ForceReply" ] = None, - reactions: List["types.Reaction"] = None + reactions: List["types.Reaction"] = None, + raw: "raw.types.Message" = None ): super().__init__(client) @@ -577,9 +581,10 @@ class Message(Object, Update): self.gift_code = gift_code self.requested_chats = requested_chats self.giveaway_launched = giveaway_launched - self.reactions = reactions self.chat_ttl_period = chat_ttl_period self.boosts_applied = boosts_applied + self.reactions = reactions + self.raw = raw @staticmethod async def _parse( @@ -592,7 +597,7 @@ class Message(Object, Update): replies: int = 1 ): if isinstance(message, raw.types.MessageEmpty): - return Message(id=message.id, empty=True, client=client) + return Message(id=message.id, empty=True, client=client, raw=message) from_id = utils.get_raw_peer_id(message.from_id) peer_id = utils.get_raw_peer_id(message.peer_id) @@ -769,6 +774,7 @@ class Message(Object, Update): requested_chats=requested_chats, chat_ttl_period=chat_ttl_period, boosts_applied=boosts_applied, + raw=message, client=client # TODO: supergroup_chat_created ) @@ -1047,6 +1053,7 @@ class Message(Object, Update): outgoing=message.out, reply_markup=reply_markup, reactions=reactions, + raw=message, client=client ) diff --git a/pyrogram/types/object.py b/pyrogram/types/object.py index 3253c8ec..aa898e6a 100644 --- a/pyrogram/types/object.py +++ b/pyrogram/types/object.py @@ -60,16 +60,22 @@ class Object: if isinstance(obj, datetime): return str(obj) + attributes_to_hide = [ + "raw" + ] + + filtered_attributes = { + attr: ("*" * 9 if attr == "phone_number" else getattr(obj, attr)) + for attr in filter( + lambda x: not x.startswith("_") and x not in attributes_to_hide, + obj.__dict__, + ) + if getattr(obj, attr) is not None + } + return { "_": obj.__class__.__name__, - **{ - attr: ( - "*" * 9 if attr == "phone_number" else - getattr(obj, attr) - ) - for attr in filter(lambda x: not x.startswith("_"), obj.__dict__) - if getattr(obj, attr) is not None - } + **filtered_attributes } def __str__(self) -> str: