Skip to content
Registry StackDocsv0.48.0

Author a Messaging package

View as Markdown

A Messaging package is everything a deployment may send: the providers, the sender profiles callers select, the templates, and the access profiles that decide who may call. Here you add a French version of the starter’s SMS reminder, preview it, and package the project for an operator.

Work in the project you built in Send your first message. Run every command from the directory that holds tutorial-work, with messagingctl on your PATH. Nothing here needs a running service; an operator installs the released binary as Deploy Registry Messaging describes.

Terminal window
messagingctl check --project tutorial-work/notices
ok: tutorial-work/notices
package digest: sha256:b819f6d18f1b32ede522cb7c4ad436056a1cc85e10523c891dcfe892623ecb5b
template: appointment-reminder 1 (email)
sample en: renders
sample fr: renders
template: appointment-reminder-sms 1 (sms)
sample en: 1 segment(s), gsm7 85 units
access profile: case-notices (sender)
access profile: operations (operator)
0 errors, 0 warnings in 18 files

Any edit to these files changes the digest, and the digest is what the operator records.

messaging.yaml names the providers and the sender profiles a caller selects:

messaging.yaml
# The transports this deployment sends through. The type and, for an http
# provider, its scripts under providers/<id>/ are package; each provider's
# endpoint and credentials are runtime configuration. `idempotentSubmit`
# declares that the provider drops a repeat carrying the same idempotency key.
providers:
mail-relay:
type: smtp
sms-gateway:
type: http
idempotentSubmit: true
# What a caller selects: a channel, the provider carrying it, the sender
# identity, and for SMS the most segments one message may use.
senderProfiles:
transactional:
channel: email
provider: mail-relay
sender: notices@example.org
reminders-sms:
channel: sms
provider: sms-gateway
sender: Registry
maximumSegments: 2

A sender profile also carries its dispatch policy, and each message keeps the policy it was accepted under. A send that definitely failed is retried with a delay that doubles each time. A send that may have reached the provider is uncertain: under the default onUncertain: hold the message stops as unknown until an operator settles it, and under retry it is sent again with the same idempotency key. retry is refused unless the provider declares idempotentSubmit: true or the profile sets acceptDuplicates: true. Set acceptDuplicates only when a duplicate is better for the recipient than a missed message.

The access profiles decide who may call:

messaging.yaml
accessProfiles:
case-notices:
principalClaim: sub
requiredScopes: [messaging:send]
requesterClients: [case-system]
actorKind: service
actsAs: sender
senderProfiles: [transactional, reminders-sms]
templates: [appointment-reminder, appointment-reminder-sms]
requestsPerMinute: 60
burst: 10

A token resolves to one profile by its client, its scopes, and its actor kind. A sender may submit and preview with the sender profiles and templates listed; an operator reads and cancels every message and may not submit. Messaging inherits no authorisation from a calling product: a service allowed to act on a case is not thereby allowed to send. requestsPerMinute and burst are counted per caller in each runtime process; maximumMessagesPerDay, when set, is counted for the whole profile from accepted messages, so it holds across replicas and restarts.

Registry Messaging configuration lists every key, its default, and its bounds.

A template version lives under templates/<id>/<version>/. Its template.yaml declares the channel, the locales, and the parts, and each locale has one Jinja file per part. Declare fr for the SMS reminder and write its text:

Terminal window
sms=tutorial-work/notices/templates/appointment-reminder-sms/1
cat >"$sms/template.yaml" <<'YAML'
apiVersion: id.registrystack.org/formats/messaging/template/v1alpha1
kind: MessagingTemplate
channel: sms
locales: [en, fr]
parts: [text]
YAML
mkdir -p "$sms/fr"
cat >"$sms/fr/text.j2" <<'JINJA'
Rappel : {{ name }}, votre rendez-vous à {{ office }} est le {{ day|date }}.
JINJA

Render it with the version’s sample data:

Terminal window
messagingctl preview --project tutorial-work/notices --locale fr \
--data "$sms/sample.json" appointment-reminder-sms 1
template: appointment-reminder-sms 1 (sms, fr)
package digest: sha256:a77193bf48a8fdcc09a4576991fbd0441307cd23e34c550d27a740b66cd0dfce
--- text
Rappel : Ada Lovelace, votre rendez-vous à Central Registry Office est le 01/10/2026.
--- sms: 1 segment(s), gsm7 85 units

