CORTEXFLOW · FREE FOREVER

Automation

Food Delivery Order Automator — Webhook Intake, Restaurant, Driver & Customer Updates

↓ Download workflow JSON

Import in n8n: Workflows → ⋯ → Import from file, then add your credentials. Free download with a free account.

How it works

One webhook endpoint runs your whole food-delivery order pipeline — no duplicate notifications, even when dozens of orders land in the same minute:

  1. STEP 1 — Webhook intake + instant ack — your food-delivery app POSTs an order event (order.created, restaurant.confirmed, driver.assigned, driver.picked_up, order.delivered, payment.failed, order.cancelled) to the Webhook — Order Events node. Normalize Order Event flattens the payload into one clean shape, then Respond — Order Received answers {"received": true, ...} immediately, so the sender never times out while the rest of the workflow runs.
  2. STEP 2 — Idempotency dedupe — Read Logged Events pulls every row from the Orders sheet and Check Duplicate Event looks for a matching order_id + event_type key. If the event was already seen, the IF — Duplicate Event? node routes it to Build Duplicate Notice and nothing is sent twice. New events get a row appended by Log Event — Status NEW — that row is itself the in-flight reservation, so a retry arriving mid-processing is caught as a duplicate.
  3. STEP 3 — Route by event type — Switch — Route by Event Type sends each event to its own branch. Unknown event types fall through to the fallback output and are logged only.
  4. STEP 4 — Event branches — each branch does its job and updates the sheet status before merging:
    • order.created → HTTP — Notify Restaurant posts the order to the restaurant endpoint.
    • restaurant.confirmed → sheet flips to CONFIRMED, then HTTP — Dispatch to Drivers notifies available delivery partners — the first driver to accept claims the delivery (claim window from claim_timeout_minutes).
    • driver.assigned → sheet flips to DISPATCHED, then AI Agent — Draft Customer Update writes a short, warm customer message via a Structured Output Parser (gpt-4o-mini), and HTTP — Send Customer Update delivers it.
    • driver.picked_up → sheet flips to OUT_FOR_DELIVERY. order.delivered → sheet flips to DELIVERED.
    • payment.failed → sheet flips to PAYMENT_FAILED, HTTP — Hold Prep at Restaurant tells the kitchen not to start cooking, and Build Retry Payment Message + HTTP — Send Retry Payment Message ask the customer to retry payment.
    • order.cancelled → sheet flips to CANCELLED with Refund Review flagged YES, HTTP — Release Driver frees the driver, and the restaurant and customer are both notified.
  5. STEP 5 — One Telegram summary — all branches merge in Merge — Combine Branches, Build Order Summary composes a single message (order, event, outcome, and the AI-drafted customer message when there is one), and Telegram — Send Order Update sends it to you.

Status flow in Sheets: NEW → CONFIRMED → DISPATCHED → OUT_FOR_DELIVERY → DELIVERED (plus PAYMENT_FAILED and CANCELLED)

Set up steps

You’ll need:

  • n8n (self-hosted or cloud)
  • A food-delivery app or backend that can POST order events as JSON webhooks — any platform works; the webhook path is food-delivery-order (see the n8n Webhook node docs for the production URL)
  • An OpenAI API key — platform.openai.com → API keys
  • Google Sheets OAuth2 credentials — n8n Credentials → Google Sheets OAuth2
  • A Telegram bot — message @BotFather, send /newbot, copy the token; get your chat ID from @userinfobot
  • Restaurant / driver / customer notify endpoints — your own backend, or a messaging provider such as the WhatsApp Business API (the workflow posts plain JSON, so any HTTP endpoint works)

