Search code examples
botstelegramtelethon

How to get the list of latest chats that I have in telegram


I want to write a program that gets the list of the latest chats that I had in telegram and their not in my contacts. I tried telethon but I couldn't do it for the users that are not in my contacts


Solution

  • If by "latest chats" you refer to "recent open conversations with other users, groups, or channels you've joined", then you're looking for client.iter_dialogs:

    # Print all dialog IDs and the title, nicely formatted
    async for dialog in client.iter_dialogs():
        print('{:>14}: {}'.format(dialog.id, dialog.title))