Danielrahmai1991 commited on
Commit
5a373ff
·
verified ·
1 Parent(s): 358de1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
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-SPACE-NAME.hf.space/webhook"
57
  await telegram_app.bot.set_webhook(webhook_url)
58
 
59
- yield # اجرای اپ بعد از startup
60
 
61
  await telegram_app.bot.delete_webhook()
62
 
63
- # ثبت lifespan
64
  app.router.lifespan_context = lifespan
65
 
66
- # ✅ روت اصلی برای webhook تلگرام
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"}