package tasks
import (
"fmt"
"math/rand"
"net/url"
"regexp"
"strings"
"github.com/google/uuid"
"github.com/warmbly/warmbly/internal/models"
)
// Conversation represents a warmup conversation for AI generation
type Conversation struct {
ID uuid.UUID
Theme string
Description string
Messages []string
}
// TemplateVariables contains variables for template rendering
type TemplateVariables struct {
FirstName string
LastName string
Email string
Company string
Phone string
Custom map[string]string
}
// RenderTemplate renders a template string with contact variables
func RenderTemplate(template string, contact models.Contact) string {
vars := TemplateVariables{
FirstName: contact.FirstName,
LastName: contact.LastName,
Email: contact.Email,
Company: contact.Company,
Phone: contact.Phone,
Custom: make(map[string]string),
}
// Parse custom fields if present
if contact.CustomFields != nil {
vars.Custom = contact.CustomFields
}
result := template
// Replace standard variables
result = strings.ReplaceAll(result, "{{.FirstName}}", vars.FirstName)
result = strings.ReplaceAll(result, "{{.LastName}}", vars.LastName)
result = strings.ReplaceAll(result, "{{.Email}}", vars.Email)
result = strings.ReplaceAll(result, "{{.Company}}", vars.Company)
result = strings.ReplaceAll(result, "{{.Phone}}", vars.Phone)
// Replace custom variables
for k, v := range vars.Custom {
placeholder := fmt.Sprintf("{{.%s}}", k)
result = strings.ReplaceAll(result, placeholder, v)
}
return result
}
// AddSignature adds signature to email body
func AddSignature(body string, signature string, isHTML bool) string {
if signature == "" {
return body
}
if isHTML {
return body + "
" + signature
}
return body + "\n\n" + signature
}
// AddOpenTrackingPixel adds an invisible tracking pixel to HTML email
// The pixel URL points to the Rust tracking service endpoint: /t/o/{taskID}.png
func AddOpenTrackingPixel(htmlBody string, taskID uuid.UUID, trackingDomain string) string {
if trackingDomain == "" {
trackingDomain = "track.warmbly.com"
}
// Use /t/o/ path to match Rust tracking service
pixelURL := fmt.Sprintf("https://%s/t/o/%s.png", trackingDomain, taskID.String())
pixel := fmt.Sprintf(`
`, pixelURL)
// Try to insert before closing body tag
if strings.Contains(htmlBody, "