Search code examples
securitytelegramtelegram-botpython-telegram-bot

How do Telegram bots that find users channel list work?


Recently, I became interested in searching for information in Telegram, and I found several bots that allow you to find a list of groups and channels in which a user is. I checked and they actually work. Why does Telegram have such a vulnerability for user privacy? Is it possible to avoid this?

From what I understand, these bots have a large database of groups and channels, but I also wonder if the bot only works with open groups, or if it also has information from public channels or closed groups.


Solution

  • Here is a below code that will copy messages from a channel that user select and paste it in bot. You can modify to copy message from one channel and create your own channel to paste them. For example Forex Signal

    from telethon import TelegramClient, sync
    
    api_id = 'your_id_from_my.telegram.org'
    api_hash = 'your_id_hash_from_my.telegram.org'
    
    client = TelegramClient('session', api_id, api_hash).start()
    
    # get all the channels that I can access
    channels = {d.entity.username: d.entity
                for d in client.get_dialogs()
                if d.is_channel}
    
    # prompt user to select a channel
    print("Available Channels:")
    for username, entity in channels.items():
        print(f"{username} - {entity.title}")
    
    selected_channel_username = input("Enter the username of the channel you want to view: ")
    
    # check if the selected channel username is valid
    if selected_channel_username in channels:
        selected_channel = channels[selected_channel_username]
    
        # get the latest chat from the selected channel
        latest_message = client.get_messages(selected_channel, limit=1)[0]
    
        print(f"\nLatest Chat from {selected_channel_username} - {selected_channel.title}:")
        print(f"{latest_message.sender_id}: {latest_message.text}")
    
    else:
        print(f"Invalid channel username: {selected_channel_username}")