Spaces:
Sleeping
Sleeping
File size: 1,072 Bytes
7139588 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | from pathlib import Path
from pyrogram import Client
# Ask for data interactively
API_ID = int(input("Enter API_ID: ").strip())
API_HASH = input("Enter API_HASH: ").strip()
BOT_TOKEN = input("Enter BOT_TOKEN: ").strip()
# Session name (file will be <session_name>.session)
session_name = input("Enter session name (e.g. bot1): ").strip() or "bot1"
# Optional: put sessions into ./cache like TGDrive does
session_dir = Path("./cache")
session_dir.mkdir(parents=True, exist_ok=True)
async def main():
print("\n>>> Starting bot once to create session file...")
async with Client(
name=session_name,
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
workdir=session_dir,
ipv6=False,
) as app:
me = await app.get_me()
print(f"Logged in as bot: @{me.username} (id: {me.id})")
print(f"\n✅ Session file created at: {session_dir / (session_name + '.session')}")
print("Now you can use this name in BOT_SESSIONS.")
if __name__ == "__main__":
import asyncio
asyncio.run(main()) |