Quick overview
This workflow uses WhatsApp Business Cloud, OpenAI, Supabase, and PostgreSQL to let patients check lab report status or receive a ready report PDF in English, Urdu, or Roman Urdu, while enforcing access control by matching the sender’s WhatsApp number to an authorized number stored with each report.
How it works
- Triggers when a new WhatsApp text message is received and ignores non-text or invalid messages.
- Loads the sender’s recent session state from Supabase and uses OpenAI to classify intent (status check, send PDF, or general query), extract any Report ID or full patient name, and detect the reply language.
- Validates and normalizes the identifier (Report ID or full patient name), optionally reusing a recently verified report context for short follow-ups, then looks up matching report records in Supabase.
- Applies access control by verifying the incoming WhatsApp number matches the report’s stored authorized_whatsapp value, and routes denied or ambiguous/missing-identifier cases to a clarification reply.
- For authorized status checks, replies on WhatsApp with “ready” or “pending” messaging based on the report_status field.
- For authorized PDF requests with a ready report and a PDF URL, validates the PDF host, downloads the PDF over HTTPS, and sends it back to the same WhatsApp number as a document.
- For general questions, uses OpenAI with PostgreSQL chat memory to draft a short WhatsApp reply in the user’s language.
Setup
- Connect credentials for WhatsApp Trigger/WhatsApp Business Cloud, OpenAI, Supabase, and PostgreSQL (and ensure Supabase and PostgreSQL point to the same database/schema used by the workflow).
- Create the required tables in your database (lab_reports, patient_session_state, and the PostgreSQL chat memory tables) and ensure lab staff populate authorized_whatsapp for each report in international digits-only format.
- Replace REPLACE_WITH_WHATSAPP_PHONE_NUMBER_ID in both WhatsApp send steps with your WhatsApp Phone Number ID.
- Set REPLACE_WITH_REPORT_STORAGE_HOST in the PDF validation step to your exact HTTPS storage hostname and ensure report_pdf_url values are short-lived direct HTTPS links with no redirects.
Requirements
- n8n, WhatsApp Business Cloud, OpenAI, Supabase and PostgreSQL credentials, configured report/session tables, registered patient WhatsApp numbers and private HTTPS report PDFs.
Customization
- Customize lab branding, AI models, reply languages, message wording, report-ID format, database mappings, session expiry and trusted PDF storage host.
Additional info
Help patients check report status and receive ready PDFs directly on WhatsApp, reducing repetitive reception queries.
Supports English, Urdu and Roman Urdu, with a registered-number check before releasing report details.
Adapt the workflow to your laboratory’s database and test with sample records before handling real patient information.