package templates import ( "bytes" "html/template" "github.com/warmbly/warmbly/internal/observability/errs" ) // Generic transactional notification used by the in-app notification // service for any category routed to email (new sign-in, reply alerts, // and so on). Title/body are plain text, auto-escaped by html/template. // CTAURL is optional: an empty value drops the button entirely. const notificationContent = `

Notification

{{.Title}}

{{.Body}}

{{if .CTAURL}}
{{.CTALabel}}
{{end}}

You're receiving this because email notifications are on for this activity. Manage them in your notification settings.

` var notificationTmpl = template.Must(template.New("notification_content").Parse(notificationContent)) // GenerateNotificationHTML renders a generic notification email. ctaURL // is optional (empty drops the button); ctaLabel defaults to "Open in // " when a URL is present but no label is supplied. func GenerateNotificationHTML(title, body, ctaURL, ctaLabel string) (string, error) { brand := CompanyName() if ctaURL != "" && ctaLabel == "" { ctaLabel = "Open in " + brand } data := struct { Title string Body string CTAURL string CTALabel string }{Title: title, Body: body, CTAURL: ctaURL, CTALabel: ctaLabel} var buf bytes.Buffer if err := notificationTmpl.Execute(&buf, data); err != nil { errs.CaptureException(err) return "", err } subject := title if subject == "" { subject = "Notification from " + brand } return renderEmail(subject, buf.String()) }