Channel examples
One complete, copyable example per channel (email over SES or Cloudflare, APNs, FCM, Web Push, Slack, Discord, push-else-email, and SMS through a custom action), from the secrets it needs to what you see once it is sent.
This page is a cookbook: one end-to-end example per channel, each in the same order. First what the channel needs configured, then the template, its registration, the step that sends it, how the recipient is found, what you see once it is sent, and the pitfalls. The reasoning behind templates, topics and opt-outs is on Templates and channels, what happens when a send fails is on Delivery, and every step is described on Steps.
The shared contract
Every example below reads this contract. Profile fields feed props through u, and the triggering event's payload feeds them through the trigger handle (see Reading the triggering event).
All templates end up in one registry, and the config registers it once:
logMessages: true echoes every outbound copy to the log before it is sent, which is what the "what you see" parts below show. The host itself is covered per runtime on Cloudflare, AWS Lambda and self-hosting; only the parts each channel adds are shown here.
Configure. A transport, passed as the host's email option (one of the three below), and a sender domain the provider has verified. With Postgres reporting and an https WORKFLOW_ORIGIN, links and opens are tracked and the topic email gets a one-click List-Unsubscribe header; without them the email still goes out. A host whose workflows send email but that has no email option fails when it is created, naming those workflows.
Templates. Each template names its own from; there is no global sender, so share addresses through a module. The layout reads the unsubscribe and preference links from the render context, so one layout serves a transactional email (no links) and a topic email (both links):
Register.
Send. The receipt takes its order fields from the event that started the journey and the name from the profile:
Recipient. The profile's email property, read when the step runs. A user without one gets no email: the copy is settled undelivered as no_recipient (or invalid_recipient for a value that is not a bare user@host), and the journey goes on. Report the profile and the event in one ingest call so the address is there before the journey starts (see Sending events).
What you see. In development, with logMessages:
With Postgres, each copy is a row of message, settled with delivered_at (the transport accepted it) or undelivered_reason:
A topic email opted out of leaves no row: it was skipped before a copy existed. Studio renders every email template from its preview props, with its From, Reply to, Subject and unsubscribe link above it (Studio views), and the host serves GET /preview/order_receipt?props=<JSON> (with the API bearer), the subject percent-encoded in the x-subject header.
Pitfalls.
- No
emailon the profile isno_recipient, not an error: watch that reason in the report rather than waiting for a failed instance. - The
List-Unsubscribeheader names only https URLs, so a localhttp://origin sends none. Test one-click unsubscribe on a deployed host. preferencesUrlmust not share its origin and path with an unsubscribe URL; the config refuses one that does. See Unsubscribe and preference links.
Amazon SES
sesEmailTransport from sendwend/transports/ses calls the SES v2 SendEmail API with a SigV4 signature over plain fetch, so it runs in a Worker, a Lambda and Node alike. Options: region, credentials (fixed values or a function read on every send), configurationSetName and endpoint.
On AWS Lambda, leave credentials out: the transport reads AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN at send time, the function's execution role, which needs ses:SendEmail:
A Worker has no execution role, so it passes the keys from its validated environment:
A refusal settles under SES's own error code (MessageRejected, for example); throttling (TooManyRequestsException, Throttling, and the rest of the AWS SDK's retryable set) and 5xx are retried. SES takes no idempotency key, so a request it never answered settles as no_answer and is not sent again (Delivery). Mailbox providers honor List-Unsubscribe only when DKIM signs it; check one real message, as AWS Lambda describes.
Cloudflare Email Sending
cloudflareEmailTransport from sendwend/transports/cloudflare-email takes either a Worker's send_email binding or an account id and API token for the REST API, which works from anywhere:
Under wrangler dev the binding only simulates sending and writes the rendered email to a file. A REST refusal settles as cloudflare_<code> (Cloudflare's first error code) or Refused<status>; a REST request that got no answer settles as no_answer. What the binding throws is taken as a refusal and retried, because the binding does not say whether the email left. Cloudflare rejects a List-Unsubscribe header with a non-TLS URI, which is one more reason the header needs an https WORKFLOW_ORIGIN (Cloudflare).
Another provider
The email channel is split where the provider starts to matter: EmailSender renders the template, applies tracking, commits the tracked links and hands a finished EmailMessage (from, to, replyTo?, subject, html, headers?, idempotencyKey) to an EmailTransport. Any object with that one send method is a transport:
Resolving means the provider accepted the email. A thrown error is classified by what it carries: a reason string names the refusal, retryable: false or a PermanentError makes it permanent, and unanswered: true (or UnansweredSendError) marks a request with no answer (Delivery).
Push
Configure. Each platform is turned on by its config entry, with its secret in the environment. A secret is read only when something is sent on that platform, so a journey that only emails does not need the APNs key in a local .dev.vars. A platform a device registered for but the config does not turn on settles that copy as not_configured.
Templates. One push template serves all three platforms. content(props) returns { title, body, image?, url? }, synchronously, with final text:
Register.
Send. One copy per device the user has, or only the most recently registered one with { devices: 'latest' }:
Recipient. The devices the engine keeps in its device table. Your backend registers each token with JourneyClient.registerDevice (POST /devices), and a token moves to the latest user that registers it:
platform picks the provider: ios goes to APNs, android to FCM, web to the browser's push service. A user with no device is skipped: no copy, no row, and the log says push order_shipped_push skipped: no device for user u_123. A topic push the user opted out of on push (the topic, or all push) is skipped too. Branch on reachable('push') to do something else for them. Sending events covers sign-out (unbindDevice) and visitors.
What you see. With logMessages, one line per device, the recipient being the device token:
Each device's copy is its own message row and its own durable step, so one device's refusal does not stop the others. With reporting on, the push carries message_id, and, with WORKFLOW_ORIGIN, delivered_url and opened_url for a client that reports straight to the host. The app reports a tap with JourneyClient.messageOpened(userId, messageId). Studio previews each push template as an iPhone and a Pixel lock screen.
Pitfalls.
- A token the provider reports as gone is removed. Any other refusal about one device keeps the device and settles the copy under the provider's reason; if one reason shows up for every device, the deployment's configuration is wrong, not the devices.
- Opt-outs are per channel: a topic switched off for push is still sent by email.
- FCM does not de-duplicate; APNs and Web Push collapse a repeated copy on the device. See Delivery.
APNs
iOS pushes go straight to Apple with a token-based auth key; there is no Firebase in between, so the app registers its APNs device token with platform: 'ios'.
| What | Where |
|---|---|
apns.topic | The app's bundle id (APNs's apns-topic) |
apns.keyId, apns.teamId | The auth key's 10-character id and the Apple Developer team id |
apns.environment | Optional map from mode to sandbox or production |
APNS_PRIVATE_KEY_BASE64 | The .p8 file, base64-encoded |
The request carries aps.alert with the title and body, sound: 'default', and next to aps the template id, the idempotency key, image and url when the content has them, and the tracking fields (message_id, delivered_url, opened_url). A push with an image or a delivered_url is sent with mutable-content: 1, so a notification service extension can attach the image and report the delivery.
APNs speaks HTTP/2 only. A deployed Worker's fetch negotiates it, and the Node and Lambda hosts use the package's own HTTP/2 client, but wrangler dev cannot. Locally, run the relay from sendwend/apns-relay next to it:
The relay listens on loopback, has no auth of its own and forwards only to Apple's two hosts. It sees the provider JWT, so a production host (ENVIRONMENT unset or production) ignores APNS_RELAY_ORIGIN, calls Apple directly and logs one error saying so.
APNs pitfalls:
- A development build's token (Xcode, the simulator) is a
sandboxtoken; App Store and TestFlight builds areproduction. A token sent to the other environment answersBadDeviceToken, and the device is kept. DeviceTokenNotForTopicis a token of another bundle id, such as a development build registered against this backend.BadTopic,TopicDisallowedor a bad provider token are the configuration: every copy settles under that reason until it is fixed.
FCM
Android pushes go through the FCM HTTP v1 API with a service account. Create a key for the Firebase project's service account and store the JSON file base64-encoded:
The app registers its FCM registration token with platform: 'android'. The message carries notification (title, body, image) and data with the template id, the idempotency key, url and the tracking fields, so the app can route a tap and report it. The access token is minted from the service account and reused for its hour, shared by every run of the host.
FCM pitfalls:
SENDER_ID_MISMATCHis a token from another Firebase project;INVALID_ARGUMENTkeeps the device too. Seen for every device, they mean the service account belongs to the wrong project.THIRD_PARTY_AUTH_ERRORis refused for good;UNREGISTEREDand 404NOT_FOUNDremove the token.- FCM has no collapse header: a request it never answered settles as
no_answerrather than risking a second notification.
Web Push
Browser pushes use standard Web Push with VAPID, one sender for Chrome, Edge, Firefox and Safari. Generate one key pair per environment with generateVapidKeys():
Both keys go in the host's environment (VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY); the public key also goes to your web app, which subscribes with it. The config's webPush entry takes subject (mailto: or an https: URL), openedEvent (a contract event a notification tap is also recorded as, with { message_id }, so conditions see web opens) and pushServices (extra push service hosts).
The device token is the browser's PushSubscription as JSON. The page subscribes and hands it to your api, which registers it, because the engine's API_TOKEN never reaches the browser:
The service worker receives { title, body, image?, url?, template, idempotencyKey, message_id, delivered_url?, opened_url? } as the push event's JSON. Reporting the delivery and the tap straight to the host needs no session: the message id in the URL names the copy.
Web Push pitfalls:
- Only an https endpoint on a browser's push service is accepted (
fcm.googleapis.com,*.push.services.mozilla.com,*.notify.windows.com,*.push.apple.com).POST /devicesanswers 400 for any other; name further hosts inwebPush.pushServices. - The encrypted payload holds at most 3993 bytes of JSON. A larger one is refused before sending as
PayloadTooLarge, so keeptitle,bodyandurlshort. - A new VAPID pair invalidates every subscription made with the old one: keep one pair per environment and do not rotate it casually.
Slack
Configure. A Slack incoming webhook URL (a Slack app with incoming webhooks, added to the channel). It is a secret, so it lives in the host's environment, and the template reads it when it sends. Declare it in the environment schema passed to the host, so a missing value fails on the first request with every problem listed:
Pass it as journeyWorker({ ..., env }) (or journeyLambda's env); on Node, the URL goes in vars.
Template. content returns a Slack incoming-webhook body: text (required, the notification fallback) and optional Block Kit blocks, plus username, icon_emoji and the other fields of SlackContent:
Templates import only the Env type: Studio loads them in Node, where the Worker's environment does not exist.
Register.
Send.
Recipient. The template's webhook, not a person: Slack posts have no per-user address, no topic and no opt-out. A webhook the environment does not hold settles the copy as not_configured, naming the template.
What you see. [journey] slack cs_churn_alert → u_123 {...} in the development log (there is no recipient address, so the user id is printed), a message row like any other channel, and in Studio the message drawn in Slack's style; a block type the preview does not draw shows as a placeholder naming it.
Pitfalls.
- A webhook Slack reports as gone (
no_service,channel_not_found,channel_is_archived,action_prohibited) or any other 4xx settles the copy undelivered and is not retried, so a deleted webhook drops posts quietly. Watch those reasons. textis required even withblocks; a template that returns none fails the step, because that is the workflow, not the channel.- Slack does not de-duplicate a webhook post: one that got no answer settles as
no_answerand is not posted again.
Discord
Configure. A Discord channel webhook (the channel's settings, Integrations, Webhooks), stored as a secret exactly like Slack's: WEBHOOK_DISCORD_COMMUNITY in the schema above, then wrangler secret put WEBHOOK_DISCORD_COMMUNITY.
Template. discordTemplate takes the same fields as slackTemplate; content returns a Discord webhook body (content, embeds, username, allowed_mentions, ...). It must show something (content, an embed, a poll or components), and content holds at most 2000 characters:
Register and send.
Recipient. The template's webhook, as for Slack. What you see: the same log line and message row, and Studio draws the message in Discord's style.
Pitfalls.
- A 404 or 401 settles as
UnknownWebhook(deleted, or its channel is gone); another 4xx asHTTP <status>. Neither is retried. allowed_mentions: { parse: [] }keeps a name like@everyonein user data from pinging the server.- Like Slack, a post with no answer is
no_answerand not posted again; 429, 408 and 5xx are retried.
Push, else email
.prefer() sends one message on the first channel the user can be reached on, from one push and one email template that declare the same props type. The two tip templates above share tipProps, which is what makes this compile:
It compiles to the branch you could write by hand, with the same IR and hash:
Recipient. reachable('push') is true when the user has a device and has not opted out of all push. Then every device gets the push; otherwise the profile's email gets the email, by the rules of each channel above. The choice is made once, when the step is reached.
What you see. One log line and one message row (per device for push) on the channel that was chosen; the canvas shows the branch with its label.
Pitfalls.
- A topic opt-out on push leaves
reachable('push')true. A user who turned off only "tips" on push takes the push arm, the push is skipped as opted out, and no email is sent. Write the branch yourself if that user should get the email. - A push that fails retries as a push; it never falls through to email. Devices that refuse settle undelivered, and the journey goes on without an email.
- Different props, or other channels, need the explicit
.branch(). See.prefer().
Other channels
The IR's channel set also has sms, in_app and survey, and the chain has .sms(), .inApp() and .survey() steps. What the SDK ships for them today:
| Step | IR channel | Recipient the engine resolves | Template definition | Built-in sender |
|---|---|---|---|---|
.sms() | sms | the profile's phone | none: template.sms<P>(key), by key | none |
.inApp() | in_app | none | none: template.inApp<P>(key) | none |
.survey() | survey | the profile's email | none: template.survey<P>(key) | none |
These steps compile, and their props are typed by the hand-written P, but the config's channels deliver only email, push, Slack and Discord. A copy on one of these channels reaches no sender: it settles undelivered as not_configured and the journey goes on. The host's messages option takes a MessageSender that receives every outbound copy, but it replaces every channel, email included, so it suits a gateway that delivers everything.
To add one channel and keep the built-in ones, use a custom action. Here is an SMS sent when an order ships, with a placeholder provider URL:
The action is registered in the config's actions (as in the config at the top), and compileBundle checks that the action a workflow runs is the object listed there. The handler's context holds only userId and idempotencyKey, not the host's environment, so it reads the provider key the way the runtime exposes secrets to modules: process.env on Node and Lambda, and on a Worker, Cloudflare's import { env } from 'cloudflare:workers'.
An action is not a message, which is the trade-off:
- It runs at least once: retried when it throws, checkpointed when it succeeds, so it can run twice for one journey. Pass
ctx.idempotencyKeyto the provider (Delivery). - There is no opt-out check, no
messagerow and no delivery report for it. Gate it in the workflow (thefilterabove), and keep your own record if you need one. - A
PermanentErrorstops the retries but still fails the step, and a step that fails without a retry fails the journey. Return instead of throwing if the journey should go on after a refusal.
Related
- Templates and channels: topics, opt-outs and what each channel checks.
- Delivery: at most once, and every outcome a copy can have.
- Steps: the message steps,
.prefer()and.run(). - Sending events: registering devices and reporting taps.