estebanpdl / telegram-tracker

The package connects to Telegram's API to generate JSON files containing data for channels, including information and posts. It allows you to search for specific channels or a set of channels provided in a text file, with one channel per line.
337 stars 62 forks source link

Channels with spaces in their name? #3

Closed Mycah closed 1 year ago

Mycah commented 2 years ago

I'm trying to connect to channels with spaces in their name and constantly get errors.

$ python ./main.py --telegram-channel Channel\ Name

Init program at Tue Nov  8 19:54:38 2022

> Authorized!

> Collecting data from Telegram Channel -> Channel Name
> ...

Traceback (most recent call last):
  File "/home/xxx/telegram/telegram-api/./main.py", line 161, in <module>
    entity_attrs = loop.run_until_complete(
  File "/home/xxx/miniconda3/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/xxx/telegram/telegram-api/api/__init__.py", line 57, in get_entity_attrs
    return await client.get_entity(source)
  File "/home/xxx/miniconda3/lib/python3.9/site-packages/telethon/client/users.py", line 335, in get_entity
    result.append(await self._get_entity_from_string(x))
  File "/home/xxx/miniconda3/lib/python3.9/site-packages/telethon/client/users.py", line 574, in _get_entity_from_string
    raise ValueError(
ValueError: Cannot find any entity corresponding to "Channel Name"

I've tried with quotes and with \, same error.

I also created a text file with the channel names using --batch-file, and it fails in the same manner.

estebanpdl commented 2 years ago

The channel name that you are adding is not actually the name in the URL. You need to select only the channel's name that is visible in the URL. https://t.me/ChannelName. Telegram's API only recognizes the official name, again, the one that is in the URL.

Mycah commented 2 years ago

Is there a way to find that within the client? I only have invite links (which don't have channel names either), and can't see any way to find them using the web ui or desktop app.

fyi i used telethon to to do this:

async for dialog in client.iter_dialogs():
    if dialog.is_channel:
        print(f'{dialog.id}:{dialog.title}')

It only gave me the same titles i see in the apps.

estebanpdl commented 2 years ago

Why dont you click on the channel's name using the desktop app (above number of subscribers)? This will open a pop-up. There, you can see something like t.me/channelname. Using the client, you will need to find in docs the class GetChannelsRequest or GetFullChannelRequest. Those will return data from the requested channel, but you need either the channel name (without spaces) or the channel id.

Mycah commented 2 years ago

I stupidly got my phone number banned, I guess trying to login too much. I'll try those options once I can connect again. I did look in the info for the channel, etc and couldn't find any t.me links, but now that I'm locked out I can't confirm.