Back to Templates

Confirm restaurant orders by phone with Supabase, Claude and Twilio

Created by

Created by: Aumadi || aumaditech
Aumadi

Last update

Last update 2 days ago

Categories

Share


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 order_call_logs 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 order_call_logs.
  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 order_call_logs 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 order_call_logs table with a unique constraint on order_id, and ensure the workflow can read notifications, orders, order_items, restaurants, and customers.
  3. Replace YOUR_PROJECT.supabase.co, YOUR_TWILIO_ACCOUNT_SID, YOUR_TWILIO_PHONE_NUMBER, YOUR_N8N_TUNNEL_URL, 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://YOUR_N8N_TUNNEL_URL/webhook/order-confirmation-call, and ensure the Twilio <Play> and StatusCallback URLs are publicly reachable.