Steps:

  1. Import the workflow — in n8n, Workflows → Import from File → select food-delivery-order-automator.json.
  2. CONFIG — Order Intake — open the Set node and check claim_timeout_minutes (5 by default — how long drivers have to accept before the dispatch is re-offered) and default_currency.
  3. CONFIG — Google Sheets — create a Google Sheet with a tab named Orders and headers: Order ID | Dedupe Key | Event Type | Customer Name | Restaurant | Items | Total | Payment Status | Driver | Status | Refund Review | Timestamp | Customer Message. Paste the spreadsheet ID into spreadsheet_id, then select your Google Sheets credential and the sheet in Read Logged Events, Log Event — Status NEW, and all seven Update Sheet — Status … nodes.
  4. CONFIG — Restaurant & Dispatch — paste your three endpoint URLs (restaurant_endpoint, driver_dispatch_endpoint, customer_notify_endpoint) and your payment provider name. These are the only places your backend URLs live — no other node hardcodes them.
  5. AI customer updates — select your OpenAI credential in OpenAI Chat Model — Customer Updates (model is gpt-4o-mini). The parser schema (message_text, eta_minutes, tone) is already set in Structured Output Parser — Customer Message; adjust the agent’s system message if you want a different tone.
  6. CONFIG — Notifications — paste your Telegram chat ID, select your Telegram credential in Telegram — Send Order Update, then activate the workflow and point your app at the webhook production URL.
  7. Test it — POST a sample order.created event (see the example payload below) and watch the row appear in Sheets with status NEW, then POST the same event again and confirm the second one is skipped as a duplicate.

Example webhook payload:

{
  "order_id": "ORD-1042",
  "event_type": "order.created",
  "customer_name": "Priya Sharma",
  "customer_phone": "+919999999999",
  "restaurant_id": "rest_88",
  "restaurant_name": "Spice Route Kitchen",
  "items": [{ "name": "Butter Chicken", "qty": 2 }, { "name": "Naan", "qty": 4 }],
  "total": 24.5,
  "currency": "USD",
  "payment_status": "paid"
}

Customize it

  • Real restaurant POS — point restaurant_endpoint at your POS or kitchen-display-system webhook instead of a generic endpoint; the payload already carries order_id, items, and total.
  • SMS instead of app push — swap the customer_notify_endpoint for a Twilio or Vonage SMS endpoint; the JSON body stays the same shape.
  • Re-dispatch on timeout — if no driver claims within claim_timeout_minutes, add a Wait node after HTTP — Dispatch to Drivers and re-POST the dispatch to a wider radius.
  • Refund automation — the CANCELLED branch flags Refund Review: YES for a human check; wire your payment provider’s refund API into that branch once you trust the flow.
  • Delivery-time SLA alerts — add a scheduled sweep over the Orders sheet: any row stuck in DISPATCHED for over 30 minutes gets a Telegram alert.
  • More events — the Switch already handles driver.picked_up and order.delivered; add a driver.arriving output the same way if your app emits it.
  • Cheaper AI — gpt-4o-mini is already the default; customer messages are short, so cost per order is a fraction of a cent.

Workflow nodes

This workflow is built from 35 nodes. Here's what each one does:

#NodeTypeWhat it does
1 Webhook — Order Events Webhook Entry point — receives incoming HTTP requests that trigger the workflow.
2 CONFIG — Order Intake Set Holds editable configuration values — fill in your own settings here before activating.
3 Normalize Order Event Code Runs custom JavaScript to transform, filter, or compute data between steps.
4 Respond — Order Received Respond to Webhook Sends the HTTP response back to whoever called the webhook.
5 CONFIG — Google Sheets Set Holds editable configuration values — fill in your own settings here before activating.
6 Read Logged Events Google Sheets Reads from or writes to a Google Sheet — this workflow's log and state store.
7 Check Duplicate Event Code Runs custom JavaScript to transform, filter, or compute data between steps.
8 IF — Duplicate Event? IF Splits the flow into branches based on a condition.
9 Build Duplicate Notice Code Runs custom JavaScript to transform, filter, or compute data between steps.
10 Log Event — Status NEW Google Sheets Reads from or writes to a Google Sheet — this workflow's log and state store.
11 Switch — Route by Event Type Switch Routes items to one of several outputs based on rules.
12 CONFIG — Restaurant & Dispatch Set Holds editable configuration values — fill in your own settings here before activating.
13 HTTP — Notify Restaurant HTTP Request Calls an external API or webhook endpoint.
14 Update Sheet — Status CONFIRMED Google Sheets Reads from or writes to a Google Sheet — this workflow's log and state store.
15 HTTP — Dispatch to Drivers HTTP Request Calls an external API or webhook endpoint.
16 Update Sheet — Status DISPATCHED Google Sheets Reads from or writes to a Google Sheet — this workflow's log and state store.
17 AI Agent — Draft Customer Update AI Agent The AI brain — reasons over the task and calls tools to get it done.
18 OpenAI Chat Model — Customer Updates OpenAI Chat Model The language model powering the AI agent.
19 Structured Output Parser — Customer Message Structured Output Parser Forces the AI to return clean, structured JSON instead of free text.
20 HTTP — Send Customer Update HTTP Request Calls an external API or webhook endpoint.
21 Update Sheet — Status OUT_FOR_DELIVERY Google Sheets Reads from or writes to a Google Sheet — this workflow's log and state store.
22 Update Sheet — Status DELIVERED Google Sheets Reads from or writes to a Google Sheet — this workflow's log and state store.
23 Update Sheet — Status PAYMENT_FAILED Google Sheets Reads from or writes to a Google Sheet — this workflow's log and state store.
24 HTTP — Hold Prep at Restaurant HTTP Request Calls an external API or webhook endpoint.
25 Build Retry Payment Message Code Runs custom JavaScript to transform, filter, or compute data between steps.
26 HTTP — Send Retry Payment Message HTTP Request Calls an external API or webhook endpoint.
27 Update Sheet — Status CANCELLED Google Sheets Reads from or writes to a Google Sheet — this workflow's log and state store.
28 HTTP — Release Driver HTTP Request Calls an external API or webhook endpoint.
29 HTTP — Notify Restaurant — Cancelled HTTP Request Calls an external API or webhook endpoint.
30 HTTP — Notify Customer — Cancelled HTTP Request Calls an external API or webhook endpoint.
31 Build Unknown Event Note Code Runs custom JavaScript to transform, filter, or compute data between steps.
32 Merge — Combine Branches Merge Combines the outputs of two or more branches back into one flow.
33 Build Order Summary Code Runs custom JavaScript to transform, filter, or compute data between steps.
34 CONFIG — Notifications Set Holds editable configuration values — fill in your own settings here before activating.
35 Telegram — Send Order Update Telegram Sends you a Telegram message or alert.

Setup instructions

1. Add your credentials

In n8n go to Credentials → New, create each credential below, then open the named node and select it:

NodeCredential to add
Read Logged Events Google Sheets OAuth2
Log Event — Status NEW Google Sheets OAuth2
Update Sheet — Status CONFIRMED Google Sheets OAuth2
Update Sheet — Status DISPATCHED Google Sheets OAuth2
OpenAI Chat Model — Customer Updates OpenAI API
Update Sheet — Status OUT_FOR_DELIVERY Google Sheets OAuth2
Update Sheet — Status DELIVERED Google Sheets OAuth2
Update Sheet — Status PAYMENT_FAILED Google Sheets OAuth2
Update Sheet — Status CANCELLED Google Sheets OAuth2
Telegram — Send Order Update Telegram Bot API

2. Fill in your config values

Open the config node listed below and replace each placeholder with your own value before activating the workflow:

NodeFieldWhat to paste
CONFIG — Google Sheets spreadsheet_id PASTE_YOUR_SPREADSHEET_ID
Your spreadsheet id
CONFIG — Restaurant & Dispatch restaurant_endpoint PASTE_YOUR_RESTAURANT_WEBHOOK_URL
Your restaurant webhook url
CONFIG — Restaurant & Dispatch driver_dispatch_endpoint PASTE_YOUR_DRIVER_DISPATCH_URL
Your driver dispatch url
CONFIG — Restaurant & Dispatch customer_notify_endpoint PASTE_YOUR_CUSTOMER_NOTIFY_URL
Your customer notify url
CONFIG — Restaurant & Dispatch payment_provider PASTE_YOUR_PAYMENT_PROVIDER
Your payment provider
CONFIG — Notifications telegram_chat_id PASTE_YOUR_TELEGRAM_CHAT_ID
Your telegram chat id

How this workflow starts

  • Webhook: Listens on path /food-delivery-order — copy the production URL from the node after activating the workflow.

← All templates