title: Read public channel texts using Telegram API
body: <p>I would like to create a small script that will fetch Telegram texts from a public channel (I am not the channel's admin).</p>
  
  <p>I've found another question asked here:
  <a href="https://stackoverflow.com/questions/46525921/read-the-messages-of-the-public-channels-from-telegram">Read the messages of the public channels from Telegram</a>
  <br>
  I've tried using Telethon as said in the answer, but it didn't work:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Throwing this error:</p>
  
  <pre><code>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 &lt;module&gt;
      response = client.invoke(ResolveUsernameRequest("test"))
  AttributeError: 'TelegramClient' object has no attribute 'invoke'
  </code></pre>
  
  <p>I've tried reading the API documentation, but I didn't fully understand how those calls work:</p>
  
  <blockquote>
    <p><a href="https://core.telegram.org/method/channels.exportMessageLink" rel="nofollow noreferrer">https://core.telegram.org/method/channels.exportMessageLink</a></p>
    
    <p><a href="https://core.telegram.org/method/channels.joinChannel" rel="nofollow noreferrer">https://core.telegram.org/method/channels.joinChannel</a></p>
    
    <p><a href="https://core.telegram.org/method/channels.getMessages" rel="nofollow noreferrer">https://core.telegram.org/method/channels.getMessages</a></p>
  </blockquote>
  
  <p>I'd be grateful if someone could explain to me how those work.</p>