fixed issue not responding to callback updates

This commit is contained in:
Hosein
2026-01-08 13:12:34 +03:30
parent 45138bb234
commit c681a5c1d7
+14 -16
View File
@@ -17,26 +17,24 @@ async def telegram_webhook(request: Request):
try: try:
import telebot import telebot
from bot.bot import get_bot from bot.bot import get_bot
bot = get_bot() bot = get_bot()
json_data = await request.json() json_data = await request.json()
logger.info(f"Received update: {json_data}") logger.info(f"Received update: {json_data}")
update = telebot.types.Update.de_json(json_data) update = telebot.types.Update.de_json(json_data)
# Process the update directly instead of using process_new_updates # Process ALL types of updates (messages, callback queries, etc.)
if update.message: try:
try: bot.process_new_updates([update])
# Call your message handlers directly except Exception as e:
bot.process_new_updates([update]) logger.error(f"Error processing update: {e}")
except Exception as e: # Still return 200 to Telegram to acknowledge receipt
logger.error(f"Error processing update: {e}") return JSONResponse(content={"ok": True}, status_code=200)
# Still return 200 to Telegram to acknowledge receipt
return JSONResponse(content={"ok": True}, status_code=200)
return JSONResponse(content={"ok": True}, status_code=200) return JSONResponse(content={"ok": True}, status_code=200)
except Exception as e: except Exception as e:
logger.error(f"Webhook error: {e}") logger.error(f"Webhook error: {e}")
# Return 200 even on error to prevent Telegram from retrying # Return 200 even on error to prevent Telegram from retrying
@@ -54,4 +52,4 @@ def read_root():
if __name__ == "__main__": if __name__ == "__main__":
import uvicorn import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=5001, reload=True) uvicorn.run("main:app", host="0.0.0.0", port=5001, reload=True)