Files
eec-campaigns/internal/campaign/send.go
T
will 4006dca9f5
CI / test (push) Successful in 12s
Split tool from content: eec-campaigns becomes a standalone CLI
Campaign content and listmonk credentials now live in separate
per-domain repos that install this tool at a pinned version, so a
client with access to one domain's content repo has no path to
another domain's secrets. Renames the module to the actual Gitea
host path so `go install` works without vanity-import redirects,
drops the four workflows that assumed campaigns/ content lived here,
adds real go-test CI, and rewrites the README for the tool's new
audience.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-10 20:00:52 -04:00

44 lines
1.5 KiB
Go

package campaign
import (
"fmt"
"gitea.reground.org/will/eec-campaigns/internal/listmonk"
)
// Send transitions a campaign from draft/paused to running — the one real
// send trigger in this whole tool (see cmd/send, triggered only by a pushed
// send/<slug> git tag or a manual workflow_dispatch, never by a plain
// sync). The campaign is looked up fresh by name each call, so this always
// acts on listmonk's current live state, not whatever sync last saw.
func Send(lm *listmonk.Client, slug string) (*listmonk.Campaign, error) {
camp, err := lm.FindCampaignByName(slug)
if err != nil {
return nil, err
}
if camp == nil {
return nil, fmt.Errorf("no campaign named %q in listmonk — run sync first", slug)
}
if camp.Status != "draft" && camp.Status != "paused" {
return nil, fmt.Errorf("campaign %q is %s in listmonk — only draft or paused campaigns can be sent", slug, camp.Status)
}
if err := lm.SetCampaignStatus(camp.ID, "running"); err != nil {
return nil, err
}
return camp, nil
}
// Test sends a preview of a campaign's current content to the given
// addresses without touching its status — the same mechanism sync's
// automatic preview uses, exposed standalone for on-demand re-previews.
func Test(lm *listmonk.Client, slug string, emails []string) error {
camp, err := lm.FindCampaignByName(slug)
if err != nil {
return err
}
if camp == nil {
return fmt.Errorf("no campaign named %q in listmonk — run sync first", slug)
}
return lm.TestCampaign(camp.ID, emails)
}