Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -15,6 +15,7 @@ GAS_WEBAPP_URL = os.getenv("GAS_WEBAPP_URL")
|
|
| 15 |
APP_ID = os.getenv("APP_ID")
|
| 16 |
APP_SECRET = os.getenv("APP_SECRET")
|
| 17 |
REDIRECT_URI = os.getenv("REDIRECT_URI")
|
|
|
|
| 18 |
|
| 19 |
@app.get("/webhook")
|
| 20 |
async def verify_webhook(request: Request):
|
|
@@ -69,6 +70,14 @@ async def receive_webhook(request: Request):
|
|
| 69 |
|
| 70 |
print("RAW GAS RESPONSE:", data)
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
field_map = {}
|
| 73 |
for item in data.get("field_data", []):
|
| 74 |
field_map[item.get("name")] = ", ".join(item.get("values", []))
|
|
@@ -103,4 +112,4 @@ async def receive_webhook(request: Request):
|
|
| 103 |
except Exception as e:
|
| 104 |
print(f"⚠️ Error processing lead: {e}")
|
| 105 |
|
| 106 |
-
return {"status": "ok"}
|
|
|
|
| 15 |
APP_ID = os.getenv("APP_ID")
|
| 16 |
APP_SECRET = os.getenv("APP_SECRET")
|
| 17 |
REDIRECT_URI = os.getenv("REDIRECT_URI")
|
| 18 |
+
BINRUSHD_AD_ACCOUNT_ID = os.getenv("BINRUSHD_AD_ACCOUNT_ID") or os.getenv("binrushd_ad_account_id")
|
| 19 |
|
| 20 |
@app.get("/webhook")
|
| 21 |
async def verify_webhook(request: Request):
|
|
|
|
| 70 |
|
| 71 |
print("RAW GAS RESPONSE:", data)
|
| 72 |
|
| 73 |
+
# ✅ التحقق من مطابقة الحساب الإعلاني (Binrushd Ad Account)
|
| 74 |
+
ad_account_id = str(data.get("ad_account_id") or "").replace("act_", "").strip()
|
| 75 |
+
expected_ad_account = str(BINRUSHD_AD_ACCOUNT_ID or "").replace("act_", "").strip()
|
| 76 |
+
|
| 77 |
+
if expected_ad_account and ad_account_id != expected_ad_account:
|
| 78 |
+
print(f"⏭️ Skipping lead {lead_id}: Ad Account ID '{ad_account_id}' does not match Binrushd Ad Account '{expected_ad_account}'.")
|
| 79 |
+
continue
|
| 80 |
+
|
| 81 |
field_map = {}
|
| 82 |
for item in data.get("field_data", []):
|
| 83 |
field_map[item.get("name")] = ", ".join(item.get("values", []))
|
|
|
|
| 112 |
except Exception as e:
|
| 113 |
print(f"⚠️ Error processing lead: {e}")
|
| 114 |
|
| 115 |
+
return {"status": "ok"}
|