Seth commited on
Commit ·
bde7250
1
Parent(s): 82763f8
update
Browse files- backend/app/main.py +6 -21
- backend/app/smartlead_client.py +2 -2
backend/app/main.py
CHANGED
|
@@ -442,44 +442,29 @@ async def push_to_smartlead(request: SmartleadPushRequest, db: Session = Depends
|
|
| 442 |
failed_count += 1
|
| 443 |
continue
|
| 444 |
|
| 445 |
-
# Build lead object -
|
| 446 |
-
#
|
| 447 |
lead = {
|
| 448 |
"email": email,
|
| 449 |
"first_name": first_name,
|
| 450 |
"last_name": last_name
|
| 451 |
}
|
| 452 |
|
| 453 |
-
#
|
| 454 |
-
# Smartlead may accept these if they match the variable names in sequences exactly
|
| 455 |
-
for i in range(1, request.steps_count + 1):
|
| 456 |
-
if i in contact.get('subjects', {}):
|
| 457 |
-
subject = contact['subjects'][i]
|
| 458 |
-
subject_str = safe_str(subject) if subject else ""
|
| 459 |
-
if subject_str:
|
| 460 |
-
# Use capitalized name to match {{Subject_1}} in sequences
|
| 461 |
-
lead[f'Subject_{i}'] = subject_str
|
| 462 |
-
if i in contact.get('bodies', {}):
|
| 463 |
-
body = contact['bodies'][i]
|
| 464 |
-
body_str = safe_str(body) if body else ""
|
| 465 |
-
if body_str:
|
| 466 |
-
# Use capitalized name to match {{Body_1}} in sequences
|
| 467 |
-
lead[f'Body_{i}'] = body_str
|
| 468 |
-
|
| 469 |
-
# Store lead with custom vars for potential update if direct fields don't work
|
| 470 |
custom_vars = {}
|
| 471 |
for i in range(1, request.steps_count + 1):
|
| 472 |
if i in contact.get('subjects', {}):
|
| 473 |
subject = contact['subjects'][i]
|
| 474 |
subject_str = safe_str(subject) if subject else ""
|
| 475 |
if subject_str:
|
| 476 |
-
custom_vars[f'
|
| 477 |
if i in contact.get('bodies', {}):
|
| 478 |
body = contact['bodies'][i]
|
| 479 |
body_str = safe_str(body) if body else ""
|
| 480 |
if body_str:
|
| 481 |
-
custom_vars[f'
|
| 482 |
|
|
|
|
| 483 |
leads.append({
|
| 484 |
"lead_data": lead,
|
| 485 |
"custom_vars": custom_vars,
|
|
|
|
| 442 |
failed_count += 1
|
| 443 |
continue
|
| 444 |
|
| 445 |
+
# Build lead object - Smartlead API doesn't allow "company", "title", or custom variables when adding leads
|
| 446 |
+
# We'll add leads first, then try to update them with custom variables separately
|
| 447 |
lead = {
|
| 448 |
"email": email,
|
| 449 |
"first_name": first_name,
|
| 450 |
"last_name": last_name
|
| 451 |
}
|
| 452 |
|
| 453 |
+
# Store custom variables separately to update leads after adding
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
custom_vars = {}
|
| 455 |
for i in range(1, request.steps_count + 1):
|
| 456 |
if i in contact.get('subjects', {}):
|
| 457 |
subject = contact['subjects'][i]
|
| 458 |
subject_str = safe_str(subject) if subject else ""
|
| 459 |
if subject_str:
|
| 460 |
+
custom_vars[f'subject_{i}'] = subject_str
|
| 461 |
if i in contact.get('bodies', {}):
|
| 462 |
body = contact['bodies'][i]
|
| 463 |
body_str = safe_str(body) if body else ""
|
| 464 |
if body_str:
|
| 465 |
+
custom_vars[f'body_{i}'] = body_str
|
| 466 |
|
| 467 |
+
# Store lead with custom vars for later update
|
| 468 |
leads.append({
|
| 469 |
"lead_data": lead,
|
| 470 |
"custom_vars": custom_vars,
|
backend/app/smartlead_client.py
CHANGED
|
@@ -262,8 +262,8 @@ class SmartleadClient:
|
|
| 262 |
|
| 263 |
sequences.append({
|
| 264 |
"seq_number": i, # Required by Smartlead API (not "step")
|
| 265 |
-
"subject": f"{{{{
|
| 266 |
-
"email_body": f"Hi {{{{first_name}}}},\n\n{{{{
|
| 267 |
"seq_delay_details": {
|
| 268 |
"delay_in_days": delay_days # Required by Smartlead API
|
| 269 |
}
|
|
|
|
| 262 |
|
| 263 |
sequences.append({
|
| 264 |
"seq_number": i, # Required by Smartlead API (not "step")
|
| 265 |
+
"subject": f"{{{{subject_{i}}}}}", # Double braces escape to produce {{subject_1}}, etc.
|
| 266 |
+
"email_body": f"Hi {{{{first_name}}}},\n\n{{{{body_{i}}}}}\n\n", # Produces: Hi {{first_name}},\n\n{{body_1}}\n\n
|
| 267 |
"seq_delay_details": {
|
| 268 |
"delay_in_days": delay_days # Required by Smartlead API
|
| 269 |
}
|