From 74f613a4c387b1b3b9a2049547d83c07f4113dde Mon Sep 17 00:00:00 2001 From: mguschin Date: Sun, 24 May 2026 16:53:34 +0300 Subject: [PATCH] fix: parse Evotor install/uninstall event structure correctly userId is nested inside body.data, and event types are ApplicationInstalled / ApplicationUninstalled (not install/uninstall). Co-Authored-By: Claude Sonnet 4.6 --- web/routes/evotor_webhooks.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/web/routes/evotor_webhooks.py b/web/routes/evotor_webhooks.py index 027e0d5..7bcf37f 100644 --- a/web/routes/evotor_webhooks.py +++ b/web/routes/evotor_webhooks.py @@ -290,12 +290,13 @@ async def user_install(request: Request, db: Session = Depends(get_db)): except Exception: return JSONResponse({"error": "Invalid JSON"}, status_code=400) - logger.info("user/install body=%s", body) - - evotor_user_id: str = body.get("userId", "") - event_type: str = body.get("type", "").lower() # "install" or "uninstall" + # userId is nested inside "data"; type is e.g. "ApplicationInstalled" / "ApplicationUninstalled" + data: dict = body.get("data", {}) + evotor_user_id: str = data.get("userId", "") or body.get("userId", "") + event_type: str = body.get("type", "").lower() # "applicationinstalled" / "applicationuninstalled" if not evotor_user_id: + logger.warning("user/install missing userId, body=%s", body) return JSONResponse({"error": "userId required"}, status_code=400) logger.info("user/install event type=%s userId=%s", event_type, evotor_user_id) @@ -307,7 +308,7 @@ async def user_install(request: Request, db: Session = Depends(get_db)): now = datetime.now(timezone.utc).replace(tzinfo=None) - if event_type == "uninstall": + if event_type == "applicationuninstalled": user.status = UserStatusEnum.suspended user.updated_at = now conn = db.query(EvotorConnection).filter( @@ -319,7 +320,7 @@ async def user_install(request: Request, db: Session = Depends(get_db)): db.commit() logger.info("user suspended on uninstall: userId=%s", evotor_user_id) - elif event_type == "install": + elif event_type == "applicationinstalled": if user.status == UserStatusEnum.suspended: user.status = UserStatusEnum.active user.updated_at = now