| import os |
| import asyncio |
| from telethon import TelegramClient, events |
|
|
| |
| |
| |
| API_ID = int(os.environ["API_ID"]) |
| API_HASH = os.environ["API_HASH"] |
| BOT_TOKEN = os.environ["BOT_TOKEN"] |
|
|
| |
| |
| |
| UPLOAD_DIR = "/data/uploads" |
| os.makedirs(UPLOAD_DIR, exist_ok=True) |
|
|
| |
| |
| |
| client = TelegramClient( |
| "bot", |
| API_ID, |
| API_HASH, |
| connection_retries=10, |
| timeout=30, |
| use_ipv6=False |
| ) |
|
|
| |
| |
| |
| @client.on(events.NewMessage(pattern="/start")) |
| async def start_handler(event): |
| await event.reply( |
| "🤖 Bot is online.\n" |
| "هر فایلی بفرستی، روی HuggingFace ذخیره میکنم." |
| ) |
|
|
| @client.on(events.NewMessage) |
| async def file_handler(event): |
| if not event.file: |
| return |
|
|
| try: |
| file_path = await event.download_media(file=UPLOAD_DIR) |
| await event.reply( |
| "✅ فایل ذخیره شد\n\n" |
| f"📂 مسیر:\n{file_path}" |
| ) |
| print(f"Saved: {file_path}") |
|
|
| except Exception as e: |
| await event.reply(f"❌ خطا:\n{e}") |
| print("Download error:", e) |
|
|
| |
| |
| |
| async def main(): |
| print("Starting Telegram bot...") |
| await client.start(bot_token=BOT_TOKEN) |
| print("Connected to Telegram") |
| await client.run_until_disconnected() |
|
|
| if __name__ == "__main__": |
| asyncio.run(main()) |
|
|