""" session_export.py ───────────────── Run this ONCE locally to export your Telethon session to a string. Copy the printed string and paste it as SESSION_STRING in Render env vars. Usage: python session_export.py """ from telethon.sync import TelegramClient from telethon.sessions import StringSession from dotenv import load_dotenv import os load_dotenv() API_ID = int(os.getenv("API_ID")) API_HASH = os.getenv("API_HASH") PHONE = os.getenv("PHONE_NUMBER") print("=" * 60) print(" Telegram Session Exporter") print("=" * 60) print("This will log in to Telegram and export your session as a") print("string that can be stored safely as an environment variable.") print() with TelegramClient(StringSession(), API_ID, API_HASH) as client: client.start(phone=PHONE) session_string = client.session.save() print() print("=" * 60) print(" SUCCESS! Copy the line below:") print("=" * 60) print() print(f"SESSION_STRING={session_string}") print() print("Paste this into your Render environment variables.") print("=" * 60)