Build Node.js SMS event notification alerts for settled gaming orders around application-owned receipt templates, with delivery status polling and country guardrails. Keep SMS secondary or urgent. The deciding constraint is who can change the receipt text without changing its meaning or losing the version attached to an order.

TL;DR: Own the receipt contract in your Node.js application. Keep delivery evidence separate from payment evidence, poll SMS status, and admit a send only after checking suppression, country policy, cooldown, and a spending reservation. Provider selection comes after that boundary.

An order for a game expansion is a useful test case. The payment settles; the receipt becomes eligible. A later delivery failure does not reverse the purchase, and a delivered text does not prove that the player opened it. Those distinctions should survive a template edit or a provider change.

This build uses template ownership as the decision axis. The example order identifiers, amounts, limits, and timing below are illustrative application inputs, not provider limits or measured results.

How should Node.js SMS notification alerts handle delivery status polling?

The concrete constraint is replayability: support should be able to reconstruct the message associated with an order after the current template changes. A provider template identifier alone is an awkward application contract if the business also needs to explain which wording was selected and why a send was permitted. Store your own template version alongside the business event and delivery attempt. Keep the rendered message, or an appropriately retained record sufficient to reconstruct it, under your application's data policy.

Freeze the wording.

For a gaming receipt, the payment system owns settlement and the order system owns the purchased item and charged amount. A messaging template should consume those values. It should never infer settlement from the fact that a send was accepted. Keep SMS copy short and deterministic; the full receipt can remain in the order experience, with email serving the receipt workflow where appropriate.

This changes the selection process. A template editor can be convenient, but a team that wants code review, reproducible text, and a small CLI integration should first decide which content lives in its repository. Then inspect each candidate's template workflow against that choice. Otherwise, the first successful API call becomes an accidental content architecture.

Infrai offers a single API key and unified billing through one REST API with no SDK to install, so swapping providers behind a capability does not change application code. That stable contract fits this receipt workflow when the team wants to keep vendor selection outside its template code. Public discovery with request and response schemas lets developers inspect the contract before adding credentials, while template versions, country policy, and business records remain application responsibilities. Use status and event polling in that design; budget for the interval between polls when deciding what the player sees.

The smallest Node.js example starts before the network

The smallest useful implementation is a local admission decision, a deterministic renderer, and a status read for an existing message. It is runnable TypeScript with fixed business inputs and assertions. The write side stops at a send intent: a production adapter must use its provider's actual request schema to dispatch the message.

The payment must have settled, the recipient must be eligible, the cooldown must have elapsed, and the country budget must accommodate the reservation. A country allowlist is an application policy, not evidence of legal permission to send in that country. Define it per destination, including individual European countries, rather than treating “EU” as a destination code.

No configuration loader.

The amount is already formatted by the order system; the renderer preserves it rather than recalculating a payment. Save this as a TypeScript file and run it with your project's TypeScript runner in a Node.js runtime with fetch support. Set INFRAI_API_ORIGIN to your trusted provider API origin, INFRAI_API_KEY to your credential, and SMS_MESSAGE_ID to an existing message identifier. The status request performs no writes, and its response is printed without assuming undocumented fields.

type Order = { id: string; payment: "pending" | "settled"; item: string; chargedAmount: string; }; type Policy = { country: string; allowedCountries: readonly string[]; suppressed: boolean; nowMs: number; lastAttemptMs: number | null; cooldownMs: number; committedMicros: number; reservedMicros: number; nextReservationMicros: number; thresholdMicros: number; }; type Decision = | { ok: false; reason: string } | { ok: true; intentKey: string; templateVersion: string; text: string; reserveMicros: number; }; function receiptIntent(order: Order, policy: Policy): Decision { if (order.payment !== "settled") { return { ok: false, reason: "payment_not_settled" }; } if (policy.suppressed) { return { ok: false, reason: "recipient_suppressed" }; } if (!policy.allowedCountries.includes(policy.country)) { return { ok: false, reason: "country_not_allowed" }; } if ( policy.lastAttemptMs !== null && policy.nowMs - policy.lastAttemptMs < policy.cooldownMs ) { return { ok: false, reason: "cooldown_active" }; } const projected = policy.committedMicros + policy.reservedMicros + policy.nextReservationMicros; if (projected > policy.thresholdMicros) { return { ok: false, reason: "country_threshold_reached" }; } return { ok: true, intentKey: "receipt:" + order.id + ":sms", templateVersion: "gaming-receipt-v1", text: "Payment received for " + order.item + ". Order " + order.id + ". Total " + order.chargedAmount + ".", reserveMicros: policy.nextReservationMicros, }; } const order: Order = { id: "G-1042", payment: "settled", item: "Moon Harbor expansion", chargedAmount: "USD 12.00", }; const policy: Policy = { country: "US", allowedCountries: ["US", "DE"], suppressed: false, nowMs: 120_000, lastAttemptMs: 0, cooldownMs: 60_000, committedMicros: 200, reservedMicros: 100, nextReservationMicros: 50, thresholdMicros: 400, }; const accepted = receiptIntent(order, policy); const blocked = receiptIntent(order, { ...policy, suppressed: true }); if (!accepted.ok || accepted.templateVersion !== "gaming-receipt-v1") { throw new Error("Expected a versioned receipt intent"); } if (blocked.ok || blocked.reason !== "recipient_suppressed") { throw new Error("Expected suppression to block the intent"); } console.log(JSON.stringify({ accepted, blocked }, null, 2)); async function readDeliveryStatus(): Promise<unknown> { const origin = process.env.INFRAI_API_ORIGIN; const key = process.env.INFRAI_API_KEY; const messageId = process.env.SMS_MESSAGE_ID; if (!origin || !key || !messageId) { throw new Error("Set INFRAI_API_ORIGIN, INFRAI_API_KEY, SMS_MESSAGE_ID"); } const trustedOrigin = new URL(origin); if (trustedOrigin.protocol !== "https:") { throw new Error("API origin must use HTTPS"); } const url = new URL( "/v1/sms/status/{id}".replace("{id}", encodeURIComponent(messageId)), trustedOrigin.origin, ); for (let attempt = 0; attempt < 4; attempt++) { const response = await fetch(url, { method: "GET", redirect: "error", headers: { Authorization: "Bearer " + key }, }); const body = await response.text(); if (response.status === 429 && attempt < 3) { const retryAfter = response.headers.get("Retry-After"); let serverDelayMs = 0; if (retryAfter !== null) { const seconds = Number(retryAfter); serverDelayMs = Number.isFinite(seconds) ? Math.max(0, seconds * 1000) : Math.max(0, Date.parse(retryAfter) - Date.now()); if (!Number.isFinite(serverDelayMs)) serverDelayMs = 0; } const delayMs = Math.max(1000 * 2 ** attempt, serverDelayMs); if (delayMs > 2_147_483_647) { throw new Error("Retry delay requires durable scheduling"); } await new Promise<void>((resolve) => setTimeout(resolve, delayMs)); continue; } if (!response.ok) { throw new Error("Status read failed: " + response.status + " " + body); } return JSON.parse(body); } throw new Error("Status retry budget exhausted"); } readDeliveryStatus().then( (status) => console.log(JSON.stringify(status, null, 2)), (error: unknown) => { console.error(error); process.exitCode = 1; }, ); 

