I am trying to read messages from my private telegram channel. I used the following code. I am facing a problem reading the message while it is in private but if I change the channel to the public this code is working fine. But I want the channel to be private is there any solution for this?
import configparser
import json
import re
from telethon.errors import SessionPasswordNeededError
from telethon import TelegramClient, events, sync
from telethon.tl.functions.messages import (GetHistoryRequest)
from telethon.tl.types import (PeerChannel)
api_id = *******
api_hash = ******
# Here you define the target channel that you want to listen to:
user_input_channel = 'https://t.me/<channel_id>'
client = TelegramClient('name', api_id, api_hash)
# Listen to messages from target Channel
@client.on(events.NewMessage(chats=user_input_channel))
async def newMessageListner(event):
# Get message text
newMessage = event.message.message
print(newMessage)
with client:
client.run_until_disconnected()
while trying with the channel in private I am getting this error message
Cannot find any entity corresponding to "https://t.me/<channel_id>"
Note: Channel ID is delibrately masked