An intelligent, production-ready WhatsApp AI Food Ordering & Customer Care assistant built with n8n, LangChain, Google Gemini, and Google Sheets.
This system transforms traditional manual restaurant telephone and messaging operations into a fully autonomous, 24/7 intelligent conversational ordering channel. Customers can browse dynamic menus, inquire about pricing, check stock availability, place real-time orders, and get instant answers to FAQs directly via WhatsApp.
- Overview & Architecture
- Key Features
- System Components & Node Breakdown
- Database & Spreadsheet Schema
- AI Agent Persona & Prompt Engineering
- End-to-End Conversation Scenarios
- Installation & Setup Guide
- Production Optimization & Best Practices
- File Structure
- Roadmap & Enhancements
- License & Authors
Modern food delivery demands immediate response times, accurate stock confirmation, and seamless order dispatching. This workflow eliminates human delay by positioning a LangChain AI Agent backed by Google Gemini at the center of your WhatsApp customer communication.
โโโโโโโโโโโโโโโโโโโ Webhook โโโโโโโโโโโโโโโโโโโโโโโโ
โ WhatsApp Client โ โโโโโโโโโโโโโโโโโโ> โ WhatsApp Trigger โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโฌโโโโโโโโโโโโ
โฒ โ Customer Message Payload
โ WhatsApp Message โผ
โโโโโโโโโโดโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ Send Message โ <โโโโโโโโโโโโโโโโโโ โ AI Agent โ
โโโโโโโโโโโโโโโโโโโ Agent Response โ (LangChain + Gemini) โ
โโโโโโโโโโโโฌโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ Tool: Get Inventory โ โ Tool: FAQ โ โ Tool: Post Order โ
โ (Google Sheets) โ โ (Google Sheets) โ โ (Google Sheets) โ
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโดโโโโโโโโโโโโ
โ Context Memory โ
โ (Buffer Window = 10) โ
โโโโโโโโโโโโโโโโโโโโโโโโ
flowchart TD
subgraph WhatsApp_Cloud ["WhatsApp / Meta Cloud"]
User(["Customer on WhatsApp"])
end
subgraph n8n_Core ["n8n Automation Engine"]
Trigger["WhatsApp Trigger (n8n-nodes-base.whatsAppTrigger)"]
Agent["AI Agent (@n8n/n8n-nodes-langchain.agent)"]
LLM["Google Gemini Model (@n8n/n8n-nodes-langchain.lmChatGoogleGemini)"]
Memory["Simple Memory Buffer (Session: wa_id | Window: 10)"]
ToolInventory["Tool: Get Inventory (Reads Inventory Sheet)"]
ToolFAQ["Tool: FAQ (Reads FAQ Sheet)"]
ToolOrder["Tool: Post order (Appends to orders Sheet)"]
Sender["Send message (n8n-nodes-base.whatsApp)"]
end
subgraph Google_Workspace ["Google Sheets Database: Fast Delivery system"]
SheetInv[("Sheet: Inventory (Items, Prices, Stock)")]
SheetFAQ[("Sheet: FAQ (Hours, Delivery, Policies)")]
SheetOrders[("Sheet: orders (Customer, Item, Qty, Status)")]
end
User -->|"1. Inbound WhatsApp Message"| Trigger
Trigger -->|"2. Pass Message & Sender ID"| Agent
Agent <-->|"3. LLM Reasoning"| LLM
Agent <-->|"4. Read/Write Conversation State"| Memory
Agent <-->|"5a. Query Stock & Prices"| ToolInventory
ToolInventory <--> SheetInv
Agent <-->|"5b. Query Policies & FAQs"| ToolFAQ
ToolFAQ <--> SheetFAQ
Agent -->|"5c. Commit Confirmed Order"| ToolOrder
ToolOrder --> SheetOrders
Agent -->|"6. Synthesize Output Message"| Sender
Sender -->|"7. Send Response via Cloud API"| User
| n8n Canvas Architecture | Google Sheets Live Order Logging |
|---|---|
![]() |
![]() |
| Visual representation of nodes, model, memory, tools, and trigger in n8n | Verified order commitments captured in real time in Google Sheets |
- 24/7 Zero-Latency Order Reception: Instant automated handling of customer messages on WhatsApp without human intervention.
- Conversational Memory Window: Utilizes a 10-message sliding window keyed to the customer's unique WhatsApp ID (
wa_id) to retain context across dialogue turns. - Live Inventory & Dynamic Bill Computation:
- Live query against restaurant inventory before order confirmation.
- Automatically calculates itemized totals and overall order balance (e.g.,
1x Chicken Biryani = Rs 350 -> 2 plates = Rs 700). - Gracefully declines out-of-stock items and suggests active alternatives.
- Instant Knowledge Base / FAQ Retrieval: Pulls answers directly from the
FAQsheet to answer opening hours, delivery radius, refund policies, and vegetarian offerings. - Automated Database Logging: Automatically structures and appends customer name, item name, quantity, timestamp, and status into the
orderssheet. - Native WhatsApp UI/UX Guidelines: Configured with strict prompt formatting rules (friendly food delivery app tone, concise formatting, single asterisks for emphasis, no confusing headers or markdown artifacts).
- Human Escalation Guardrails: Prevents destructive actions (such as automated order cancellation once confirmed), cleanly redirecting customers to the restaurant manager/owner.
| Node Name | Node Type | Version | Role & Configuration |
|---|---|---|---|
| WhatsApp Trigger | n8n-nodes-base.whatsAppTrigger |
1.0 |
Listens for incoming WhatsApp webhook events (messages). Captures customer payload, message text ($json.messages[0].text.body), and contact metadata ($json.contacts[0].wa_id). |
| AI Agent | @n8n/n8n-nodes-langchain.agent |
2.2 |
Core orchestration agent running LangChain. Evaluates customer intent, maintains persona guidelines, calls appropriate tools, and generates user replies. |
| Google Gemini Chat Model | @n8n/n8n-nodes-langchain.lmChatGoogleGemini |
1.0 |
Generative language model (Google Gemini PaLM API) providing context comprehension, reasoning, and tool selection. |
| Simple Memory | @n8n/n8n-nodes-langchain.memoryBufferWindow |
1.3 |
Sliding context window memory (length = 10) using customKey = {{ $json.contacts[0].wa_id }} to maintain distinct conversation threads per customer. |
| Get Inventory | n8n-nodes-base.googleSheetsTool |
4.7 |
Reads the Inventory tab (gid: 898910044) in the Google Spreadsheet to inspect real-time pricing and stock counts. |
| FAQ | n8n-nodes-base.googleSheetsTool |
4.7 |
Reads the FAQ tab (gid: 678432777) to deliver policy, delivery radius, payment methods, and hours information. |
| Post order | n8n-nodes-base.googleSheetsTool |
4.7 |
Appends a row to the orders tab (gid: 257576541). Maps fields dynamically using $fromAI() for CUSTOMER_NAME, FOOD_ITEM, QUANTITY_ORDER, STATUS, and $now for timestamping. |
| Send message | n8n-nodes-base.whatsApp |
1.0 |
Sends outbound WhatsApp text message via Meta Cloud API using the synthesized response {{ $json.output }}. |
The application uses Google Sheets (Fast Delivery system) as its operational datastore, mirrored locally in fast_food_menu.xlsx.
Tracks menu items, live prices in PKR, availability flag, and stock quantity.
| Column Header | Data Type | Example Value | Description |
|---|---|---|---|
Fast Food Item |
String | Burger, Pizza (Slice), Shawarma |
Name of the food item |
Price_PKR |
Integer / Decimal | 350, 1200, 600 |
Price per single unit in PKR |
STATUS |
String | Available / out of stock |
Stock availability indicator |
QUANTITY |
Integer | 10, 20, 0 |
Number of servings currently available |
| Item | Price (PKR) | Status | Stock Quantity |
|---|---|---|---|
| ๐ Burger | Rs 350 | Available | 10 |
| ๐ French Fries | Rs 1400 | Available | 12 |
| ๐ Pizza (Slice) | Rs 1200 | Available | 20 |
| ๐ฅช Sandwich | Rs 300 | Available | 20 |
| ๐ฏ Shawarma | Rs 600 | Available | 20 |
| ๐ Fried Chicken (Piece) | Rs 300 | Available | 30 |
| ๐ชฃ Chicken Meal (Bucket) | Rs 1500 | Available | 15 |
| ๐ chicken_wings | Rs 450 | Available | 13 |
| ๐ pasta | Rs 300 | Available | 14 |
| ๐ฅ Boil_egg | Rs 50 | Available | 100 |
| ๐ต soap_cup | Rs 100 | Available | 70 |
| ๐ฆ Extra_things | โ | out of stock | 0 |
Captures incoming orders logged by the Post order tool.
| Column Header | Tool Parameter Mapping | Sample Data |
|---|---|---|
CUSTOMER NAME |
{{ $fromAI('CUSTOMER_NAME', '', 'string') }} |
Asim imam |
FOOD ITEM |
{{ $fromAI('FOOD_ITEM', '', 'string') }} |
Pizza (Slice) |
QUANTITY ORDER |
{{ $fromAI('QUANTITY_ORDER', '', 'string') }} |
2 |
ORDER DATE |
{"datetime":"{{ $now.format('YYYY-MM-DD HH:mm:ss') }}"} |
2025-10-02 23:37:15 |
STATUS |
{{ $fromAI('STATUS', '', 'string') }} |
Confirmed |
Provides static restaurant domain knowledge for the AI Agent.
| Question | Answer |
|---|---|
| What are your opening hours? | We are open daily from 11:00 AM to 10:00 PM. |
| Do you offer home delivery? | Yes, we provide home delivery within 5 km. |
| What is your refund policy? | Refunds are only available for canceled orders before preparation starts. |
| Do you have vegetarian options? | Yes, we serve a variety of vegetarian thalis and meals. |
| How can I place an order? | You can order via phone, WhatsApp, or our website. |
| Do you accept online payments? | Yes, we accept UPI, cards, and cash on delivery. |
The system prompt embeds precise operational logic into the Gemini model:
You are a smart food ordering assistant for "HK Restaurant".
Rules:
1. When a user sends their first message (like hi, hello), reply with:
"Welcome to HK Restaurant ๐ด
How can I help you today?
* ๐ Place an order
* โ FAQ / Information
* ๐ฆ Check order / stock"
๐ Keep the tone friendly like a food delivery app, not like a product e-commerce site
2. If user wants *order*:
* Ask step by step: name, food item, quantity
* Show the *unit price* and calculate *total price* before confirmation
Example: "1x Chicken Biryani = Rs 350 โ 2 plates = Rs 700"
* Check Inventory sheet before confirming
* If available โ "Your order for *Chicken Biryani* (x2 = Rs 700) is confirmed โ
"
* If not available โ "Sorry, *Chicken Biryani* is out of stock โ. Available options: [list items with prices]"
* Only confirmed orders go into the Orders sheet
* In Orders sheet always include:
* Status = Confirmed / Rejected
* Description = "Order accepted (item available)" OR "Order rejected (out of stock)"
* Item, Quantity, Unit Price, Total Price
3. If user asks about *price of an item*:
* Look up in Inventory sheet
* Reply short with price and availability
Example: "๐ Chicken Karahi = Rs 1200 (Available 5 plates)"
4. If user wants *FAQ*:
* Answer short and clear (delivery time, payment method, restaurant hours)
5. If user wants *check order* or *check stock*:
* Ask for food name or order id
* Look up in Google Sheets (Orders / Inventory)
* If checking order โ reply with status + total price (if confirmed)
* If checking stock โ reply with available quantity + price of that food
* If requested, also list all *available* food items with prices and quantity
6. If user wants *cancel order*:
* Reply politely:
"Sorry ๐ I cannot cancel orders directly.
Please call the restaurant owner first and inform them.
Owner Contact: +92 3005880486"
7. Always reply in short text like a normal WhatsApp chat
* Do not use **bold** or long paragraphs
* Use *stars* only for highlighting words
* Keep tone friendly, polite, and food-delivery app style
Customer: Hello!
AI Agent: Welcome to HK Restaurant ๐ด
How can I help you today?
* ๐ Place an order
* โ FAQ / Information
* ๐ฆ Check order / stock
Customer: I want to order 2 Pizza slices.
AI Agent: Sure! May I have your name, please?
Customer: Asim Imam
AI Agent: 1x Pizza (Slice) = Rs 1200 โ 2 slices = Rs 2400.
Your order for *Pizza (Slice)* (x2 = Rs 2400) is confirmed โ
We're preparing your food now!
(Order logged immediately in the orders Google Sheet)
Customer: Can I get Extra_things with my order?
AI Agent: [Queries 'Get Inventory' tool]
Sorry, *Extra_things* is out of stock โ.
Available options:
* Burger (Rs 350)
* French Fries (Rs 1400)
* Shawarma (Rs 600)
* Fried Chicken (Rs 300)
Customer: How far do you deliver and what are your hours?
AI Agent: [Queries 'FAQ' tool]
We deliver within a 5 km radius! ๐ต
Our opening hours are daily from 11:00 AM to 10:00 PM.
Customer: Please cancel my order.
AI Agent: Sorry ๐ I cannot cancel orders directly.
Please call the restaurant owner first and inform them.
Owner Contact: +92 3005880486
- An active n8n instance (n8n Cloud or self-hosted via Docker / npm).
- A Meta for Developers account with a configured WhatsApp Cloud API app.
- A Google Cloud Console account with Google Sheets API enabled and OAuth2 credentials configured.
- A Google Gemini API Key (PaLM / Gemini API via Google AI Studio).
- Download or clone this repository:
git clone git@github.com:Asim-imam-ai/N8N-PROJECT-HK-RESTURANT.git
- Open your n8n workspace dashboard.
- Click on Workflows โ Import from File...
- Select
HK_Resturant (1).json. - The workflow canvas with all 8 interconnected nodes will load automatically.
- Open Google Drive and upload
fast_food_menu.xlsx, or create a new Google Spreadsheet titledFast Delivery system. - Ensure the spreadsheet contains three sheets with exact names:
InventoryordersFAQ
- Copy the spreadsheet URL and extract the Document ID from the link:
https://docs.google.com/spreadsheets/d/<DOCUMENT_ID>/edit - In n8n, update the Document ID in each Google Sheets tool:
- Get Inventory: Select your spreadsheet and choose sheet
Inventory. - FAQ: Select your spreadsheet and choose sheet
FAQ. - Post order: Select your spreadsheet, choose sheet
orders, and ensure column mappings match.
- Get Inventory: Select your spreadsheet and choose sheet
- Go to the Meta Developer Portal.
- Create or select your WhatsApp Business App.
- In WhatsApp โ Configuration:
- Set Callback URL to the production webhook URL provided by the n8n
WhatsApp Triggernode:https://<your-n8n-instance>/webhook/6e1a6177-460b-4fbd-bb69-46c836cf6543/webhook - Enter your chosen Verify Token.
- Under Webhook fields, subscribe to
messages.
- Set Callback URL to the production webhook URL provided by the n8n
- Note your Phone Number ID (e.g.,
838440309346424) and temporary or permanent System User Access Token.
Configure the following credentials in n8n:
- WhatsApp Trigger API (
whatsAppTriggerApi):- Type: WhatsApp OAuth2 or Webhook configuration.
- WhatsApp API (
whatsAppApi):- Access Token from Meta Developer Portal.
- Google Gemini (PaLM) API (
googlePalmApi):- API key from Google AI Studio.
- Google Sheets OAuth2 API (
googleSheetsOAuth2Api):- Connect using your Google account with access to the
Fast Delivery systemsheet.
- Connect using your Google account with access to the
- Turn on the Active toggle switch in the upper right corner of the n8n canvas.
- Send a WhatsApp message (e.g.,
"Hi") to your test WhatsApp Business number. - Observe the execution in n8n under the Executions tab.
- Verify that the agent replies on WhatsApp and creates records in your Google Sheet upon order confirmation.
In test/development workflows, the Send message node may be set to a static recipient phone number. For multi-user production environments, update the Recipient Phone Number field in the Send message node to dynamic resolution:
={{ $('WhatsApp Trigger').item.json.contacts[0].wa_id }}or
={{ $json.contacts[0].wa_id }}The Post order node default expression formats the timestamp as:
{"datetime":"{{ $now.format('YYYY-MM-DD HH:mm:ss') }}"}For a clean date string in spreadsheet cells, simplify the expression to:
={{ $now.format('YYYY-MM-DD HH:mm:ss') }}To prevent overselling high-demand items, add an automated step after Post order to decrement QUANTITY in the Inventory sheet:
0, set STATUS to "out of stock".
- Always verify the HMAC-SHA256 signature in production headers using your Meta App Secret.
- Implement rate limiting on the webhook endpoint to protect against spam attacks.
N8N-PROJECT-HK-RESTURANT/
โโโ HK_Resturant (1).json # Complete exportable n8n workflow definition
โโโ fast_food_menu.xlsx # Local Excel datastore (Inventory, orders, FAQ)
โโโ Screenshot (296).png # Canvas architecture screenshot in n8n Cloud
โโโ Screenshot (297).png # Live orders capture in Google Sheets
โโโ Screenshot (298).png # Orders verification log in Google Sheets
โโโ Screenshot (299).png # Workflow editor & execution state screenshot
โโโ README.md # Project documentation and setup guide
- Multi-Language Support: Natural dialogue support in Urdu, Roman Urdu, and Arabic.
- Automated Payment Gateway: Integration with Stripe, JazzCash, or EasyPaisa checkout links.
- POS / Kitchen Display Sync: Webhook dispatches to kitchen thermal printers or POS software.
- Rider & Delivery Tracking: Live rider location sharing via WhatsApp Location API.
- Customer Feedback Loop: Automated follow-up message 45 minutes post-delivery requesting food ratings.
Distributed under the MIT License. See LICENSE for details.
- Asim Imam (@Asim-imam-ai)
- Email:
asimimam.programmer@gmail.com
Developed with โค๏ธ using n8n, LangChain, Google Gemini, and Meta WhatsApp Cloud API.



