fix: use polling mode for Telegram (no WEBHOOK_BASE_URL)
Some checks failed
Deploy BetterBot / deploy (push) Failing after 3s
Deploy BetterBot / notify (push) Successful in 3s

This commit is contained in:
Andre Kamarudin 2026-04-19 08:08:56 +08:00
parent 7d6db76ceb
commit 1d49a39c6a
2 changed files with 12 additions and 3 deletions

View file

@ -52,6 +52,9 @@ class Settings(BaseSettings):
DATA_DIR: str = "/data"
TG_PERSISTENCE_DIR: str = ""
# Telegram webhook — leave empty to use polling mode
WEBHOOK_BASE_URL: str = ""
# BetterBot — site directories
SITE_DIR: str = "/site"
MEMORAIZ_DIR: str = "/memoraiz"

12
main.py
View file

@ -584,9 +584,13 @@ async def startup() -> None:
# invoke it explicitly to register bot commands.
if tg_app.post_init:
await tg_app.post_init(tg_app)
base_url = f"https://code.bytesizeprotip.com/telegram/webhook/{webhook_secret()}"
await tg_app.bot.set_webhook(base_url, drop_pending_updates=True)
logger.info("Telegram webhook registered (dropped pending updates) at %s", base_url)
if settings.WEBHOOK_BASE_URL:
webhook_url = f"{settings.WEBHOOK_BASE_URL}/telegram/webhook/{webhook_secret()}"
await tg_app.bot.set_webhook(webhook_url, drop_pending_updates=True)
logger.info("Telegram webhook registered (dropped pending updates) at %s", webhook_url)
else:
await tg_app.updater.start_polling(drop_pending_updates=True)
logger.info("Telegram polling started (no WEBHOOK_BASE_URL configured)")
# Start event polling background task (T027)
import asyncio
@ -597,6 +601,8 @@ async def startup() -> None:
@app.on_event("shutdown")
async def shutdown() -> None:
if tg_app:
if tg_app.updater and tg_app.updater.running:
await tg_app.updater.stop()
await tg_app.stop()
await tg_app.shutdown()
await copilot.stop()