2323 / services /core /auth_interactive.py
GreenMan101
Add Doctor Freud Bot - all files
55b6d21
Raw History Blame Contribute Delete
1.55 kB
#!/usr/bin/env python3
"""Interactive Telegram authorization script."""
import os
import asyncio
from telethon import TelegramClient
API_ID = int(os.getenv("TELEGRAM_API_ID"))
API_HASH = os.getenv("TELEGRAM_API_HASH")
PHONE = os.getenv("TELEGRAM_PHONE")
async def main():
"""Authorize Telegram client interactively."""
session_path = "/app/sessions/telegram_session"
client = TelegramClient(session_path, API_ID, API_HASH)
await client.connect()
if not await client.is_user_authorized():
print(f"Sending code to {PHONE}...")
await client.send_code_request(PHONE)
print("\nWaiting for code input...")
print("Enter the code you received in Telegram:")
code = input("> ")
try:
await client.sign_in(PHONE, code)
print("\n✅ Successfully authorized!")
except Exception as e:
if "password" in str(e).lower():
print("\nTwo-factor authentication enabled.")
password = input("Enter your 2FA password: ")
await client.sign_in(password=password)
print("\n✅ Successfully authorized!")
else:
print(f"\n❌ Error: {e}")
await client.disconnect()
return
me = await client.get_me()
print(f"\n✅ Logged in as: {me.first_name} (@{me.username})")
print(f"Session saved to: {session_path}.session")
await client.disconnect()
if __name__ == "__main__":
asyncio.run(main())