Alerts by text and email
Owner alerts. Twilio SMS + email, dependency-free & fail-safe
For when the answer to “Text or email me when something breaks” is yes.
Text or email yourself when something matters (an export failed, the shared API key is out of credit) with no npm dependency and no risk to the request path: it never throws, owner() throttles so failures can't spam you, and it no-ops when unconfigured.
Skip the rebuild
You do not write this one. It arrives in your project as ordinary source you can read, change and keep, with its audit record and its caveats beside it.
- Download the Playground. It is free and runs on your own machine.
- Start a new app and tick “Text or email me when something breaks”.
- This block is written in, along with anything else you ticked.
The mistake it removes
The naive version calls Twilio from the wrong place or lets a paging failure crash the very request it was trying to report. And a Twilio auth token in client code is a full-account credential leak.
What is already handled
Some are checked by running the block’s own tests every time its checks run and some only by reading the shipped source. Each item’s label says which. Tested means the block’s own test suite runs that code. It does not mean a live run against an outside service such as a payment provider.
- 44 node assertions (counted here: test/notify-kit.test.mjs), all passing, with fetch injected as a mock Tested
- the Twilio REST call is built correctly: Basic auth = base64(sid:token), urlencoded From/To/Body, /2010-04-01/Accounts/<sid>/Messages.json Tested
- sms/email no-op with {skipped} when their channel isn't configured, never a half-built call Tested
- reads TWILIO_*/RESEND_* from env when config isn't passed explicitly Read in the source, not run
- NEVER throws into the caller: a rejected fetch or a non-2xx returns {ok:false,...} and logs; owner() uses Promise.allSettled so one dead channel can't sink the other Tested
- owner() throttles a second page inside the window (verified with an injected clock) and pages again after it elapses Tested
- owner() is loud-but-harmless when no channel is configured (logs the fix, returns {unconfigured:true}) Tested
- every Twilio and Resend call has a deadline (timeoutMs) and carries an AbortSignal: with a fetch that never settles, owner() resolves with sent:false and error:'timeout' on each channel Tested
- a page that reached no channel holds the throttle only for failBackoffMs, so the next page after the backoff is sent; a page that got through still holds the full window Tested
- sms() refuses a `to` that is not E.164 (no plus sign, two numbers joined, letters, a non-string) without making any upstream call, and still sends to a real E.164 number; sms() and email() are not throttled, and the docs now say only owner() is Tested
What the audit found
Named rather than summarized. The reasoning behind each one ships inside the block, so it travels with the code instead of living on a page you have to trust. A finding marked fixed was fixed after the audit ran; the verdict above is still the one the audit gave.
- No deadline on the Twilio or Resend fetch; owner() can hang the request path it promises to protect major · Error handling & resilience (7) Fixed after the audit in
1fae4e796 - A failed page burns the throttle window: one transient provider error silences the pager for the whole hour with no retry major · Correctness (2) / Error handling (7) Fixed after the audit in
1fae4e796 - 'Throttles so failures can't spam you' applies only to owner(); sms() and email() are unthrottled and accept a caller-supplied `to` minor · Claims match behavior (25) / API cost (12) Fixed after the audit in
2750e8008
One more finding is written in the auditors' internal shorthand, so it is not listed here. The full text is in the report inside the block. It was fixed after the audit, in 30bc5b88c.
What you still have to do
A copied file cannot own your secrets, your host or your legal obligations. This is the part the block deliberately does not claim.
- Keep this on the server and out of every client bundle. A Twilio auth token is a full-account credential; there is deliberately no vanilla build, but nothing stops a host importing the module into browser code.
- A shared-store throttle, or spend caps set in the Twilio and Resend dashboards. The throttle here is in-memory per warm serverless instance, so a cold start may send one extra page and a fleet sends one per instance.
- TWILIO_AUTH_TOKEN and RESEND_API_KEY must come from your host's environment or secret manager. The block reads them from env; it does not store, rotate or scope them.
- Twilio and Resend are paid/rate-limited services; a page still costs a fraction of a cent and counts against their limits. The throttle bounds it, honeypot/abuse paths shouldn't call owner() per request.
- Only owner() is throttled. sms() and email() send on every call and accept a `to`: never pass them a `to` taken from request input, and never call them once per request on a public route, or a stranger can run up your Twilio bill (toll fraud). sms() refuses a `to` that is not E.164, which is a format check and not a rate limit.
- isCreditError is an Anthropic-specific example predicate: swap it for whatever condition should page you.
What lands in your project
node
- node/notify.js
createNotifier(config?) -> { sms, email, owner, smsConfigured, emailConfigured }. Also exports isCreditError(status, msg). Reads TWILIO_*/RESEND_* from env by default, or pass explicit config. Dependency-free (raw REST + fetch).
What you supply
- TWILIO_ACCOUNT_SID / TWILIO_AUTH_TOKEN / TWILIO_FROM: your Twilio creds + sending number (+15551234567)
- ALERT_SMS_TO: the phone that gets the text
- RESEND_API_KEY / EMAIL_FROM / ALERT_EMAIL_TO: optional email channel (Resend)
- throttleMs: min gap between owner() pages (default 1 hour)
- timeoutMs: deadline on each Twilio or Resend call; past it the send returns {ok:false, error:'timeout'} (default 10 seconds)
- failBackoffMs: after an owner() page that reached no channel, how long until the next page may try again, instead of the full throttle window (default 60 seconds)
Licensed MIT. It is a starting point, not a finished product.
Get it
Download the Playground See the other blocks
Nothing here is locked. The files are yours, in your folder, under a permissive license.
Questions
- Is Alerts by text and email audited?
- It was audited on 2026-09-29, and the verdict was not a clean pass. 4 findings have been fixed since then, and the verdict stands until the block is audited again.
- What do I still have to do myself?
- Keep this on the server and out of every client bundle. A Twilio auth token is a full-account credential; there is deliberately no vanilla build, but nothing stops a host importing the module into browser code.
- How do I get this code?
- Download the Playground, start a new app, and tick “Text or email me when something breaks”. The block is written into your project as ordinary source you can read and edit.
All pre-built code blocks · Learn to build from zero · The coding guide