#!/bin/bash
# Telegram MTProto login script
# Run this via SSH: bash /tmp/tg_login.sh
#
# This bypasses the mcp-telegram CLI (which has pydantic-settings env conflicts)
# and uses Telethon directly with SOCKS5 proxy.

/home/openclaw/.local/share/uv/tools/mcp-telegram/bin/python3 << 'EOF'
import asyncio
from telethon import TelegramClient
from telethon.errors import SessionPasswordNeededError
import socks

API_ID = 37679203
API_HASH = '514a2ba8b7898365c9070da4739e8deb'
SESSION = '/home/openclaw/.local/share/state/mcp-telegram/mcp_telegram_session'

async def main():
    phone = input("Phone (e.g. +1234567890): ").strip()
    client = TelegramClient(
        SESSION, API_ID, API_HASH,
        proxy=(socks.SOCKS5, '127.0.0.1', 7890)
    )
    await client.start(phone=phone)
    me = await client.get_me()
    print(f"\n✅ Logged in as: {me.username} (ID: {me.id})")
    await client.disconnect()

asyncio.run(main())
EOF
