Skip to content

Instantly share code, notes, and snippets.

@moenk
Created April 4, 2021 09:06
Show Gist options
  • Save moenk/b709dc445d1df9e8b56374f18e6adbc5 to your computer and use it in GitHub Desktop.
Save moenk/b709dc445d1df9e8b56374f18e6adbc5 to your computer and use it in GitHub Desktop.
Python telegram send bulk messages to all contacts
from telethon.sync import TelegramClient
from telethon.tl.types import InputPeerUser
from telethon import functions
from time import sleep
api_id = 359***
api_hash = 'fe0b***'
with TelegramClient("moenk", api_id, api_hash) as client:
contacts = client(functions.contacts.GetContactsRequest(hash=0))
for u in contacts.users:
sleep(2)
print(u.username)
client.send_message(InputPeerUser(u.id, u.access_hash), "Frohe Ostern! Urbi et orbi.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment