Order digest
This example collapses several orders for the same customer into one summary email, using the digest building block.
The flush workflow
Section titled “The flush workflow”A normal workflow that receives the accumulated
batch as payload.items:
import { workflow } from '@palumb/sdk/bridge';
const orderDigest = workflow('orderDigest', async ({ payload, step }) => { const items = (payload.items as Array<{ orderId: string }>) ?? []; if (items.length === 0) return; const list = items.map((i) => `<li>${i.orderId}</li>`).join(''); await step.send('digest', 'email', () => ({ subject: `${items.length} order(s) received`, body: `<p>Your recent orders:</p><ul>${list}</ul>`, }));});Push items as orders happen
Section titled “Push items as orders happen”for id in O-1 O-2 O-3; do curl -sS "$PALUMB_BASE_URL/v1/digests/orders/items" \ -H "Authorization: Bearer $PALUMB_API_KEY" \ -H 'Content-Type: application/json' \ -d "{ \"workflowId\": \"orderDigest\", \"subscriberId\": \"cust_1\", \"data\": { \"orderId\": \"$id\" }, \"windowSeconds\": 5 }"doneThe flow
Section titled “The flow”flowchart TD
T["POST /v1/digests/orders/items ×3<br/>same subscriber, within the window"]
D["palumb accumulates the batch<br/>(keyed by subscriber) · arms the window timer"]
F["after windowSeconds<br/>run orderDigest({ items }) → step.send (ONE email)"]
S["palumb delivers → SMTP"]
T --> D --> F --> S
Three items in, one email out.
Related
Section titled “Related”- Digest — the building block in depth.
- Quickstart — the full setup, end to end.