I would like to create a small script that will fetch Telegram texts from a public channel (I am not the channel's admin).
I've found another question asked here:
Read the messages of the public channels from Telegram
I've tried using Telethon as said in the answer, but it didn't work:
from telethon.tl.functions.contacts import ResolveUsernameRequest
import telethon
client = telethon.TelegramClient("session.txt", api_id=XYZ, api_hash='XYZ')
client.connect()
response = client.invoke(ResolveUsernameRequest("test"))
print(response.channel_id)
print(response.access_hash)
Throwing this error:
C:/Users/mypc/PycharmProjects/untitled/aa.py:5: RuntimeWarning: coroutine 'TelegramBaseClient.connect' was never awaited
client.connect()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
File "C:/Users/mypc/PycharmProjects/untitled/aa.py", line 6, in <module>
response = client.invoke(ResolveUsernameRequest("test"))
AttributeError: 'TelegramClient' object has no attribute 'invoke'
I've tried reading the API documentation, but I didn't fully understand how those calls work:
https://core.telegram.org/method/channels.exportMessageLink
I'd be grateful if someone could explain to me how those work.
client.invoke(request)
is the old way to do it. You need to useclient(request)
. – Gary