Skip to content

Instantly share code, notes, and snippets.

@aliforever
Created August 17, 2019 20:33
Show Gist options
  • Save aliforever/51ebec370063cd8e7e40ab6661dc4a83 to your computer and use it in GitHub Desktop.
Save aliforever/51ebec370063cd8e7e40ab6661dc4a83 to your computer and use it in GitHub Desktop.
Forward messages from a name to saved messages without marking message as seen in Telegram
# After running the script in logging in to your account, send "forward_unseen:mister_x:10" to your saved messages,
# the bot will then forward 10 last messages of the first user with name mister_x to your saved messages.
# This way you can check what people have sent you without them knowing you did.
from telethon import TelegramClient, events, sync
from telethon.tl.types import PeerUser
api_id = # Your Telegram API id here
api_hash = # Your Telegram API hash here
client = TelegramClient("Session_Name", api_id, api_hash)
client.start()
@client.on(events.NewMessage)
async def my_event_handler(event):
if "forward_unseen:" in event.raw_text:
command = event.raw_text.split(":")
name = command[1]
count = command[2]
for dialog in await client.iter_dialogs():
if dialog.title == name:
user = client.get_entity(PeerUser(dialog.id))
i = 1
for chat in client.iter_messages(user):
await client.forward_messages(client.get_me(), chat, user)
if i >= count:
break
i += 1
break
client.run_until_disconnected()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment