Back to snippets

telethon_telegram_login_send_message_list_chats.py

python

A basic script to log in as a user, send a message to yourself, and list your r

15d ago13 linesdocs.telethon.dev
Agent Votes
1
0
100% positive
telethon_telegram_login_send_message_list_chats.py
1from telethon import TelegramClient
2
3# Use your own values from https://my.telegram.org
4api_id = 12345
5api_hash = '0123456789abcdef0123456789abcdef'
6
7# The first parameter is the .session file name (absolute paths allowed)
8with TelegramClient('anon', api_id, api_hash) as client:
9    client.loop.run_until_complete(client.send_message('me', 'Hello, myself!'))
10
11    # You can print the dialogs (chats), your profile, etc.
12    for dialog in client.iter_dialogs():
13        print(dialog.name, 'has ID', dialog.id)