How to get only unread messages from chat using telethon?

Tags: ,



I have client.get_messages(dialog.entity) but its return just messages without “read/unread mark”… So, how can I get unread new messages only? Anybody know? 😥

Answer

Each dialog has unread_count

x = [[d.unread_count, d.title] for d in client.get_dialogs() if not getattr(d.entity, 'is_private', False) and d.unread_count != 0]
x = [[d.unread_count, d.title] for d in client.get_dialogs() if not getattr(d.entity, 'megagroup', False) and d.unread_count != 0]


Source: stackoverflow