Add template-as-code sync (campaigns template NAME PATH)

Answers "can the unsubscribe template be added via git+API too": commit
listmonk's own stock campaign template (already unsubscribe-capable) as
email-templates/campaign.html, add a small find-or-create-or-update
Template client (confirmed against knadh/listmonk's actual model/handlers),
a new `template` subcommand, and a manual-dispatch-only workflow to push it
in as the default campaign template. Unlike campaign sync there's no
draft/live status to protect, so this is always a safe overwrite.
This commit is contained in:
2026-07-10 08:54:31 -04:00
parent bcf8df5579
commit a630a8f8ab
9 changed files with 476 additions and 6 deletions
+15 -1
View File
@@ -45,13 +45,19 @@ func main() {
os.Exit(1)
}
runTest(lm, os.Args[2], os.Args[3:])
case "template":
if len(os.Args) < 4 {
fmt.Fprintln(os.Stderr, "usage: campaigns template NAME PATH")
os.Exit(1)
}
runTemplate(lm, os.Args[2], os.Args[3])
default:
usage()
}
}
func usage() {
fmt.Fprintln(os.Stderr, "usage: campaigns <sync PATH|send SLUG|test SLUG EMAIL...>")
fmt.Fprintln(os.Stderr, "usage: campaigns <sync PATH|send SLUG|test SLUG EMAIL...|template NAME PATH>")
os.Exit(1)
}
@@ -101,6 +107,14 @@ func runTest(lm *listmonk.Client, slug string, emails []string) {
log.Printf("test: sent preview of %q to %v", slug, emails)
}
func runTemplate(lm *listmonk.Client, name, path string) {
tpl, err := campaign.SyncTemplate(lm, name, path)
if err != nil {
log.Fatalf("template: %v", err)
}
log.Printf("template: %q (id=%d) is now the default campaign template", tpl.Name, tpl.ID)
}
func mustEnv(key string) string {
v := os.Getenv(key)
if v == "" {