Seth commited on
Commit ·
82763f8
1
Parent(s): 12ebb02
update
Browse files- backend/app/main.py +21 -6
- backend/app/smartlead_client.py +2 -2
backend/app/main.py
CHANGED
|
@@ -442,29 +442,44 @@ 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 |
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'
|
| 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'
|
| 466 |
|
| 467 |
-
# Store lead with custom vars for later update
|
| 468 |
leads.append({
|
| 469 |
"lead_data": lead,
|
| 470 |
"custom_vars": custom_vars,
|
|
|
|
| 442 |
failed_count += 1
|
| 443 |
continue
|
| 444 |
|
| 445 |
+
# Build lead object - Try including custom variables as direct fields with capitalized names
|
| 446 |
+
# Smartlead sequences use {{Subject_1}}, {{Body_1}} (capitalized), so we need to match that
|
| 447 |
lead = {
|
| 448 |
"email": email,
|
| 449 |
"first_name": first_name,
|
| 450 |
"last_name": last_name
|
| 451 |
}
|
| 452 |
|
| 453 |
+
# Add custom variables as direct fields with capitalized names to match sequence variables
|
| 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'Subject_{i}'] = subject_str # Capitalized
|
| 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'Body_{i}'] = body_str # Capitalized
|
| 482 |
|
|
|
|
| 483 |
leads.append({
|
| 484 |
"lead_data": lead,
|
| 485 |
"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. (capitalized)
|
| 266 |
+
"email_body": f"Hi {{{{first_name}}}},\n\n{{{{Body_{i}}}}}\n\n", # Produces: Hi {{first_name}},\n\n{{Body_1}}\n\n (capitalized)
|
| 267 |
"seq_delay_details": {
|
| 268 |
"delay_in_days": delay_days # Required by Smartlead API
|
| 269 |
}
|