forked from MargotP/telegram_similar_channels_finder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_telegram_auth.py
More file actions
44 lines (35 loc) · 1.1 KB
/
test_telegram_auth.py
File metadata and controls
44 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
"""
Simple Telegram API authentication test
"""
import asyncio
from telethon import TelegramClient
from dotenv import load_dotenv
import os
load_dotenv()
async def main():
client = TelegramClient(
'test_session',
os.getenv('TELEGRAM_API_ID'),
os.getenv('TELEGRAM_API_HASH')
)
print("Connecting to Telegram...")
await client.connect()
if not await client.is_user_authorized():
phone = os.getenv('TELEGRAM_PHONE')
if not phone:
phone = input("Enter phone number (with country code): ")
print(f"Sending code to {phone}...")
await client.send_code_request(phone)
code = input("Enter received code: ")
try:
await client.sign_in(phone, code)
print("Successfully signed in!")
except Exception as e:
print(f"Sign in failed: {e}")
return
me = await client.get_me()
print(f"Authenticated as: {me.first_name} ({me.phone})")
await client.disconnect()
if __name__ == '__main__':
asyncio.run(main())