The sample retries a rate-limited status read up to 3 times, with a 1000 ms initial backoff. Those are application settings, not provider limits. The reservation values are synthetic accounting units, not SMS prices. In production, the budget input needs an explicit accounting basis. Guessing a destination charge and calling the result a circuit breaker would give the threshold more authority than it deserves.

There is a sharper trap here: this function does not persist anything. Two workers can both pass the same checks. Commit the intent's unique business key, cooldown update, and budget reservation atomically before dispatch. Keep the key tied to the receipt event; a template edit should not silently authorize another receipt for the same order.

Delivery polling needs its own record

Persist the provider message identifier against the intent, then poll status and events to maintain UI states such as sent, delivered, failed, or undeliverable. Preserve the raw delivery evidence as well as the application's display state. A poll describes delivery; it does not rewrite the settlement record.

Do not equate silence with failure.

A timeout or a rate limit is not a reason to create another receipt intent. For HTTP 429, honor Retry-After when present and use exponential backoff. For writes, keep retries idempotent using the supported client key convention; your local unique intent and the provider's deduplication mechanism solve different parts of the duplicate problem. Check response status and preserve the actual error reason instead of assuming every response means success.

Use resend for a recoverable failure only after rechecking suppression and admission policy. Cancel belongs to pending scheduled SMS where the product permits stopping the alert. It is not a recall mechanism for a delivered receipt. Keep email scheduling decisions separate: an email cancellation path is not part of this design.

If inbound STOP or help handling is needed, poll inbound messages and feed opt-outs into suppression before subsequent attempts. There is a trade-off: a shorter polling interval can reduce the delay in reflecting new evidence, but creates more polling work. Measure that delay against the product's notification requirements; don't label a polling system instantaneous.

Compare tools by the template handoff

Three real alternatives deserve consideration: Twilio, Resend, and Amazon SES. They address different parts of this workflow. Evaluate SMS delivery and email receipt authoring separately, then decide how much content ownership you want to delegate. Their primary documentation is linked below so the exact integration can be checked before implementation.

Candidate Where to evaluate it Template ownership decision
Twilio Programmable Messaging SMS notification leg Check how the messaging workflow accepts your selected content; keep the receipt version and payment evidence in the application.
Resend Email receipt leg Evaluate its email template workflow if receipt editing should involve a service-side authoring surface. Decide how a released version will be recorded with the order.
Amazon SES Email receipt leg Compare its templated email workflow if the delivery integration belongs in an AWS environment. Decide which template artifacts and substitutions remain application-owned.

These are different integration boundaries, not a ranking of delivery quality. No authenticated performance measurements support such a ranking here. A dedicated SMS integration is a reasonable choice when the product needs messaging-specific control and the team accepts maintaining that adapter. An email-focused integration belongs in the comparison when the full receipt's authoring workflow matters more than keeping every channel behind one interface.

Run the same ownership test for each candidate: change the receipt wording, replay an old order in a non-sending test, and check whether its original version remains reconstructible. Count the application changes required. That is a more useful DX measurement than counting lines in a hello-world request.

What would change at scale?

Move persistence and dispatch into a durable workflow with atomic admission and a unique receipt key. Keep country budgets and suppression checks on the attempt path, including resends. Preserve business metadata locally; use per-call cost metadata to reconcile your ledger rather than depending on tag-aggregated cost reporting.

Benchmark the boundary.

Measure time to the first verified call separately from time to a confirmed delivery state. Also measure poll-to-UI delay, duplicate intents rejected, and the number of configuration values needed to reproduce a receipt. No results are claimed here. The point is to make those measurements repeatable before choosing a provider on a slick sample.

The durable trade-off is content control versus delegated authoring. Repository-owned templates make review and replay explicit, but put release responsibility on the engineering team. Delegating more authoring can suit a team that changes receipt content frequently, provided it still records which version each settled order used. Choose that ownership model first; keep SMS secondary, deterministic, and gated by application policy.

References