TelegramSteamBot / generate_session.py
mrpoddaa's picture
Upload 13 files
18b952c verified
#!/usr/bin/env python3
"""
Session String Generator for Telegram Multi-Part File Streamer
Generates Pyrogram session strings for multi-session load balancing
"""
import asyncio
import sys
from pyrogram import Client
async def generate_session_string():
"""Generate a Pyrogram session string"""
print("=" * 60)
print("Telegram Session String Generator")
print("=" * 60)
print()
# Get credentials
try:
api_id = input("Enter your API_ID: ").strip()
if not api_id:
print("❌ API_ID is required!")
return
api_id = int(api_id)
api_hash = input("Enter your API_HASH: ").strip()
if not api_hash:
print("❌ API_HASH is required!")
return
print()
print("πŸ” Credentials validated!")
print()
print("πŸ“± You will now receive a code on your Telegram app.")
print(" Please enter the code when prompted.")
print()
except ValueError:
print("❌ Invalid API_ID! Must be a number.")
return
except KeyboardInterrupt:
print("\n\n❌ Cancelled by user.")
return
# Create client
client = Client(
name="session_generator",
api_id=api_id,
api_hash=api_hash,
in_memory=True
)
try:
# Start client (will prompt for phone number and code)
await client.start()
# Get session string
session_string = await client.export_session_string()
# Get user info
me = await client.get_me()
print()
print("=" * 60)
print("βœ… Session String Generated Successfully!")
print("=" * 60)
print()
print(f"πŸ‘€ Account: {me.first_name} {me.last_name or ''}")
print(f"πŸ“ž Phone: +{me.phone_number}")
print(f"πŸ†” Username: @{me.username or 'N/A'}")
print()
print("πŸ“‹ Session String:")
print("-" * 60)
print(session_string)
print("-" * 60)
print()
print("⚠️ IMPORTANT:")
print(" 1. Keep this session string PRIVATE and SECURE")
print(" 2. Anyone with this string can access your account")
print(" 3. Add this to SESSION_STRINGS in your .env file")
print(" 4. You can generate multiple session strings for")
print(" load balancing (comma-separated)")
print()
print("πŸ’‘ Example .env configuration:")
print("-" * 60)
print(f"SESSION_STRINGS={session_string},YOUR_SECOND_SESSION_STRING")
print("-" * 60)
print()
# Stop client
await client.stop()
except Exception as e:
print(f"\n❌ Error: {str(e)}")
if "PASSWORD" in str(e).upper():
print("\n⚠️ Your account has 2FA enabled.")
print(" Please enter your password when prompted.")
return
finally:
if client.is_connected:
await client.stop()
def main():
"""Main function"""
try:
asyncio.run(generate_session_string())
except KeyboardInterrupt:
print("\n\n❌ Cancelled by user.")
sys.exit(1)
if __name__ == "__main__":
main()