Skip to content

feat: add spintax support for email templates#310

Open
anjali20006 wants to merge 3 commits into
Kuldeeep18:mainfrom
anjali20006:clean-spintax
Open

feat: add spintax support for email templates#310
anjali20006 wants to merge 3 commits into
Kuldeeep18:mainfrom
anjali20006:clean-spintax

Conversation

@anjali20006

@anjali20006 anjali20006 commented Jun 18, 2026

Copy link
Copy Markdown

Summary

Adds Spintax support for email templates.

Closes #122

Changes

  • Added parse_spintax import in campaigns/tasks.py
  • Applied Spintax parsing to email subject and body before sending
  • Added Spintax utility implementation in campaigns/utils.py

Testing

  • Created a campaign with Spintax-formatted content
  • Verified subject/body are parsed before sending
  • Confirmed existing email sending flow remains unchanged

Notes

This PR contains only the Spintax-related backend changes and excludes unrelated frontend formatting changes and merge-conflict resolutions.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added spintax parsing for email campaigns, enabling subject lines and email bodies to include {option1|option2|...} variants.
    • Parsed output is now resolved into final text before emails are dispatched.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7f8d5e53-1a26-4234-a8f6-d583b6ed57bf

📥 Commits

Reviewing files that changed from the base of the PR and between d3199b4 and ec55c51.

📒 Files selected for processing (1)
  • backend/campaigns/utils.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/campaigns/utils.py

📝 Walkthrough

Walkthrough

A parse_spintax(text) utility function is added to backend/campaigns/utils.py, using random and re to iteratively replace {option1|option2|...} blocks with a randomly chosen alternative. This function is then imported and applied to the email subject and body inside send_email_step in backend/campaigns/tasks.py, after personalize_email and before dispatch.

Changes

Spintax Support

Layer / File(s) Summary
parse_spintax implementation
backend/campaigns/utils.py
Adds random and re imports, a module-level Signer instance, and the new parse_spintax(text) function that loops over {…} blocks containing |-delimited alternatives and replaces each with a random choice until none remain.
Integration into email dispatch task
backend/campaigns/tasks.py
Imports parse_spintax and calls it on both subject and body inside send_email_step after personalize_email returns, before the Gmail or mock send path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

  • #210: Directly related — the PR implements the parse_spintax(text) utility and dispatch integration described in the implementation guide for spintax support.

Poem

🐇 A bunny spins words with a flick of a paw,
{Hi|Hello|Hey} — now pick one, that's the law!
With random.choice and a loop through re,
Each email looks fresh, as fresh as can be.
No two look the same, the spam filters say:
"This rabbit's the best at keeping flags away!" 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding spintax support for email templates, which is the primary focus of the PR.
Linked Issues check ✅ Passed The PR successfully implements objectives 1 and 2 from issue #122: the parse_spintax function is added to utils.py, and spintax parsing is integrated into the email dispatch task after merge tag replacement. Objective 3 (UI preview) is explicitly excluded.
Out of Scope Changes check ✅ Passed All changes are scoped to backend spintax implementation. The PR objectives explicitly exclude unrelated frontend changes and merge conflict resolutions, aligning with the actual changeset in tasks.py and utils.py.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/campaigns/utils.py`:
- Around line 23-33: The regex pattern variable `pattern` on line 23 is too
broad and matches any text within braces. Modify the pattern to only match true
Spintax blocks that contain the pipe character (|), ensuring it requires at
least one pipe separator within the braces. This way, only valid Spintax
alternatives like {option1|option2} will be processed, while other braced
content such as unresolved merge tags or literal braces remain untouched and
their content is not accidentally mutated.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8370fcba-5e4e-4efd-9dc0-5290da90af70

📥 Commits

Reviewing files that changed from the base of the PR and between 90052f9 and d3199b4.

📒 Files selected for processing (2)
  • backend/campaigns/tasks.py
  • backend/campaigns/utils.py

Comment thread backend/campaigns/utils.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LO-031 [Medium]: Spintax Support in Email Template Editor and Parser

1 participant