TransWikia.com

How can I read recent messages from my telegram account in python?

Stack Overflow Asked by VjSwamy on February 3, 2021

I am trying to read the recent messages from my telegram account to automate replies..

import configparser
from telethon.sync import TelegramClient, utils

config = configparser.ConfigParser()
config.read( "config.ini")

mySession = 'xyz'
myUserId = '@xyz'

async with TelegramClient(mySession, api_id, api_hash) as client:
    async for message in client.iter_messages(myUserId):
        print(message.sender_id, ':', message.text)

This Code asks for credentials and successfully logs me in..

Please enter your phone (or bot token): 9XXXXXXXXXXX
Please enter the code you received: 4XXXXX
Signed in successfully as SXXXXX

but..

myself = client.get_me()
print( myself.stringify())

returns..

AttributeError                            Traceback (most recent call last)
<ipython-input-5-fddc5bc3f77b> in <module>
----> 1 print( myself.stringify())

AttributeError: 'coroutine' object has no attribute 'stringify'

please help..

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP