I built a missed-call text-back + AI lead reply system on Cloudflare Workers (open source)
Local service businesses (plumbers, HVAC, roofers, electricians) miss a lot of calls. They're on a ladder, under a sink, or driving. Most callers who hit voicemail don't leave a message; they just call the next company o
Local service businesses (plumbers, HVAC, roofers, electricians) miss a lot of calls. They're on a ladder, under a sink, or driving. Most callers who hit voicemail don't leave a message; they just call the next company on Google.
So I built a small, open-source system that fixes that with three automations, running on a single Cloudflare Worker:
- Missed-call text-back: calls still ring the owner's phone. If nobody answers, the caller gets a friendly text within seconds and the owner gets an alert.
- Instant AI lead reply: website form leads get a short, personal SMS written by Claude in seconds, 24/7. If the AI call fails, a safe template goes out instead.
- Review requests: after a job, the customer gets a text with the Google review link.
Code: https://github.com/pbisjoint/missed-call-text-back-ai (MIT licensed)
How it works
Caller -> Twilio number -> /voice (Worker) -> <Dial> owner's phone (20s)
|
no answer -> /voice/status -> SMS to caller + alert to owner
Web form -> /lead -> Claude drafts reply -> SMS to lead + alert to owner
Job done -> /review -> SMS with review link
The whole thing is ~250 lines of plain JavaScript with no dependencies. Cloudflare's free Workers tier covers typical small-business volume, so the running cost is basically the Twilio number plus SMS fees and a few cents of Claude usage.
The missed-call part
Twilio hits /voice when someone calls. The Worker returns TwiML that forwards the call to the owner with a timeout and an action callback:
const twiml =
`<Response><Dial timeout="20" action="${statusUrl}" method="POST">` +
`${env.OWNER_PHONE}</Dial></Response>`;
When the dial ends, Twilio posts DialCallStatus to /voice/status. Anything other than completed means nobody picked up, so the caller gets a text.
Don't skip signature validation
Any public webhook URL will get hit by random traffic. The Worker verifies X-Twilio-Signature (HMAC-SHA1 of the URL plus sorted POST params) with WebCrypto and rejects anything that doesn't match. The test suite checks the implementation against the example in Twilio's own security docs.
Keeping the AI reply safe
The system prompt is deliberately narrow: under 300 characters, acknowledge the issue, say someone will call shortly, ask one useful question (address, urgency or a photo). It never quotes prices or promises arrival times. The model output is trimmed and capped before sending, and there's a fallback template if the API errors.
Setup in about 30 minutes
- Buy a Twilio number (in the US, register for A2P 10DLC first)
- Edit
wrangler.tomlwith the business details -
wrangler secret putthe Twilio token, Anthropic key and an API key npx wrangler deploy- Point the Twilio number's voice webhook to
/voiceand the site's form webhook to/lead?key=...
Run npm test to check the 10 tests: signature checks, forwarding, missed-call texts, auth, AI reply with fallback, and reviews.
Compliance notes
Only text people who contacted the business, add consent wording to the form, and honour STOP replies (Twilio handles STOP/HELP automatically).
Want it set up for you?
If you run a local business (or an agency with clients who miss calls) and want this deployed for you, open an issue titled "Setup request" on the repo with your business type and city, and I'll reply with a fixed quote.
This post and the code were written with help from Claude.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.