feat: Add interest form endpoint and fix lead parsing
- Updated to check https://hoaledgeriq.com/api/leads - Fixed JSON parsing (uses 'leads' key not 'submissions') - Added proper handling for interest form fields - Notifications now include first name, last name, org - Detected 5 historical interest form leads - Both endpoints now fully functional
This commit is contained in:
@@ -18,7 +18,7 @@ TELEGRAM_TARGET = "telegram:8269921691"
|
||||
# API Endpoints
|
||||
ENDPOINTS = {
|
||||
"roi_calculator": "https://www.hoaledgeriq.com/api/calc-submissions",
|
||||
"interest_form": "https://www.hoaledgeriq.com/api/interest-submissions"
|
||||
"interest_form": "https://hoaledgeriq.com/api/leads"
|
||||
}
|
||||
|
||||
def log(message):
|
||||
@@ -73,7 +73,7 @@ def send_telegram_notification(lead_id, email, source, property_type=None, homes
|
||||
if property_type:
|
||||
message += f"*Property Type:* {property_type}\n"
|
||||
if homesites:
|
||||
message += f"*Homesites:* {homesites:,}\n"
|
||||
message += f"*Homesites:* {homesites}\n"
|
||||
|
||||
message += f"\n*Time:* {datetime.now().strftime('%Y-%m-%d %H:%M')}"
|
||||
|
||||
@@ -124,23 +124,26 @@ def check_interest_form(state):
|
||||
log("📝 Checking Interest Form...")
|
||||
data = fetch_endpoint(ENDPOINTS["interest_form"])
|
||||
|
||||
if not data or 'submissions' not in data:
|
||||
if not data or 'leads' not in data:
|
||||
log(" No submissions found")
|
||||
return state
|
||||
|
||||
new_count = 0
|
||||
for submission in data['submissions']:
|
||||
for submission in data['leads']:
|
||||
lead_id = submission.get('id')
|
||||
email = submission.get('email', 'unknown')
|
||||
first_name = submission.get('first_name', '')
|
||||
last_name = submission.get('last_name', '')
|
||||
org_name = submission.get('org_name', '')
|
||||
|
||||
if lead_id not in state['processed_interest']:
|
||||
log(f" 🎯 NEW: ID {lead_id} - {email}")
|
||||
log(f" 🎯 NEW: ID {lead_id} - {email} ({first_name} {last_name})")
|
||||
send_telegram_notification(
|
||||
lead_id=lead_id,
|
||||
email=email,
|
||||
source="Interest Form",
|
||||
property_type=submission.get('property_type', ''),
|
||||
homesites=submission.get('homesites')
|
||||
property_type=f"{first_name} {last_name} ({org_name})",
|
||||
homesites=submission.get('unit_count')
|
||||
)
|
||||
state['processed_interest'].append(lead_id)
|
||||
new_count += 1
|
||||
|
||||
Reference in New Issue
Block a user