diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index e0954b59..f9599469 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -374,6 +374,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. @@ -486,7 +489,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) @@ -582,6 +586,7 @@ class Message(Object, Update): self.video_chat_members_invited = video_chat_members_invited self.web_app_data = web_app_data self.reactions = reactions + self.raw = raw async def wait_for_click( self, @@ -631,7 +636,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) @@ -812,6 +817,7 @@ class Message(Object, Update): web_app_data=web_app_data, giveaway_launched=giveaway_launched, giveaway_result=giveaway_result, + raw=message, client=client # TODO: supergroup_chat_created ) @@ -1080,6 +1086,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 f19a2a75..60dc2dd1 100644 --- a/pyrogram/types/object.py +++ b/pyrogram/types/object.py @@ -61,16 +61,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: