From 9604161c91b18169ba6de6e02d349d2091d8c29b Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 26 Feb 2018 12:14:21 +0100 Subject: [PATCH] Fix incoming private messages not working with whitelists For some reason this was only happening with bots and not actual private messages. The fix doesn't seem to affect previous behaviour with actual users in private messages. --- telethon/events/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/telethon/events/__init__.py b/telethon/events/__init__.py index 204609c0..1f3b15f2 100644 --- a/telethon/events/__init__.py +++ b/telethon/events/__init__.py @@ -277,7 +277,14 @@ class NewMessage(_EventBuilder): Whether the message is a reply to some other or not. """ def __init__(self, message): - super().__init__(chat_peer=message.to_id, + if not message.out and isinstance(message.to_id, types.PeerUser): + # Incoming message (e.g. from a bot) has to_id=us, and + # from_id=bot (the actual "chat" from an user's perspective). + chat_peer = types.PeerUser(message.from_id) + else: + chat_peer = message.to_id + + super().__init__(chat_peer=chat_peer, msg_id=message.id, broadcast=bool(message.post)) self.message = message