Templates let you define a message body once, with {{.variable}} placeholders, and render it server-side on every send. Benefits: shorter requests, consistent copy, and a single place to edit when the copy changes.
Create a template
Response:
The slug is derived from name and doubles as a stable identifier — use it (instead of the UUID) in sends so renaming a template doesn’t break callers.
Send using the template
The server renders the body, re-computes segments and cost, and proceeds normally.
Variable syntax
We use Go’s text/template engine:
Missing variables render as <no value> — not an error. This is deliberate so a typo doesn’t block a send; but test your templates with the render endpoint (below) to catch them in dev.
Preview before sending
POST /v1/sms-templates/:id/render renders the template with variables and returns the body + segment count without sending anything. Great for previews in your admin UI:
List, update, delete
Keeping segment count predictable
Variables change the final length. A good pattern: cap user-supplied variables to a max length before passing them, so your template never balloons past one segment:
The render endpoint is useful here too — check segments before batch-sending to estimate cost.