The segment count is what the runtime charges against the sender profile’s maximumSegments. A submission whose text needs more segments than that is refused with 422 content.too-many-segments; check reports the count but does not compare it.

Check the project again. The French sample now renders at load:

Terminal window
messagingctl check --project tutorial-work/notices
ok: tutorial-work/notices
package digest: sha256:a77193bf48a8fdcc09a4576991fbd0441307cd23e34c550d27a740b66cd0dfce
template: appointment-reminder 1 (email)
sample en: renders
sample fr: renders
template: appointment-reminder-sms 1 (sms)
sample en: 1 segment(s), gsm7 85 units
sample fr: 1 segment(s), gsm7 85 units
access profile: case-notices (sender)
access profile: operations (operator)
0 errors, 0 warnings in 19 files

A version directory holds template.yaml, a schema.json (JSON Schema draft 2020-12, with no outside references) that the caller’s data must satisfy before anything renders, an optional sample.json every locale must render at load, and the <locale>/<part>.j2 files. An email version renders subject, text, and optionally html; an SMS version renders exactly text.

Templates are Jinja without a loader: no include, import, extends, or macros, no built-in filters or globals, and no file, network, or clock access. A missing or null value refuses the render instead of printing nothing. Two filters format for the requested locale: date for an ISO calendar date and number(decimals) for a number. HTML parts escape every value, text and SMS parts strip control characters, and a subject strips newlines. A locale the version does not declare is refused with 422 template.locale-unavailable, never answered in another language.

To change wording a deployment already sends, add a new version directory, list it under templates in messaging.yaml, and keep the old one until no caller names it.

An smtp provider needs nothing in the package beyond its entry. An http provider has a directory providers/<id>/ with a provider.yaml and the Rhai scripts it names. The starter’s sms-gateway declares:

providers/sms-gateway/provider.yaml
prepareScript: scripts/prepare.rhai
interpretScript: scripts/interpret.rhai
receiptScript: scripts/receipt.rhai
request:
method: post
headers: [idempotency-key, x-request-id]
responseHeaders: [x-request-id]
capabilities:
receipts: callback
maximumConcurrentRequests: 8

The scripts see plain data only, never a credential, a URL, or a header value the runtime owns:

ScriptReceivesReturns
prepare(message, profile)The message’s messageId, generation, attempt, channel, recipient, parts, and idempotencyKey when the provider declares idempotentSubmit; the profile’s id, channel, sender, maximumSegmentstarget relative to the operator’s baseUrl, declared headers, bodyFormat json or form, and body
interpret(response)status, the declared response headers, and the decoded bodyoutcome: accepted with a providerReference, transient with an optional retryAfter, permanent with an optional code, or maybe-sent
receipt(request)A verified callback’s method, with its form, query, and json limited to the parts the verifier authenticates; an unauthenticated part reads as emptyproviderReference and report (sent, delivered, or undelivered), or () to ignore the callback

Without an interpret script, a 2xx is accepted, 429 and 503 are transient, 408 and any other 5xx are maybe-sent, and any other status is permanent with the code http.<status>. An interpret script that fails falls back to the status, except that an unreadable 2xx is maybe-sent. Return maybe-sent whenever the provider may have taken the message: that is what keeps it from being sent twice under onUncertain: hold.

Two more examples live in the Registry Stack repository under products/messaging/examples/providers/: mock, a loopback mock, and form-sms-gateway, a form-encoded gateway with a form callback.

messagingctl package writes the package into a directory that does not exist yet:

Terminal window
messagingctl package tutorial-work/notices --output tutorial-work/notices-package
created: tutorial-work/notices-package
package digest: sha256:a77193bf48a8fdcc09a4576991fbd0441307cd23e34c550d27a740b66cd0dfce
package files: 19

The digest is the one check reported. The package holds messaging.yaml, the providers, the templates, and a SHA256SUMS envelope, with no runtime file, credential, or development state. Check it as the operator will:

Terminal window
messagingctl check --package tutorial-work/notices-package

The report is the project’s, headed ok: tutorial-work/notices-package, with the same digest. Give the operator the directory and the digest. The runtime refuses a package whose files differ from its SHA256SUMS before it connects to the database, serves only the digest the operator recorded, and sends only what the package holds, so editing the project never changes what a running deployment sends.