Voltar para modelos
MODELO DE WORKFLOW
WhatsApp AI Agent For Restaurants (Delivery) | Operasyon için n8n Otomasyon İş Akışı Şablonu (HTTP)
n8n için hazır otomasyon şablonu: WhatsApp AI Agent For Restaurants (Delivery). 42 düğüm. Entegrasyonlar: HTTP. JSON'u kopyalayıp n8n'e içe aktarın.
42 nósWhatsapp_AI_Agent_For_Restaurants_Delivery-workflow.json
{"id": "W8cNJXxPgBStJGT9","meta": {"instanceId": "1c262716821ea2650dac3177f9ad82ec17728569a6c7be365abb2776d5d0867d"},"name": "WhatsApp AI Agent for Restaurants (Delivery)","tags": [],"nodes": [{"id": "fbaea2b1-8a98-4114-8243-1e10d08d7a4c","name": "OpenAI Chat Model2","type": "@n8n/n8n-nodes-langchain.lmChatOpenAi","position": [48,832],"parameters": {"model": {"__rl": true,"mode": "list","value": "gpt-4o","cachedResultName": "gpt-4o"},"options": {}},"credentials": {"openAiApi": {"id": "ZNNVcWV7IhlWKcvj","name": "OpenAi account Rodrigo"}},"typeVersion": 1.2},{"id": "6148e121-f043-438b-ab50-fdf6c09fbda1","name": "Postgres Chat Memory1","type": "@n8n/n8n-nodes-langchain.memoryPostgresChat","position": [208,816],"parameters": {"sessionKey": "={{ $('Message Received').item.json.messages[0].from }}","sessionIdType": "customKey","contextWindowLength": 300},"credentials": {"postgres": {"id": "cR2RyvCPoqUwfa30","name": "Postgres account Rodrigo con Supabase"}},"typeVersion": 1.3},{"id": "b0039654-d346-4e24-8236-3385b78862b4","name": "Wait","type": "n8n-nodes-base.wait","position": [848,560],"webhookId": "8dca9493-78df-4cd9-8ee4-89cfee72752b","parameters": {"amount": 0},"typeVersion": 1.1},{"id": "c083f637-1338-4511-bd58-2bd558c7adc1","name": "Google Maps","type": "n8n-nodes-base.httpRequest","position": [-1056,688],"parameters": {"url": "=https://maps.googleapis.com/maps/api/geocode/json?latlng={{ $json.messages[0].location.latitude }},{{ $json.messages[0].location.longitude }}&key=YOUR_APIKEY\n","options": {}},"typeVersion": 4.2},{"id": "e8b3b788-8703-4380-89ae-9d906c0950f9","name": "Code","type": "n8n-nodes-base.code","position": [1200,80],"parameters": {"jsCode": "// Get structured data from output\nconst data = $input.first().json.output;\n\n// Extract each field directly from JSON object\nconst customer = data.customer_name;\nconst orderType = data.order_type;\nconst refNumber = data.reference_number;\nconst paymentMethod = data.payment_method;\nconst address = data.address;\nconst latitude = data.latitude;\nconst longitude = data.longitude;\nconst shippingCost = data.shipping_cost;\nconst finalTotal = data.final_total;\n\n// Process product list\nconst orderText = data.products.map(product => {\n return `${product.name} – Bs ${product.price}`;\n}).join('\\n');\n\n// Create final message with desired format\nconst order_message = `🍝 *NEW ORDER -[RESTAURANT_NAME]* 🇮🇹\n👤 *Customer:* ${customer}\n📞 *Phone:* ${refNumber}\n🚀 *Type:* ${orderType}\n💳 *Payment:* ${paymentMethod}\n📍 *Location:* ${address}\n📍 *Latitude:* ${latitude}\n📍 *Longitude:* ${longitude}\n📋 *ORDER:*\n${orderText}\n🚚 *Shipping cost:* ${shippingCost} Bs\n🧾 *Total:* ${finalTotal}Bs\n💭 *Comments:*\n⏰ *Time:* ${new Date().toLocaleString('en-US', { timeZone: '[YOUR_TIMEZONE]' })}`;\n\n// Return result\nreturn {\n order_message: order_message\n};"},"typeVersion": 2},{"id": "112bbd41-8677-42cc-b37c-264b111e6b4a","name": "WhatsApp Business Cloud2","type": "n8n-nodes-base.whatsApp","position": [1216,1088],"webhookId": "53847e40-a8a0-43f4-a41c-e218c097ff0d","parameters": {"mediaPath": "useMedian8n","operation": "send","messageType": "image","phoneNumberId": "={{ $('Message Received').item.json.metadata.phone_number_id }}","additionalFields": {},"recipientPhoneNumber": "={{ $('Message Received').item.json.messages[0].from }}"},"credentials": {"whatsAppApi": {"id": "7rMPI0CcyqqjedhR","name": "WhatsApp account FASTA"}},"typeVersion": 1},{"id": "e3f68073-7d17-4996-ac03-7dfa83c5b743","name": "Download Image","type": "n8n-nodes-base.httpRequest","position": [-880,144],"parameters": {"url": "={{ $json.url }}","options": {},"authentication": "genericCredentialType","genericAuthType": "httpHeaderAuth"},"credentials": {"httpHeaderAuth": {"id": "PZefPgHGkREf4iN0","name": "Header Auth account WhatsApp FASTA"}},"typeVersion": 4.2},{"id": "1d392362-aea6-4ada-bbb1-8075fafea9d9","name": "Get Image Url","type": "n8n-nodes-base.whatsApp","position": [-1056,144],"webhookId": "7eb58296-2363-429c-abab-7f2e6c29ade2","parameters": {"resource": "media","operation": "mediaUrlGet","mediaGetId": "={{ $('Message Received').item.json.messages[0].image.id }}"},"credentials": {"whatsAppApi": {"id": "7rMPI0CcyqqjedhR","name": "WhatsApp account FASTA"}},"typeVersion": 1},{"id": "3ad70b86-ca31-4613-a1b5-799032ca3fff","name": "Image","type": "n8n-nodes-base.set","position": [-432,144],"parameters": {"options": {},"assignments": {"assignments": [{"id": "67552183-de2e-494a-878e-c2948e8cb6bb","name": "text","type": "string","value": "=Image description:\n{{ $json.content }}"}]}},"typeVersion": 3.4},{"id": "b8077628-7900-42b1-b579-d0fd6228c5a8","name": "Sticky Note","type": "n8n-nodes-base.stickyNote","position": [-1120,96],"parameters": {"color": 4,"width": 1060,"height": 220,"content": "## Recognize Image Type Receipts"},"typeVersion": 1},{"id": "2bcf817b-57ea-4ba6-9854-e18b65baebd5","name": "Sticky Note3","type": "n8n-nodes-base.stickyNote","position": [0,464],"parameters": {"width": 720,"height": 540,"content": "## Chat with customer about order\n"},"typeVersion": 1},{"id": "3d37a734-7f4d-48b9-bb24-c732c633baec","name": "Download Audio","type": "n8n-nodes-base.httpRequest","position": [-848,912],"parameters": {"url": "={{ $json.url }}","options": {},"authentication": "genericCredentialType","genericAuthType": "httpHeaderAuth"},"credentials": {"httpHeaderAuth": {"id": "PZefPgHGkREf4iN0","name": "Header Auth account WhatsApp FASTA"}},"typeVersion": 4.2},{"id": "0bc6800c-4eb0-4549-85a0-c466bbf35894","name": "Transcribe Audio","type": "@n8n/n8n-nodes-langchain.openAi","position": [-656,912],"parameters": {"options": {},"resource": "audio","operation": "transcribe"},"credentials": {"openAiApi": {"id": "ZNNVcWV7IhlWKcvj","name": "OpenAi account Rodrigo"}},"typeVersion": 1.8},{"id": "2e6216f3-cbd2-4897-bead-db7944280b7f","name": "Audio","type": "n8n-nodes-base.set","position": [-480,912],"parameters": {"options": {},"assignments": {"assignments": [{"id": "219577d5-b028-48fc-90be-980f4171ab68","name": "text","type": "string","value": "={{ $json.text }}"}]}},"typeVersion": 3.4},{"id": "d1400646-8429-4516-aed1-c99660f0daa7","name": "Get Audio Url","type": "n8n-nodes-base.whatsApp","position": [-1040,912],"webhookId": "761cfe95-c1e8-4a29-aac1-091e9241454d","parameters": {"resource": "media","operation": "mediaUrlGet","mediaGetId": "={{ $('Message Received').item.json.messages[0].audio.id }}"},"credentials": {"whatsAppApi": {"id": "4IdzQkn96wTOyXsv","name": "WhatsApp account Romar AI"}},"typeVersion": 1},{"id": "0ec520fa-5ee1-4115-ad65-b27e7dedf587","name": "Text","type": "n8n-nodes-base.set","position": [-704,560],"parameters": {"options": {},"assignments": {"assignments": [{"id": "c53cd9f9-77c1-4331-98ff-bfc9bdf95a3c","name": "text","type": "string","value": "={{ $('Message Received').item.json.messages[0].text.body }}"}]}},"typeVersion": 3.4},{"id": "4d1b23c4-14dd-4b4e-abf2-13196eca47bb","name": "Location","type": "n8n-nodes-base.set","position": [-896,688],"parameters": {"options": {},"assignments": {"assignments": [{"id": "f8d40eb6-8c0f-4dac-af88-7d00fdcb1035","name": "text","type": "string","value": "={{ $json.results[0].formatted_address }}"},{"id": "d72598e1-6769-4f19-aadc-9247dc7dd7c8","name": "latitude","type": "string","value": "={{ $json.results[0].navigation_points[0].location.latitude }}"},{"id": "ed97ff19-587c-4505-881a-0c9fe59385fc","name": "longitude","type": "string","value": "={{ $json.results[0].navigation_points[0].location.longitude }}"}]}},"typeVersion": 3.4},{"id": "b4e8d80a-a8d9-4512-a573-b34108d6cf7f","name": "Download File","type": "n8n-nodes-base.httpRequest","position": [-880,384],"parameters": {"url": "={{ $json.url }}","options": {},"authentication": "genericCredentialType","genericAuthType": "httpHeaderAuth"},"credentials": {"httpHeaderAuth": {"id": "PZefPgHGkREf4iN0","name": "Header Auth account WhatsApp FASTA"}},"typeVersion": 4.2},{"id": "89467936-6483-44d6-a04f-9a84366ab7dd","name": "Get File Url","type": "n8n-nodes-base.whatsApp","position": [-1056,384],"webhookId": "187156a6-aa4f-43ae-8dc8-cd4ad07b5a7c","parameters": {"resource": "media","operation": "mediaUrlGet","mediaGetId": "={{ $('Message Received').item.json.messages[0].document.id }}"},"credentials": {"whatsAppApi": {"id": "7rMPI0CcyqqjedhR","name": "WhatsApp account FASTA"}},"typeVersion": 1},{"id": "3b7af386-ed67-42d3-bad7-3317e1e54e15","name": "File","type": "n8n-nodes-base.set","position": [-336,384],"parameters": {"options": {},"assignments": {"assignments": [{"id": "67552183-de2e-494a-878e-c2948e8cb6bb","name": "text","type": "string","value": "={{ $json.candidates[0].content.parts[0].text }}"}]}},"typeVersion": 3.4},{"id": "b42a2e31-c7f6-4cdb-940d-2ce27a87cee0","name": "Sticky Note5","type": "n8n-nodes-base.stickyNote","position": [-1120,848],"parameters": {"color": 7,"width": 820,"height": 220,"content": "## Recognize voice messages"},"typeVersion": 1},{"id": "16e1c4bc-9d57-48f5-9eab-fef334a51725","name": "Sticky Note6","type": "n8n-nodes-base.stickyNote","position": [-1120,624],"parameters": {"color": 6,"width": 400,"height": 200,"content": "## Recognize customer location"},"typeVersion": 1},{"id": "dd93796f-12ef-452c-8e66-09e4d1365ee6","name": "Sticky Note7","type": "n8n-nodes-base.stickyNote","position": [-1120,336],"parameters": {"color": 3,"width": 1100,"height": 240,"content": "## Recognize PDF type receipts"},"typeVersion": 1},{"id": "f5707aa2-106e-4d2a-9802-261590f37b6b","name": "Sticky Note8","type": "n8n-nodes-base.stickyNote","disabled": true,"position": [0,0],"parameters": {"color": 5,"width": 672,"height": 440,"content": "## Analyze and confirm payment receipt"},"typeVersion": 1},{"id": "de6ec3de-43dd-478b-90fc-2faa0108a84b","name": "Forward receipt to Management","type": "n8n-nodes-base.whatsApp","position": [-128,400],"webhookId": "beef7d41-e69d-49f2-bbba-fd18367db97e","parameters": {"mediaId": "={{ $('Message Received').item.json.messages[0].document.id }}","mediaPath": "useMediaId","operation": "send","messageType": "document","mediaFilename": "={{ $('Message Received').item.json.messages[0].document.filename }}","phoneNumberId": "=Sender Phone Number","additionalFields": {},"recipientPhoneNumber": "=Recipient's Phone Number"},"credentials": {"whatsAppApi": {"id": "7rMPI0CcyqqjedhR","name": "WhatsApp account FASTA"}},"typeVersion": 1},{"id": "1114452a-c737-426f-99d9-4462dbabc6c7","name": "Response to Customer","type": "n8n-nodes-base.whatsApp","position": [1088,560],"webhookId": "5e54411e-1339-4e5a-990e-5dbc644c6384","parameters": {"textBody": "={{ $('AI Restaurant Agent').item.json.output }}","operation": "send","phoneNumberId": "=[PHONE_NUMBER]","additionalFields": {},"recipientPhoneNumber": "={{ $('Message Received').item.json.messages[0].from }}"},"credentials": {"whatsAppApi": {"id": "4IdzQkn96wTOyXsv","name": "WhatsApp account Romar AI"}},"typeVersion": 1},{"id": "36a3c898-0b2f-42da-b7e8-3b305d97500c","name": "Message Type","type": "n8n-nodes-base.switch","position": [-1312,512],"parameters": {"rules": {"values": [{"outputKey": "Image","conditions": {"options": {"version": 2,"leftValue": "","caseSensitive": true,"typeValidation": "strict"},"combinator": "and","conditions": [{"id": "202af928-a324-411a-bf15-68a349e7bf9e","operator": {"type": "object","operation": "exists","singleValue": true},"leftValue": "={{ $json.messages[0].image }}","rightValue": ""}]},"renameOutput": true},{"outputKey": "Document","conditions": {"options": {"version": 2,"leftValue": "","caseSensitive": true,"typeValidation": "strict"},"combinator": "and","conditions": [{"id": "c63299e9-6069-4bc6-afb9-7beebf6e3d69","operator": {"type": "object","operation": "exists","singleValue": true},"leftValue": "={{ $json.messages[0].document }}","rightValue": ""}]},"renameOutput": true},{"outputKey": "Text","conditions": {"options": {"version": 2,"leftValue": "","caseSensitive": true,"typeValidation": "strict"},"combinator": "and","conditions": [{"id": "08fd0c80-307e-4f45-b1de-35192ee4ec5e","operator": {"type": "string","operation": "exists","singleValue": true},"leftValue": "={{ $json.messages[0].text.body }}","rightValue": ""}]},"renameOutput": true},{"outputKey": "Location","conditions": {"options": {"version": 2,"leftValue": "","caseSensitive": true,"typeValidation": "strict"},"combinator": "and","conditions": [{"id": "c8092137-ea08-485c-8aaf-8e1702cc11cd","operator": {"type": "object","operation": "exists","singleValue": true},"leftValue": "={{ $json.messages[0].location }}","rightValue": ""}]},"renameOutput": true},{"outputKey": "Voice","conditions": {"options": {"version": 2,"leftValue": "","caseSensitive": true,"typeValidation": "strict"},"combinator": "and","conditions": [{"id": "b7b64446-f1ea-4622-990c-22f3999a8269","operator": {"type": "object","operation": "exists","singleValue": true},"leftValue": "={{ $json.messages[0].audio }}","rightValue": ""}]},"renameOutput": true}]},"options": {"fallbackOutput": "extra"}},"typeVersion": 3.2},{"id": "48697937-4684-4b79-a682-52e328b1f9b4","name": "Message Received","type": "n8n-nodes-base.whatsAppTrigger","position": [-1488,576],"webhookId": "01cd78e0-06f9-494f-ba9c-e90db36fb50c","parameters": {"options": {},"updates": ["messages"]},"credentials": {"whatsAppTriggerApi": {"id": "tGfxaBAq75XkQK8x","name": "WhatsApp OAuth account Romar AI"}},"typeVersion": 1},{"id": "2709f208-c4ff-4f76-81be-5055cd1e05fb","name": "Extract PDF Content Using Gemini Vision","type": "n8n-nodes-base.httpRequest","position": [-512,384],"parameters": {"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent\n","method": "POST","options": {},"jsonBody": "={\n \"contents\": [\n {\n \"parts\": [\n {\n \"text\": \"Extract The Contents Of This PDF\"\n },\n {\n \"inline_data\": {\n \"mime_type\": \"application/pdf\",\n \"data\": \"{{ $json.data }}\"\n }\n }\n ]\n }\n ]\n}\n","sendBody": true,"specifyBody": "json","authentication": "genericCredentialType","genericAuthType": "httpQueryAuth"},"credentials": {"httpQueryAuth": {"id": "e5NLkb1fnWvEF6QR","name": "Query Auth account Gemini"}},"typeVersion": 4.2},{"id": "67f01154-2e20-45c6-acba-b93cea33bdff","name": "Extract from File1","type": "n8n-nodes-base.extractFromFile","position": [-688,384],"parameters": {"options": {},"operation": "binaryToPropery"},"typeVersion": 1},{"id": "a1232ddf-c513-4ef9-8abe-0e9848d45ff1","name": "Postgres Chat Memory4","type": "@n8n/n8n-nodes-langchain.memoryPostgresChat","position": [272,304],"parameters": {"sessionKey": "={{ $('Message Received').item.json.messages[0].from }}","sessionIdType": "customKey","contextWindowLength": 300},"credentials": {"postgres": {"id": "cR2RyvCPoqUwfa30","name": "Postgres account Rodrigo con Supabase"}},"typeVersion": 1.3},{"id": "89043031-a27f-4e86-9dee-b58a0bcb8fa4","name": "OpenAI Chat Model6","type": "@n8n/n8n-nodes-langchain.lmChatOpenAi","position": [112,304],"parameters": {"model": {"__rl": true,"mode": "list","value": "o3-mini","cachedResultName": "o3-mini"},"options": {}},"credentials": {"openAiApi": {"id": "ZNNVcWV7IhlWKcvj","name": "OpenAi account Rodrigo"}},"typeVersion": 1.2},{"id": "4367ea5e-666b-4ef1-9ea4-4b4ae90d9799","name": "Message to Customer2","type": "n8n-nodes-base.whatsApp","position": [1536,384],"webhookId": "0f958239-0d67-4c53-b63f-83ef32e3ff9a","parameters": {"textBody": "={{ $json.output.customer_response }}{{ $json.output }}{{ $json.order_message }}","operation": "send","phoneNumberId": "={{ $('Message Received').item.json.metadata.phone_number_id }}","additionalFields": {},"recipientPhoneNumber": "={{ $('Message Received').item.json.messages[0].from }}"},"credentials": {"whatsAppApi": {"id": "7rMPI0CcyqqjedhR","name": "WhatsApp account FASTA"}},"typeVersion": 1},{"id": "aee465c1-b1ba-4a74-933c-bfb540ea5d71","name": "Message to cashier","type": "n8n-nodes-base.whatsApp","position": [1536,160],"webhookId": "b170d560-7216-4474-835a-b9626c60964b","parameters": {"textBody": "={{ $json.order_message }}{{ $json.output }}","operation": "send","phoneNumberId": "=[PHONE_NUMBER]","additionalFields": {},"recipientPhoneNumber": "[PHONE_NUMBER]"},"credentials": {"whatsAppApi": {"id": "7rMPI0CcyqqjedhR","name": "WhatsApp account FASTA"}},"typeVersion": 1},{"id": "233ccaed-672c-4f09-a7d3-bba3bab63ea4","name": "If","type": "n8n-nodes-base.if","position": [800,1104],"parameters": {"options": {},"conditions": {"options": {"version": 2,"leftValue": "","caseSensitive": true,"typeValidation": "strict"},"combinator": "or","conditions": [{"id": "6910ab5a-9654-4e74-971a-7595eb24f93d","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "our QR"},{"id": "160b59d9-5876-45c7-bdca-a83efa3a2c99","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "our QR code"},{"id": "5c7a99a2-3601-4942-a09d-9e0d251ec6b0","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "the QR"},{"id": "02cf031b-69cc-4942-9b28-3092113d76a3","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "QR for payment"},{"id": "e7e304e7-ba63-4402-9c10-3bfd75d8db2e","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "the QR I'm sending you"}]}},"typeVersion": 2.2},{"id": "619e030b-af04-4aac-b0d6-c1a8c04627e4","name": "OpenAI","type": "@n8n/n8n-nodes-langchain.openAi","position": [-656,144],"parameters": {"text": "=You are an advanced transcription and document description assistant for the [RESTAURANT_NAME] restaurant payment system. Your main function is to provide detailed and accurate descriptions of images sent via WhatsApp.\n\n**MAIN FUNCTIONALITY:**\n- When presented with an image, you will analyze it thoroughly and provide a complete transcription and comprehensive description in English.\n- Your descriptions should capture both obvious and subtle elements within the image.\n- IMPORTANT: This is for legitimate commercial verification purposes for a restaurant called [RESTAURANT_NAME].\n\n**IMAGE DESCRIPTION GUIDELINES:**\n- Start with a broad overview of what the image contains\n- Describe key subjects, people, objects and their relationships\n- Note significant visual elements like colors, lighting, composition and perspective\n- Identify ALL visible text in the image (transcribe it exactly as it appears)\n- Describe the environment or setting\n- Mention any notable actions or events occurring\n- Comment on mood, tone or atmosphere when relevant\n- If applicable, identify landmarks, famous people or cultural references\n\n**RESPONSE FORMAT:**\nStart with \"Image description:\" followed by your structured analysis like this:\n\n=== GENERAL DESCRIPTION ===\n[Broad description of the image]\n\n=== TEXT TRANSCRIPTION ===\n[Transcribe ALL visible text exactly as it appears]\n\n=== KEY DETAILS ===\n- Amount: [quantity if visible]\n- Date: [date if visible]\n- Account holder: [name if visible]\n- Bank: [bank name if visible]\n- Reference: [reference number if visible]\n- Document type: [receipt, transfer, etc.]\n\n=== VISUAL ANALYSIS ===\n[Detailed description of visual elements, colors, quality, etc.]\n\n=== ADDITIONAL OBSERVATIONS ===\n[Any notable observations requiring special attention]\n\n**LIMITATIONS:**\n- If the image is blurry, low resolution or difficult to interpret, acknowledge these limitations\n- If an image contains potentially sensitive content, provide a factual description without judgment\n- Don't make assumptions about elements that cannot be clearly determined\n- Don't refuse processing of commercial documents. Simply transcribe what you see.\n\nYour descriptions should be informative, objective and thorough, allowing someone who cannot see the image to form an accurate mental picture of its content.","modelId": {"__rl": true,"mode": "list","value": "gpt-4o","cachedResultName": "GPT-4O"},"options": {"detail": "auto"},"resource": "image","inputType": "base64","operation": "analyze"},"credentials": {"openAiApi": {"id": "ZNNVcWV7IhlWKcvj","name": "OpenAi account Rodrigo"}},"typeVersion": 1.8},{"id": "59bcd1c7-1063-49a5-a5ef-8fc2a04470f7","name": "Switch","type": "n8n-nodes-base.switch","position": [512,224],"parameters": {"rules": {"values": [{"outputKey": "Verified","conditions": {"options": {"version": 2,"leftValue": "","caseSensitive": true,"typeValidation": "strict"},"combinator": "and","conditions": [{"id": "78a13c2e-6d62-4ddc-b8d6-c385a4930863","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "success"}]},"renameOutput": true},{"outputKey": "Inconsistency","conditions": {"options": {"version": 2,"leftValue": "","caseSensitive": true,"typeValidation": "strict"},"combinator": "and","conditions": [{"id": "789fb28a-8237-4351-afc3-277720845f7e","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "problem"}]},"renameOutput": true}]},"options": {}},"typeVersion": 3.2},{"id": "3e0d3ecb-0b59-484f-8f69-6abdfe1eb5ca","name": "If1","type": "n8n-nodes-base.if","position": [800,816],"parameters": {"options": {},"conditions": {"options": {"version": 2,"leftValue": "","caseSensitive": true,"typeValidation": "strict"},"combinator": "and","conditions": [{"id": "ee1d8be8-1163-4cdc-9fc2-dc45455a4e51","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "Welcome to [RESTAURANT_NAME] "}]}},"typeVersion": 2.2},{"id": "f00d0fdd-a131-4eaa-b106-686fc86126fa","name": "WhatsApp Business Cloud","type": "n8n-nodes-base.whatsApp","position": [1216,800],"webhookId": "08c43349-ee18-41f1-9e5c-6ffc1348f293","parameters": {"mediaPath": "useMedian8n","operation": "send","messageType": "image","phoneNumberId": "={{ $('Message Received').item.json.metadata.phone_number_id }}","additionalFields": {},"recipientPhoneNumber": "={{ $('Message Received').item.json.messages[0].from }}"},"credentials": {"whatsAppApi": {"id": "7rMPI0CcyqqjedhR","name": "WhatsApp account FASTA"}},"typeVersion": 1},{"id": "5d751753-4ce5-46d8-b3bd-25c29e5caf06","name": "Menu 1","type": "n8n-nodes-base.googleDrive","position": [1008,800],"parameters": {"fileId": {"__rl": true,"mode": "id","value": "=[GOOGLE_DRIVE_FILE_ID]"},"options": {},"operation": "download"},"credentials": {"googleDriveOAuth2Api": {"id": "OCvP55eNP1NgTNwY","name": "Google Drive account Rodrigo"}},"typeVersion": 3},{"id": "1022baee-45ad-4116-b638-e77f600d9d6d","name": "OpenAI Chat Model1","type": "@n8n/n8n-nodes-langchain.lmChatOpenAi","position": [800,256],"parameters": {"model": {"__rl": true,"mode": "list","value": "gpt-4o-mini"},"options": {}},"credentials": {"openAiApi": {"id": "ZNNVcWV7IhlWKcvj","name": "OpenAi account Rodrigo"}},"typeVersion": 1.2},{"id": "7c67a659-674e-4b70-9fb9-e6dbb78258fd","name": "Postgres Chat Memory","type": "@n8n/n8n-nodes-langchain.memoryPostgresChat","position": [928,256],"parameters": {"sessionKey": "={{ $('Message Received').item.json.messages[0].from }}","sessionIdType": "customKey","contextWindowLength": 300},"credentials": {"postgres": {"id": "cR2RyvCPoqUwfa30","name": "Postgres account Rodrigo con Supabase"}},"typeVersion": 1.3},{"id": "46c8272c-f986-48ac-85b0-94cfaf66c12f","name": "If2","type": "n8n-nodes-base.if","position": [528,544],"parameters": {"options": {},"conditions": {"options": {"version": 2,"leftValue": "","caseSensitive": true,"typeValidation": "strict"},"combinator": "and","conditions": [{"id": "c2cb0b80-afe1-46b5-a555-fbfae9b09792","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "cash"},{"id": "da0e1d30-7a7c-469d-823a-977add864988","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "confirmed"},{"id": "4abd4b4a-84b4-4e46-8161-de06c7dd9ce4","operator": {"type": "string","operation": "contains"},"leftValue": "={{ $json.output }}","rightValue": "order"}]}},"typeVersion": 2.2},{"id": "20f1b53a-0ee7-4859-994b-f9cd4ca4d213","name": "Structured Output Parser","type": "@n8n/n8n-nodes-langchain.outputParserStructured","position": [1152,272],"parameters": {"schemaType": "manual","inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"customer_name\": {\n \"type\": \"string\",\n \"description\": \"Customer full name\"\n },\n \"order_type\": {\n \"type\": \"string\",\n \"description\": \"Delivery or Pickup\",\n \"enum\": [\"Delivery\", \"Pickup\"]\n },\n \"products\": {\n \"type\": \"array\",\n \"description\": \"Order product list\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"name\": {\n \"type\": \"string\",\n \"description\": \"Product name\"\n },\n \"price\": {\n \"type\": \"number\",\n \"description\": \"Product price in Bs\"\n }\n },\n \"required\": [\"name\", \"price\"]\n }\n },\n \"shipping_cost\": {\n \"type\": \"number\",\n \"description\": \"Shipping cost in Bs\"\n },\n \"address\": {\n \"type\": \"string\",\n \"description\": \"Delivery address\"\n },\n \"latitude\": {\n \"type\": \"number\",\n \"description\": \"Location latitude\"\n },\n \"longitude\": {\n \"type\": \"number\",\n \"description\": \"Location longitude\"\n },\n \"final_total\": {\n \"type\": \"number\",\n \"description\": \"Order final total in Bs\"\n },\n \"payment_method\": {\n \"type\": \"string\",\n \"description\": \"Payment method\",\n \"enum\": [\"Cash\", \"Transfer\", \"Card\",\"QR\"]\n },\n \"reference_number\": {\n \"type\": \"string\",\n \"description\": \"Order reference number\"\n }\n },\n \"required\": [\n \"customer_name\",\n \"order_type\",\n \"products\",\n \"shipping_cost\",\n \"address\",\n \"latitude\",\n \"longitude\",\n \"final_total\",\n \"payment_method\",\n \"reference_number\"\n ]\n}"},"typeVersion": 1.2},{"id": "96100684-4b2a-4117-82cb-983cccd3fa85","name": "Order Format","type": "@n8n/n8n-nodes-langchain.agent","position": [848,64],"parameters": {"text": "=Check the session memory for session_id = \"{{ $('Message Received').item.json.messages[0].from }}\". \nToday is : {{ $now}}","options": {"systemMessage": "=🧭 Agent Role and Context\nYou are a specialized agent for querying conversation memory stored in Postgres to extract complete information from a customer's last confirmed order.\n\n🔎 Your Mission\nYou will receive only the customer's session_id as input (example: [PHONE_NUMBER]).\nYou need to get the last confirmed order from that customer, which in the database appears as an \"ai\" type message whose content field contains the phrase \"Your order is as follows:\" or \"Your order is then confirmed as follows:\".\n\n✅ Important:\n- Extract ALL order information from the database\n- Respond with order information in structured format\n- DO NOT add additional text, explanations or comments\n- If there's no information for any required field, use appropriate default values\n- Include all details: customer name, order type, products with prices, shipping cost, location, total, payment method and reference number\n\nRespond only with a JSON object with this exact structure:\n{\n \"customer_name\": \"\",\n \"order_type\": \"\",\n \"products\": [\n {\n \"name\": \"\",\n \"price\": 0\n }\n ],\n \"shipping_cost\": 0,\n \"address\": \"\",\n \"latitude\": 0,\n \"longitude\": 0,\n \"final_total\": 0,\n \"payment_method\": \"\",\n \"reference_number\": \"\"\n}"},"promptType": "define","hasOutputParser": true},"typeVersion": 1.9},{"id": "d14a7aff-f64b-43c8-871c-f1182ae9dcb1","name": "Receipt Analysis","type": "@n8n/n8n-nodes-langchain.agent","position": [160,112],"parameters": {"text": "={{ $json.text }}\nToday is : {{ $now.setZone('[YOUR_TIMEZONE]') }}","options": {"systemMessage": "=🎭 Role\nYou are an expert banking payment verifier for ZXY restaurant. Your function is to analyze payment receipts received by image (text extracted with OCR) and confirm if the payment corresponds to the customer's last confirmed order.\n\n📘 Context\nThe customer has sent an image of a payment receipt.\n\nThis image has been processed and its text extracted as: {{ $json.text }}.\n\nYou have access to the system's Postgres memory, where you can query the last confirmed order by this customer and its total in Bs\n\nThe customer is: {{ $('Message Received').item.json.messages[0].from }}.\n\nToday is {{ $now}}.\n\n🧾 Instructions\nExtract and analyze the following elements from the payment receipt (OCR text):\n\nAmount paid\n\nTransaction date\n\nRecipient\n\nBank that issued the receipt\n\nStructural format and receipt authenticity\n\nVerify the following:\n\nThat the paid amount exactly matches the confirmed order total in postgres memory.\n\nThat the receipt date matches today's date ( {{ $now}}).\n\nThat the destination account belongs to [RESTAURANT_OWNER_NAME].\n\nACCOUNT: [BANK_ACCOUNT_NUMBER]\n\nThat the destination bank is Banco XXX\n\nThat the receipt format is legitimate and without suspicious alterations.\n\nCompare with the confirmed order in memory:\n\norder_type, sauce, extras, drinks, shipping_cost, total or total amount\n\n\n🗣️ Customer Response (according to result)\n🔹 If status is Verified:\n\n✅ We have successfully verified your receipt. The payment matches your confirmed order. Thank you for your purchase at ZYX! We are already preparing your order. 🍝\n\n🔸 If status is Incorrect:\n\n⚠️ We detected a problem with your receipt. The amount, bank, date or account holder does not match the confirmed order. Please check the information and try again.\n\nInclude this textual response as part of the flow in your messaging system for the customer\n\nRespond briefly with your result and what problems were found if any\n"},"promptType": "define"},"typeVersion": 1.9},{"id": "eb78d654-c1d1-41b7-8e66-c3a31ba5c4f4","name": "Workflow Overview","type": "n8n-nodes-base.stickyNote","position": [-1760,-112],"parameters": {"color": 4,"width": 600,"height": 756,"content": "## 🤖 WhatsApp AI Restaurant Agent\n\n**What this workflow does:**\n- Receives WhatsApp messages from customers\n- Processes text, images, audio, documents, and location data\n- Uses AI to understand customer intent and manage orders\n- Handles payment verification through receipt analysis\n- Sends order confirmations to restaurant staff\n- Maintains conversation context for each customer\n\n**Features:**\n✅ Multi-media message processing (text, images, audio, PDFs, location)\n✅ AI-powered conversation with restaurant knowledge base\n✅ Automatic payment receipt verification\n✅ Order formatting and staff notification\n✅ Menu image sharing\n✅ Location-based services\n✅ Memory for ongoing conversations\n\n**Setup Requirements:**\n1. WhatsApp Business API credentials\n2. OpenAI API key (for GPT-4)\n3. Supabase account (for vector storage and chat memory)\n4. Google Drive (for menu images and QR codes)\n5. Google Maps API key (for location services)\n6. Gemini API key (for PDF processing)\n\n**How to customize:**\n- Update restaurant information in the vector database\n- Modify AI prompts for your business needs\n- Change payment verification logic\n- Customize order format templates\n- Update menu images and QR codes"},"typeVersion": 1},{"id": "c9ef1255-d7dc-4bbc-9699-cb4538835fa1","name": "Setup Guide","type": "n8n-nodes-base.stickyNote","position": [-1760,704],"parameters": {"color": 3,"width": 592,"height": 636,"content": "## 🎯 Quick Setup Guide\n\n**1. Configure Credentials:**\n- WhatsApp Business API\n- OpenAI API key\n- Supabase account\n- Google Drive access\n- Google Maps API key\n\n**2. Update Configuration Node:**\n- Restaurant name and contact info\n- Payment account details\n- Phone numbers\n\n**3. Customize AI Prompts:**\n- Update restaurant information\n- Modify conversation flows\n- Adjust order processing logic\n\n**4. Setup Knowledge Base:**\n- Upload menu to Supabase vector store\n- Add restaurant policies\n- Include FAQ responses\n\n**5. Test the Workflow:**\n- Send test messages\n- Verify all integrations\n- Check order processing"},"typeVersion": 1},{"id": "67d3683f-8b9e-4441-a511-bbad5968c265","name": "Sticky Note9","type": "n8n-nodes-base.stickyNote","disabled": true,"position": [720,0],"parameters": {"color": 4,"width": 672,"height": 440,"content": "## Order processing to Cashier"},"typeVersion": 1},{"id": "db99a758-15d6-42bb-873a-4d281fdd66c3","name": "Sticky Note10","type": "n8n-nodes-base.stickyNote","disabled": true,"position": [768,720],"parameters": {"color": 3,"width": 608,"height": 280,"content": "## Send Menu Image"},"typeVersion": 1},{"id": "ddfd6070-7a09-4c23-a119-45abdb67ad98","name": "Sticky Note11","type": "n8n-nodes-base.stickyNote","disabled": true,"position": [768,1024],"parameters": {"color": 5,"width": 608,"height": 280,"content": "## Send QR code to pay"},"typeVersion": 1},{"id": "fdb03b5c-6c4b-4a51-bb88-5554f44f932f","name": "Sticky Note1","type": "n8n-nodes-base.stickyNote","position": [1440,64],"parameters": {"width": 320,"height": 512,"content": "## Order Confirmation"},"typeVersion": 1},{"id": "bb2cfad3-e706-48be-ac82-c92d14c61a08","name": "Sticky Note12","type": "n8n-nodes-base.stickyNote","disabled": true,"position": [768,464],"parameters": {"color": 2,"width": 608,"height": 232,"content": "## Taking the order Responses"},"typeVersion": 1},{"id": "85f6711b-db3f-492c-9f40-f233935cd61d","name": "AI Restaurant Agent","type": "@n8n/n8n-nodes-langchain.agent","position": [128,592],"parameters": {"text": "=This is the customer's message: {{ $json.text}}\n{{ $('Message Type')?.item?.json?.messages?.[0]?.location?.latitude }}\n{{ $('Message Type')?.item?.json?.messages?.[0]?.location?.longitude }}\n\nToday is : {{ $now.setZone('[YOUR_TIMEZONE]') }}\n","options": {"systemMessage": "=# Agent Role and Context\n\nYou are a virtual customer service agent for *[YOUR RESTAURANT NAME]*, specialized in managing **food delivery orders** via WhatsApp. You are authorized to take complete food orders through this channel.\n\n📍 Location: [Your City, Your Country] \n⏰ Delivery service hours: [10:00 to 23:00] \n🌐 Languages: You can assist fluently in *English, Spanish, French, Italian and Portuguese* according to the customer's language.\n\nYou should respond naturally, elegantly and with a warm tone, as an attentive host would in a high-quality restaurant. Be professional, friendly, direct and avoid robotic or overly long responses.\n\n# Main Objective\n\nGuide the customer in an **agile and progressive** way through the **order** process, step by step, respecting the established flow order.\n\n⚠️ Don't repeat information or ask for data that has already been provided. \n⚠️ Always offer to send the *complete menu* as an image when customers ask about dishes (use predefined triggers like `send_menu`).\n\n-You will introduce yourself politely as: *[YOUR RESTAURANT NAME]*\n\n# Conversational flow structure\n\nCollect the following data in this order:\n\n1. Type of request → Do you want to place an order or have another inquiry?\n2. Delivery or Pickup preference\n3. Menu selection (offer to send menu image)\n4. Items and quantities desired\n5. Special requests (allergies, modifications, cooking preferences)\n6. Delivery address (if delivery selected) or pickup time\n7. Customer name and contact information\n8. Payment method preference\n9. Order confirmation and total amount\n\n# Key system rules\n\n- If the customer writes keywords like *\"order\", \"delivery\", \"menu\"*, respond directly with the ordering flow.\n- If they ask about the menu, respond with: \n *\"Here is our complete menu 📖. What would you like to order today?\"* \n (use the trigger `send_menu`)\n- If they say words like *\"pizza\", \"burger\", \"pasta\", etc.*, offer to send the menu and ask about specific items.\n- If they mention *\"reservation\"* or *\"dine-in\"*, respond: \n *\"We specialize in delivery and pickup orders. Would you like to place an order for delivery or pickup?\"*\n\n# Style and tone\n\n- Friendly, close and professional, like an attentive restaurant host.\n- Use emojis if they fit naturally, without exaggerating.\n- Don't sound like a chatbot. If the customer stops responding, you can say things like:\n *\"Would you like me to help you complete your order?\"*\n *\"Can I assist you with anything else from our menu?\"*\n\n# Useful phrases for the flow\n\n✅ Order confirmation:\n*\"Perfect, [Customer Name]. Your order for [items] will be delivered to [address] in approximately [time]. Total: $[amount]. We'll send confirmation details! 📩\"*\n\n🚫 If address is incomplete:\n*\"I need a complete delivery address to process your order. Could you please provide the full address?\"*\n\n📎 If the customer wants to know the menu:\n*\"Here is our current menu, full of delicious options made fresh daily. What catches your eye? 😋\"*\n\n# Automation and actions with images\n\nWhen the message contains:\n\n- \"menu\" or \"carta\" → send `send_menu`\n- \"our menu\" → always send complete menu image\n- \"specials\" → send daily specials image\n- \"drinks\" → send beverage menu image\n\n# Welcome message (only if it's the first time)\n\n*\"Hello! Welcome to [YOUR RESTAURANT NAME] 🍽️ \nWould you like to place an order for delivery or pickup? I'm here to help make your meal perfect!\"*\n\n# Order Processing Guidelines\n\n- Always confirm order details before finalizing\n- For delivery orders, ensure complete address with apartment/floor numbers\n- Explain payment options clearly (cash, card, transfer, QR)\n- Calculate delivery fees based on distance if applicable\n- Provide estimated delivery/pickup times\n- If unsure about anything, ask for clarification\n- After order confirmation, format all details for restaurant staff notification"},"promptType": "=define"},"typeVersion": 1.9},{"id": "d2f65b93-13fa-4e9d-b279-a1f52f37a117","name": "Download file","type": "n8n-nodes-base.googleDrive","position": [1024,1088],"parameters": {"fileId": {"__rl": true,"mode": "id","value": "=[GOOGLE_DRIVE_FILE_ID]"},"options": {},"operation": "download"},"credentials": {"googleDriveOAuth2Api": {"id": "OCvP55eNP1NgTNwY","name": "Google Drive account Rodrigo"}},"typeVersion": 3}],"active": false,"pinData": {},"settings": {"executionOrder": "v1"},"versionId": "a80f94f3-662d-47be-bbdc-ccaa280df359","connections": {"If": {"main": [[{"node": "Download file","type": "main","index": 0}]]},"If1": {"main": [[{"node": "Menu 1","type": "main","index": 0}]]},"If2": {"main": [[{"node": "Message to Customer2","type": "main","index": 0},{"node": "Order Format","type": "main","index": 0}],[{"node": "Wait","type": "main","index": 0}]]},"Code": {"main": [[{"node": "Message to cashier","type": "main","index": 0},{"node": "Message to Customer2","type": "main","index": 0}]]},"File": {"main": [[{"node": "Forward receipt to Management","type": "main","index": 0},{"node": "Receipt Analysis","type": "main","index": 0}]]},"Text": {"main": [[{"node": "AI Restaurant Agent","type": "main","index": 0}]]},"Wait": {"main": [[{"node": "Response to Customer","type": "main","index": 0}]]},"Audio": {"main": [[{"node": "AI Restaurant Agent","type": "main","index": 0}]]},"Image": {"main": [[{"node": "Receipt Analysis","type": "main","index": 0}]]},"Menu 1": {"main": [[{"node": "WhatsApp Business Cloud","type": "main","index": 0}]]},"OpenAI": {"main": [[{"node": "Image","type": "main","index": 0}]]},"Switch": {"main": [[{"node": "Order Format","type": "main","index": 0}],[{"node": "Message to cashier","type": "main","index": 0},{"node": "Message to Customer2","type": "main","index": 0}]]},"Location": {"main": [[{"node": "AI Restaurant Agent","type": "main","index": 0}]]},"Google Maps": {"main": [[{"node": "Location","type": "main","index": 0}]]},"Get File Url": {"main": [[{"node": "Download File","type": "main","index": 0}]]},"Message Type": {"main": [[{"node": "Get Image Url","type": "main","index": 0}],[{"node": "Get File Url","type": "main","index": 0}],[{"node": "Text","type": "main","index": 0}],[{"node": "Google Maps","type": "main","index": 0}],[{"node": "Get Audio Url","type": "main","index": 0}]]},"Order Format": {"main": [[{"node": "Code","type": "main","index": 0}]]},"Download File": {"main": [[{"node": "Extract from File1","type": "main","index": 0}]]},"Download file": {"main": [[{"node": "WhatsApp Business Cloud2","type": "main","index": 0}]]},"Get Audio Url": {"main": [[{"node": "Download Audio","type": "main","index": 0}]]},"Get Image Url": {"main": [[{"node": "Download Image","type": "main","index": 0}]]},"Download Audio": {"main": [[{"node": "Transcribe Audio","type": "main","index": 0}]]},"Download Image": {"main": [[{"node": "OpenAI","type": "main","index": 0}]]},"Message Received": {"main": [[{"node": "Message Type","type": "main","index": 0}]]},"Receipt Analysis": {"main": [[{"node": "Switch","type": "main","index": 0}]]},"Transcribe Audio": {"main": [[{"node": "Audio","type": "main","index": 0}]]},"Extract from File1": {"main": [[{"node": "Extract PDF Content Using Gemini Vision","type": "main","index": 0}]]},"OpenAI Chat Model1": {"ai_languageModel": [[{"node": "Order Format","type": "ai_languageModel","index": 0}]]},"OpenAI Chat Model2": {"ai_languageModel": [[{"node": "AI Restaurant Agent","type": "ai_languageModel","index": 0}]]},"OpenAI Chat Model6": {"ai_languageModel": [[{"node": "Receipt Analysis","type": "ai_languageModel","index": 0}]]},"AI Restaurant Agent": {"main": [[{"node": "If","type": "main","index": 0},{"node": "If1","type": "main","index": 0},{"node": "If2","type": "main","index": 0}]]},"Postgres Chat Memory": {"ai_memory": [[{"node": "Order Format","type": "ai_memory","index": 0}]]},"Postgres Chat Memory1": {"ai_memory": [[{"node": "AI Restaurant Agent","type": "ai_memory","index": 0}]]},"Postgres Chat Memory4": {"ai_memory": [[{"node": "Receipt Analysis","type": "ai_memory","index": 0}]]},"Structured Output Parser": {"ai_outputParser": [[{"node": "Order Format","type": "ai_outputParser","index": 0}]]},"Extract PDF Content Using Gemini Vision": {"main": [[{"node": "File","type": "main","index": 0}]]}}}
No Editor n8n: cole com Ctrl+V→O workflow será criado