Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,17 +53,17 @@ async def lifespan(app: FastAPI):
|
|
| 53 |
telegram_app.add_handler(MessageHandler(filters.PHOTO, handle_photo))
|
| 54 |
|
| 55 |
# ستکردن آدرس webhook
|
| 56 |
-
webhook_url = "https://YOUR-
|
| 57 |
await telegram_app.bot.set_webhook(webhook_url)
|
| 58 |
|
| 59 |
-
yield
|
| 60 |
|
| 61 |
await telegram_app.bot.delete_webhook()
|
| 62 |
|
| 63 |
-
# ثبت lifespan
|
| 64 |
app.router.lifespan_context = lifespan
|
| 65 |
|
| 66 |
-
# ✅ روت
|
| 67 |
@app.post("/webhook")
|
| 68 |
async def telegram_webhook(request: Request):
|
| 69 |
global telegram_app
|
|
@@ -71,4 +71,3 @@ async def telegram_webhook(request: Request):
|
|
| 71 |
update = Update.de_json(data, bot)
|
| 72 |
await telegram_app.update_queue.put(update)
|
| 73 |
return {"status": "ok"}
|
| 74 |
-
|
|
|
|
| 53 |
telegram_app.add_handler(MessageHandler(filters.PHOTO, handle_photo))
|
| 54 |
|
| 55 |
# ستکردن آدرس webhook
|
| 56 |
+
webhook_url = "https://YOUR-USERNAME-YOUR-SPACENAME.hf.space/webhook"
|
| 57 |
await telegram_app.bot.set_webhook(webhook_url)
|
| 58 |
|
| 59 |
+
yield
|
| 60 |
|
| 61 |
await telegram_app.bot.delete_webhook()
|
| 62 |
|
| 63 |
+
# 🔁 ثبت lifespan به FastAPI
|
| 64 |
app.router.lifespan_context = lifespan
|
| 65 |
|
| 66 |
+
# ✅ روت برای دریافت پیام تلگرام
|
| 67 |
@app.post("/webhook")
|
| 68 |
async def telegram_webhook(request: Request):
|
| 69 |
global telegram_app
|
|
|
|
| 71 |
update = Update.de_json(data, bot)
|
| 72 |
await telegram_app.update_queue.put(update)
|
| 73 |
return {"status": "ok"}
|
|
|