diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index 50727ce2..63252de2 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -447,8 +447,10 @@ class TelegramClient(TelegramBareClient): total_messages = getattr(result, 'count', len(result.messages)) # Iterate over all the messages and find the sender User - entities = [find_user_or_chat(msg.from_id, result.users, result.chats) - for msg in result.messages] + entities = [find_user_or_chat(m.from_id, result.users, result.chats) + if m.from_id is not None else + find_user_or_chat(m.to_id, result.users, result.chats) + for m in result.messages] return total_messages, result.messages, entities diff --git a/telethon_examples/interactive_telegram_client.py b/telethon_examples/interactive_telegram_client.py index 6784d411..748f4142 100644 --- a/telethon_examples/interactive_telegram_client.py +++ b/telethon_examples/interactive_telegram_client.py @@ -162,7 +162,14 @@ class InteractiveTelegramClient(TelegramClient): for msg, sender in zip( reversed(messages), reversed(senders)): # Get the name of the sender if any - name = sender.first_name if sender else '???' + if sender: + name = getattr(sender, 'first_name', None) + if not name: + name = getattr(sender, 'title') + if not name: + name = '???' + else: + name = '???' # Format the message content if getattr(msg, 'media', None):