fix: read email/phone from top-level body fields in /user/create

Evotor sends user fields (email, phone_number, first_name, last_name)
at the top level of the webhook body, not inside customField. Now we
check both locations with top-level taking precedence. Also store the
full body in evotor_meta instead of just the customField subset.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mguschin
2026-05-24 16:48:15 +03:00
parent a3f6697bc4
commit dc32bef7e8

View File

@@ -102,10 +102,11 @@ async def user_create(request: Request, db: Session = Depends(get_db)):
return JSONResponse({"error": "userId required"}, status_code=400)
custom = _parse_custom_fields(body.get("customField"))
email = (custom.get("email") or "").strip().lower() or None
phone = (custom.get("phone") or "").strip() or None
first_name = (custom.get("first_name") or custom.get("firstName") or "").strip() or None
last_name = (custom.get("last_name") or custom.get("lastName") or "").strip() or None
# Evotor sends fields both at top level and inside customField
email = (body.get("email") or custom.get("email") or "").strip().lower() or None
phone = (body.get("phone_number") or body.get("phone") or custom.get("phone_number") or custom.get("phone") or "").strip() or None
first_name = (body.get("first_name") or body.get("firstName") or custom.get("first_name") or custom.get("firstName") or "").strip() or None
last_name = (body.get("last_name") or body.get("lastName") or custom.get("last_name") or custom.get("lastName") or "").strip() or None
# Try to find existing user
user: User | None = None
@@ -126,7 +127,7 @@ async def user_create(request: Request, db: Session = Depends(get_db)):
if user:
# Link Evotor to existing user
user.evotor_user_id = evotor_user_id
user.evotor_meta = custom or body
user.evotor_meta = body
if user.status == UserStatusEnum.pending:
user.status = UserStatusEnum.active
db.flush()
@@ -141,7 +142,7 @@ async def user_create(request: Request, db: Session = Depends(get_db)):
role=UserRoleEnum.user,
status=UserStatusEnum.pending,
evotor_user_id=evotor_user_id,
evotor_meta=custom or body,
evotor_meta=body,
created_at=now,
updated_at=now,
)