Hi pricing and unsubscribe
` + out, links := WrapLinksForTracking(body, uuid.New(), uuid.New(), "t.example.com") + if len(links) != 1 || links[0].Destination != "https://acme.com/pricing" { + t.Fatalf("expected only the pricing link to be ticketed, got %+v", links) + } + if !strings.Contains(out, `href="https://api.example.com/unsubscribe/abc123"`) { + t.Fatalf("unsubscribe link was rewritten: %s", out) + } +} + +func TestOptOutFooter(t *testing.T) { + text := models.UnsubscribeSettings{Mode: models.UnsubscribeModeText, Text: "Reply and I'll stop."} + h, p := appendOptOut("Hi
", "Hi", text, "") + if !strings.Contains(h, "Reply and I'll stop.") || !strings.HasSuffix(p, "Reply and I'll stop.") { + t.Fatalf("text footer missing: %q / %q", h, p) + } + + link := models.UnsubscribeSettings{Mode: models.UnsubscribeModeLink, Text: "fallback", LinkIntro: "Not interested?", LinkText: "Unsubscribe"} + h, p = appendOptOut("Hi
", "Hi", link, "https://api.example.com/unsubscribe/tok") + if !strings.Contains(h, `href="https://api.example.com/unsubscribe/tok"`) || !strings.Contains(p, "Unsubscribe: https://api.example.com/unsubscribe/tok") { + t.Fatalf("link footer missing: %q / %q", h, p) + } + // No link to mint: link mode degrades to the text line, never to nothing. + h, _ = appendOptOut("Hi
", "Hi", link, "") + if !strings.Contains(h, "fallback") { + t.Fatalf("link mode without a link should fall back to text: %q", h) + } + h, p = appendOptOut("Hi
", "Hi", models.UnsubscribeSettings{Mode: models.UnsubscribeModeOff}, "x") + if h != "Hi
" || p != "Hi" { + t.Fatalf("off mode changed the body: %q / %q", h, p) + } +} diff --git a/internal/tasks/template.go b/internal/tasks/template.go index 084e6326..a73bc326 100644 --- a/internal/tasks/template.go +++ b/internal/tasks/template.go @@ -13,7 +13,6 @@ import ( "github.com/warmbly/warmbly/internal/models" "github.com/warmbly/warmbly/internal/pkg/tmplfuncs" "github.com/warmbly/warmbly/internal/pkg/warmpersona" - "github.com/warmbly/warmbly/internal/repository" ) // Conversation represents a warmup conversation for AI generation @@ -294,63 +293,6 @@ func AddOpenTrackingPixel(htmlBody string, taskID uuid.UUID, trackingDomain stri return htmlBody + pixel } -// WrapLinksForTracking rewrites every external link to an opaque -// click-tracking ticket (https://See our Pricing & plans or
+ Leave a field empty to use the placeholder default. utm_content is set per link from its text + (for example pricing), so each link is attributed on its own. +
+