Confirm restaurant orders by phone with Supabase, Claude and Twilio
Quick Overview This workflow triggers from a Supabase Database Webhook when a new order is inserted, generates a short order-confirmation script with Anthropic Claude, calls the customer via Twilio, and streams live v...
Template notes
Quick Overview This workflow triggers from a Supabase Database Webhook when a new order is inserted, generates a short order-confirmation script with Anthropic Claude, calls the customer via Twilio, and streams live voice audio generated by ElevenLabs back to Twilio without storing an audio file.
How it works 1. Receives a webhook request from Supabase for a new row inserted in the notifications or orders table and extracts the orderId. 2. Skips processing if the payload is not a new order (or has no order id), and otherwise inserts a row into Supabase ordercalllogs to claim the order and prevent duplicate calls. 3. Fetches the order, restaurant, items, and customer language from Supabase and prepares a call context including a normalized E.164 phone number. 4. Sends the call context to Anthropic Claude to generate a short confirmation script and saves the script plus call metadata back to ordercalllogs. 5. Places an outbound call with Twilio that instructs Twilio to play audio from an n8n webhook URL and returns a JSON response indicating the call was initiated. 6. When Twilio requests the audio URL, the workflow loads the saved script from Supabase, generates an MP3 on the fly with ElevenLabs Text-to-Speech, and streams the binary audio response directly back to Twilio. 7. When Twilio posts the final call status callback, the workflow maps the outcome and updates the matching ordercalllogs row in Supabase with the final status, pickup flag, and Call SID.
Setup 1. Create n8n credentials for Supabase API (project URL as host and a service role key), Anthropic API (header auth x-api-key), ElevenLabs (header auth xi-api-key), and Twilio (basic auth using Account SID and Auth Token). 2. In Supabase, create the ordercalllogs table with a unique constraint on orderid, and ensure the workflow can read notifications, orders, orderitems, restaurants, and customers. 3. Replace YOURPROJECT.supabase.co, YOURTWILIOACCOUNTSID, YOURTWILIOPHONENUMBER, YOURN8NTUNNELURL, and the ElevenLabs voice ID in the ElevenLabs Text-to-Speech request URL. 4. Configure a Supabase Database Webhook on notifications (or orders) for the Insert event to POST to https://YOURN8NTUNNELURL/webhook/order-confirmation-call, and ensure the Twilio <Play and StatusCallback URLs are publicly reachable.