fix config
This commit is contained in:
parent
ae14782da4
commit
360f8110a4
|
|
@ -21,8 +21,28 @@ assert TELEGRAM_API_KEY, "Telegram API_KEY required"
|
|||
CLIENT_TELEGRAM_API_KEY = os.environ.get('CLIENT_TELEGRAM_API_KEY')
|
||||
assert CLIENT_TELEGRAM_API_KEY, "Client Telegram API_KEY required"
|
||||
import httpx
|
||||
TELEGRAM_BOT_USERNAME = httpx.get(f"https://api.telegram.org/bot{TELEGRAM_API_KEY}/getMe").json()['result']['username']
|
||||
CLIENT_TELEGRAM_BOT_USERNAME = httpx.get(f"https://api.telegram.org/bot{CLIENT_TELEGRAM_API_KEY}/getMe").json()['result']['username']
|
||||
|
||||
|
||||
def _resolve_bot_username(token: str, label: str) -> str:
|
||||
try:
|
||||
resp = httpx.get(f"https://api.telegram.org/bot{token}/getMe", timeout=10.0)
|
||||
resp.raise_for_status()
|
||||
payload = resp.json()
|
||||
except Exception as exc:
|
||||
raise RuntimeError(f"{label} Telegram token validation failed: {exc}") from exc
|
||||
|
||||
if not payload.get('ok'):
|
||||
detail = payload.get('description') or 'unknown Telegram API error'
|
||||
raise RuntimeError(f"{label} Telegram token validation failed: {detail}")
|
||||
|
||||
username = (payload.get('result') or {}).get('username')
|
||||
if not username:
|
||||
raise RuntimeError(f"{label} Telegram token validation failed: username missing in Telegram response")
|
||||
return username
|
||||
|
||||
|
||||
TELEGRAM_BOT_USERNAME = _resolve_bot_username(TELEGRAM_API_KEY, 'Uploader bot')
|
||||
CLIENT_TELEGRAM_BOT_USERNAME = _resolve_bot_username(CLIENT_TELEGRAM_API_KEY, 'Client bot')
|
||||
|
||||
# Unified database URL (PostgreSQL)
|
||||
DATABASE_URL = os.environ['DATABASE_URL']
|
||||
|
|
|
|||
Loading…
Reference in New Issue