What this workflow does
- Twilio inbound SMS (Webhook) receives the reply, and Reply to Twilio (empty TwiML) answers Twilio straight away.
- Normalize and screen (Code) converts the number to E.164 and checks fixed rules before any AI: single-word opt-out keywords (STOP, CANCEL, END, QUIT, UNSUBSCRIBE and others), HELP, and your clinician-written urgent phrase list.
- Postgres: look up consent and appointment reads the consent row and the next upcoming appointment for that number.
- Gate on consent (Code) applies the order that matters: opt-outs are always recorded; numbers without recorded consent are never texted and go to staff; urgent phrases get a fixed reply to call 911 or the office plus an urgent staff task; everything else is classified.
- Route reply (Switch) sends each reply down the right path.
- Postgres: record opt-out updates the consent table, so the reminder sender skips the number from then on.
- Claude: classify reply (HTTP Request) returns intent, confidence, a clinical concern flag and any preferred times as strict JSON, at low effort.
- Parse intent and decide (Code) handles
refusal,max_tokensand API errors. Plain-words opt-out requests are recorded as opt-outs. Clinical mentions and low confidence go to staff. - Scheduling system: apply action (HTTP Request) posts confirm, cancel or reschedule to your scheduling webhook, and Compose reply writes a short confirmation or up to three open slots.
- Twilio: send reply texts the patient. Postgres: add to staff queue collects every reply that needs a person, including failed sends.
Before you import
- Self-hosted n8n on HIPAA-eligible infrastructure, a Twilio account covered by a BAA (Twilio signs BAAs for Security and Enterprise Edition accounts) and registered for A2P 10DLC, and a BAA-covered arrangement for the model API.
- A Postgres database with
sms_consent,appointmentsandstaff_queuetables, kept in sync with your EHR or scheduling system. - A scheduling endpoint that accepts
{ appointmentId, action, preferredTimes }. DrChrono and Acuity have APIs; Epic and athenahealth usually need partner or customer-specific approval first.
Setup
- Create the three tables listed in the sticky note, with phone numbers in E.164.
- Set your Twilio number’s incoming message webhook to the production URL.
- Review
URGENT_PHRASESwith a clinician and setPRACTICE_TZin Compose reply. - Replace
REPLACE_WITH_SCHEDULING_WEBHOOK_URL,REPLACE_WITH_TWILIO_NUMBERandREPLACE_WITH_PRACTICE_NAME. - Write reminders that ask for C to confirm and R to reschedule. CANCEL is one of Twilio’s default opt-out keywords and YES is a Twilio opt-in keyword, so both trigger Twilio’s own handling.
Test it
From a test phone with a consent row, reply C, R with a preferred day, a question, and STOP. Check the scheduling calls, the replies and the consent table. Repeat from a number without a consent row and confirm nothing is texted and a staff row appears instead.
Make it production-ready
- Under the TCPA, automated texts need the patient’s prior consent, and FCC rules require honoring an opt-out made by any reasonable means, including a plain-words reply, within 10 business days. Have counsel review consent language and message content. This template is not legal advice.
- Validate Twilio’s request signature before trusting the webhook.
- Keep clinical details out of every message, and add an error workflow that alerts staff if the workflow stops.
- Slot picks (a reply of 1, 2 or 3) go to staff in this starter; add a step to book them once write-back is reliable.
claude-haiku-5-5is a cheaper option for this short, high-volume classification.
Read the full guide at How to reduce no-shows with AI appointment reminders, or talk to us about connecting your EHR.