Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -733,6 +733,9 @@ async def admin_handle_remove_channel(update: Update, context):
|
|
733 |
# --- ادغام با FastAPI برای Webhook ---
|
734 |
WEBHOOK_PATH = "/webhook"
|
735 |
|
|
|
|
|
|
|
736 |
application = Application.builder().token(TOKEN).build()
|
737 |
app = FastAPI(
|
738 |
title="Telegram Bot Webhook",
|
@@ -807,7 +810,7 @@ conv_handler = ConversationHandler(
|
|
807 |
application.add_handler(conv_handler)
|
808 |
application.add_error_handler(error_handler)
|
809 |
|
810 |
-
# FastAPI app events
|
811 |
@app.on_event("startup")
|
812 |
async def on_startup():
|
813 |
print("Application startup...")
|
@@ -826,13 +829,14 @@ async def bot_webhook(request: Request):
|
|
826 |
"""
|
827 |
Endpoint for Telegram Webhook. Receives updates from Telegram.
|
828 |
"""
|
829 |
-
#
|
830 |
-
print("Received webhook update.")
|
831 |
json_data = await request.json()
|
|
|
|
|
832 |
update = Update.de_json(json_data, application.bot)
|
833 |
|
834 |
# Process the update using the PTB application
|
835 |
-
# این خط آپدیت را به هندلرهای تعریف شده (مانند ConversationHandler) پاس می دهد.
|
836 |
await application.process_update(update)
|
837 |
|
838 |
return {"ok": True}
|
@@ -840,5 +844,4 @@ async def bot_webhook(request: Request):
|
|
840 |
@app.get("/")
|
841 |
async def root():
|
842 |
"""Home endpoint to show bot status or a welcome message."""
|
843 |
-
|
844 |
-
return HTMLResponse("<h1>Telegram Bot is running!</h1><p>Send messages to your bot on Telegram.</p>")
|
|
|
733 |
# --- ادغام با FastAPI برای Webhook ---
|
734 |
WEBHOOK_PATH = "/webhook"
|
735 |
|
736 |
+
# اضافه کردن خط دیباگ در ابتدای فایل برای لاگهای Build/Startup
|
737 |
+
print("DEBUG: app.py is starting up.")
|
738 |
+
|
739 |
application = Application.builder().token(TOKEN).build()
|
740 |
app = FastAPI(
|
741 |
title="Telegram Bot Webhook",
|
|
|
810 |
application.add_handler(conv_handler)
|
811 |
application.add_error_handler(error_handler)
|
812 |
|
813 |
+
# FastAPI app events
|
814 |
@app.on_event("startup")
|
815 |
async def on_startup():
|
816 |
print("Application startup...")
|
|
|
829 |
"""
|
830 |
Endpoint for Telegram Webhook. Receives updates from Telegram.
|
831 |
"""
|
832 |
+
# اضافه کردن خط دیباگ در لحظه دریافت آپدیت
|
833 |
+
print("DEBUG: Received webhook update.")
|
834 |
json_data = await request.json()
|
835 |
+
print(f"DEBUG: Update JSON: {json.dumps(json_data, indent=2)}") # لاگ کردن محتوای آپدیت برای عیب یابی
|
836 |
+
|
837 |
update = Update.de_json(json_data, application.bot)
|
838 |
|
839 |
# Process the update using the PTB application
|
|
|
840 |
await application.process_update(update)
|
841 |
|
842 |
return {"ok": True}
|
|
|
844 |
@app.get("/")
|
845 |
async def root():
|
846 |
"""Home endpoint to show bot status or a welcome message."""
|
847 |
+
return HTMLResponse("<h1>Telegram Bot is running!</h1><p>Send messages to your bot on Telegram.</p>")
|
|