Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/campaigns/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .sms_service import send_sms, initiate_call
from .models import CampaignLead, SequenceStep
from leads.models import BlockedDomain, normalize_domain
from .utils import parse_spintax

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -458,6 +459,9 @@ def send_email_step(campaign_lead_id, step_id):
return

subject, body = personalize_email(step.template_subject, step.template_body, clead.lead)

subject = parse_spintax(subject)
body = parse_spintax(body)

account = clead.campaign.connected_account
if account:
Expand Down
25 changes: 24 additions & 1 deletion backend/campaigns/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
from django.core.signing import Signer, BadSignature
import random
import re

signer = Signer()


def generate_unsubscribe_token(lead_id):
return signer.sign(str(lead_id))


def verify_unsubscribe_token(token):
try:
return signer.unsign(token)
except BadSignature:
return None
return None


def parse_spintax(text):
if not text:
return text

pattern = r"\{([^{}]*\|[^{}]*)\}"

while re.search(pattern, text):
text = re.sub(
pattern,
lambda match: random.choice(
match.group(1).split("|")
),
text,
count=1,
)

return text