Spaces:
Runtime error
Runtime error
| import os | |
| def _get_int(name: str, default: int) -> int: | |
| try: | |
| return int(os.environ.get(name, str(default))) | |
| except Exception: | |
| return default | |
| class Telegram: | |
| # User account session (phone) recommended | |
| API_ID = _get_int("TELEGRAM_API_ID", 0) | |
| API_HASH = os.environ.get("TELEGRAM_API_HASH", "") | |
| # Use ONLY one of these: | |
| SESSION_STRING = os.environ.get("SESSION_STRING", "") # ✅ user session string (phone) | |
| BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN", "") # optional (bot token) if you ever use bot auth | |
| OWNER_ID = _get_int("OWNER_ID", 0) | |
| # optional: allowlist via env (space separated ids) | |
| ALLOWED_USER_IDS = [x for x in os.environ.get("ALLOWED_USER_IDS", "").split() if x.strip()] | |
| class Server: | |
| BIND_ADDRESS = os.environ.get("BIND_ADDRESS", "0.0.0.0") | |
| PORT = _get_int("PORT", 7860) | |
| # Simple logging config for uvicorn + hydrogram | |
| LOGGER_CONFIG_JSON = { | |
| "version": 1, | |
| "formatters": { | |
| "default": { | |
| "format": "[%(asctime)s][%(name)s][%(levelname)s] -> %(message)s", | |
| "datefmt": "%d/%m/%Y %H:%M:%S", | |
| } | |
| }, | |
| "handlers": { | |
| "stream_handler": { | |
| "class": "logging.StreamHandler", | |
| "formatter": "default", | |
| } | |
| }, | |
| "loggers": { | |
| "uvicorn": {"level": "INFO", "handlers": ["stream_handler"]}, | |
| "uvicorn.error": {"level": "INFO", "handlers": ["stream_handler"]}, | |
| "hydrogram": {"level": "INFO", "handlers": ["stream_handler"]}, | |
| "bot": {"level": "INFO", "handlers": ["stream_handler"]}, | |
| }, | |
| } |