Mr-Help commited on
Commit
ddf861f
·
verified ·
1 Parent(s): 953d0c7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -6
main.py CHANGED
@@ -6,7 +6,7 @@ import requests
6
  app = FastAPI()
7
 
8
  VERIFY_TOKEN = "my_secure_token"
9
- PAGE_ACCESS_TOKEN = "EAAJGMsgQEhMBO3RPgdfKCwDGrmiQCZBZADpRZCqqYyxRkKjr0lZCQk3NfNY6qARDSWpjAVgnwJnHEgZAnp5QNKnoNgZCIFi6g149ZBU02TfKXil2P690Q1ZC0fn8jGQYew8MZB62zUIOed9jG9Li4tmpnZBddZBvyLyRlJH6EqvyYA9Bg03HGyMU0UzKZAA6Aexc5H8tWPrNZBE0wkxF2qT0CWxsZD" # Replace with your actual Page Token
10
 
11
  @app.get("/webhook")
12
  async def verify_webhook(request: Request):
@@ -24,13 +24,10 @@ async def verify_webhook(request: Request):
24
  async def receive_webhook(request: Request):
25
  payload = await request.json()
26
  print("📥 Webhook payload received:")
27
-
28
  gmt_plus_3 = timezone(timedelta(hours=3))
29
  print("Timestamp:", datetime.now(gmt_plus_3).strftime('%Y-%m-%d %H:%M:%S'))
30
 
31
- # Extract and print the payload
32
- print(payload)
33
-
34
  try:
35
  for entry in payload.get("entry", []):
36
  for change in entry.get("changes", []):
@@ -38,7 +35,7 @@ async def receive_webhook(request: Request):
38
  lead_id = change["value"]["leadgen_id"]
39
  print(f"🔍 Lead ID: {lead_id}")
40
 
41
- # Fetch lead details from Graph API
42
  url = f"https://graph.facebook.com/v18.0/{lead_id}"
43
  params = {"access_token": PAGE_ACCESS_TOKEN}
44
  lead_resp = requests.get(url, params=params)
@@ -47,6 +44,12 @@ async def receive_webhook(request: Request):
47
  print("📄 Lead Details:")
48
  print(lead_data)
49
 
 
 
 
 
 
 
50
  except Exception as e:
51
  print(f"⚠️ Error processing lead: {e}")
52
 
 
6
  app = FastAPI()
7
 
8
  VERIFY_TOKEN = "my_secure_token"
9
+ PAGE_ACCESS_TOKEN = "EAAJGMsgQEhMBO3RPgdfKCwDGrmiQCZBZADpRZCqqYyxRkKjr0lZCQk3NfNY6qARDSWpjAVgnwJnHEgZAnp5QNKnoNgZCIFi6g149ZBU02TfKXil2P690Q1ZC0fn8jGQYew8MZB62zUIOed9jG9Li4tmpnZBddZBvyLyRlJH6EqvyYA9Bg03HGyMU0UzKZAA6Aexc5H8tWPrNZBE0wkxF2qT0CWxsZD" # Replace with actual page token
10
 
11
  @app.get("/webhook")
12
  async def verify_webhook(request: Request):
 
24
  async def receive_webhook(request: Request):
25
  payload = await request.json()
26
  print("📥 Webhook payload received:")
27
+
28
  gmt_plus_3 = timezone(timedelta(hours=3))
29
  print("Timestamp:", datetime.now(gmt_plus_3).strftime('%Y-%m-%d %H:%M:%S'))
30
 
 
 
 
31
  try:
32
  for entry in payload.get("entry", []):
33
  for change in entry.get("changes", []):
 
35
  lead_id = change["value"]["leadgen_id"]
36
  print(f"🔍 Lead ID: {lead_id}")
37
 
38
+ # Fetch lead details
39
  url = f"https://graph.facebook.com/v18.0/{lead_id}"
40
  params = {"access_token": PAGE_ACCESS_TOKEN}
41
  lead_resp = requests.get(url, params=params)
 
44
  print("📄 Lead Details:")
45
  print(lead_data)
46
 
47
+ # Pretty print each field
48
+ for item in lead_data.get("field_data", []):
49
+ field_name = item.get("name")
50
+ field_value = ", ".join(item.get("values", []))
51
+ print(f"{field_name}: {field_value}")
52
+
53
  except Exception as e:
54
  print(f"⚠️ Error processing lead: {e}")
55