{
  "name": "AI-Powered WhatsApp Business Automation with n8n, OpenAI & Google Sheets",
  "nodes": [
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        576,
        400
      ],
      "id": "02f0a094-e86a-4e37-968f-8a4f8cd94c1d",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "updates": [
          "messages"
        ],
        "options": {}
      },
      "type": "n8n-nodes-base.whatsAppTrigger",
      "typeVersion": 1,
      "position": [
        -832,
        256
      ],
      "id": "6362cf0d-bd85-4c2a-b5c3-02bb78df0cb0",
      "name": "Incoming WhatsApp Message",
      "credentials": {
        "whatsAppTriggerApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.messages[0].text.body }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "id": "d53b98e7-1000-4c5a-97b1-ac85ae27bdcf"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Text"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "f636c133-cf65-4e7e-b27a-ed03c17ebcab",
                    "leftValue": "={{ $json.messages[0].audio }}",
                    "rightValue": "",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Audio"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "a6d4d807-e948-4f49-a71d-57c26d0f62af",
                    "leftValue": "={{ $json.messages[0].image }}",
                    "rightValue": "",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Image"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -576,
        240
      ],
      "id": "54c8f485-2b19-4839-afd6-3b2275a06374",
      "name": "Detect Message Type (Text / Audio / Image)"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "223aa09e-26a3-4994-9a87-8190e7524f09",
              "name": "Text",
              "value": "={{ $json.messages[0].text.body }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        0,
        0
      ],
      "id": "b592f13b-3f3d-41d8-8479-c84ade443ec7",
      "name": "Extract Text Message"
    },
    {
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].audio.id }}"
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -320,
        240
      ],
      "id": "d6788766-e040-4238-bfdf-ed2a706749b7",
      "name": "Fetch Audio Media Metadata",
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "authentication": "YOUR_API_KEY_HERE",
        "genericAuthType": "YOUR_API_KEY_HERE",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -112,
        240
      ],
      "id": "5737487b-e38d-4073-8cb7-71d812c52999",
      "name": "Download Audio File",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "audio",
        "operation": "transcribe",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        96,
        240
      ],
      "id": "8c88e3a1-aee4-4eb2-8737-2e5fd7193790",
      "name": "Transcribe Voice Note",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c57f6c30-790d-4a57-9279-2a925bdfd62a",
              "name": "text",
              "value": "={{ $json.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        304,
        240
      ],
      "id": "3a19a5d4-ea6b-4e49-9c8b-a44d24df9a26",
      "name": "Normalize Transcribed Text"
    },
    {
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].image.id }}"
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -336,
        448
      ],
      "id": "eb84c923-a67f-4f93-a388-526b9e0907ce",
      "name": "Fetch Image Media Metadata",
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "authentication": "YOUR_API_KEY_HERE",
        "genericAuthType": "YOUR_API_KEY_HERE",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -160,
        448
      ],
      "id": "38d89516-86d0-4b10-810c-2621d66e94b5",
      "name": "Download Image File",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "image",
        "operation": "analyze",
        "modelId": {
          "__rl": true,
          "value": "chatgpt-4o-latest",
          "mode": "list",
          "cachedResultName": "CHATGPT-4O-LATEST"
        },
        "text": "Describe what is in this image with a lot of details",
        "inputType": "base64",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        48,
        448
      ],
      "id": "bfe030de-e267-4a50-ae20-c959931957ff",
      "name": "Analyze Image Content (Vision AI)",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "398fe85a-8761-48b6-be3c-7083e015d185",
              "name": "Text",
              "value": "={{ $json.content }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        256,
        448
      ],
      "id": "6540e158-65b7-4042-af12-d42133ea47da",
      "name": "Normalize Image Description"
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "wamid.HBgNMjM0ODE2NjM0MzUyMBUCABIYIEQ5NzlDREIxNDhGNjVCQ0QyOUU2QUZEN0ZFRkRDNDEzAA==",
        "contextWindowLength": 20
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        704,
        400
      ],
      "id": "76b24a6b-f02a-4b13-aea8-9c4f0711af3e",
      "name": "Conversation Memory Buffer"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.Text }}",
        "options": {
          "systemMessage": "You are the friendly WhatsApp assistant for Sylvia Hub, a Nigerian jewellery vendor. \nBusiness details:\n- Open Monday to Saturday, 11:00 AM to 6:00 PM (Nigeria time).\n- Some items may be out of stock; availability is indicated in the data.\n- Delivery fees are also listed in the data.\n- Customers may ask about jewellery availability, prices, delivery, or general info.\n\nYour rules:\n1. Always use the google sheet given to you.\n2. If current time is outside open hours, reply: \n   \"Hi there! We\u2019re currently closed. Our hours are Mon\u2013Sat, 11AM\u20136PM. I can take your pre-order for when we open.\"\n3. Never guess jewellery items or prices \u2014 only use what\u2019s provided in the google sheet.\n4. If an item is unavailable, tell the customer it\u2019s sold out and suggest available alternatives.\n5. If the customer wants to order:\n   - Confirm the item name and quantity.\n   - Ask for their delivery address.\n   - Give the delivery fee from the menu or delivery table.\n   - Calculate total cost (item price \u00d7 quantity + delivery fee).\n   - Ask for preferred payment method.\n   - Confirm the order and expected delivery time.\n\nTone:\n- Warm, polite, professional, and efficient.\n- Use Nigerian Naira (\u20a6) for prices.\n- Keep responses short unless more detail is requested.\n- Avoid over-formality; sound human and approachable.\n\n---\n\n### Menu Data:\n{{GoogleSheetMenuData}}\n\n### Current Date & Time (Nigeria):\n{{CurrentTime}}\n\n---\n\nExample interaction:\n\nCustomer: \u201cWhat\u2019s available today?\u201d\nAssistant: \u201cToday we have:\n- Gold Necklace Set \u2013 \u20a635,000 (Available)\n- Pearl Earrings \u2013 \u20a67,500 (Sold Out)\nDelivery within Lagos is \u20a61,500. Which piece would you like?\u201d\n\nCustomer: \u201cDo you have pearl earrings?\u201d\nAssistant: \u201cPearl Earrings are sold out today. We still have Gold Necklace Sets available. Would you like to order one?\u201d\n\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.1,
      "position": [
        576,
        240
      ],
      "id": "3ae7ee90-5010-454e-9886-55b9ff50569a",
      "name": "Sylvia Hub Sales Assistant"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1BoesL7V4xw5pgLiTrSo3dICqDqG9M1udffDFJQKfkP4",
          "mode": "list",
          "cachedResultName": "Sylvia's Hub Menu",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1BoesL7V4xw5pgLiTrSo3dICqDqG9M1udffDFJQKfkP4/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 947720271,
          "mode": "list",
          "cachedResultName": "jewellery_inventory.csv",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1BoesL7V4xw5pgLiTrSo3dICqDqG9M1udffDFJQKfkP4/edit#gid=947720271"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.6,
      "position": [
        592,
        592
      ],
      "id": "fdcb283c-20c4-4795-a058-a3f86d2acfb1",
      "name": "Fetch Jewellery Inventory",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1yUNbvxxxEv5erYj8aFQk0ZRE6P9hDSHNgv7w1mmZ0GA",
          "mode": "list",
          "cachedResultName": "sylvia_hub_operations",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1yUNbvxxxEv5erYj8aFQk0ZRE6P9hDSHNgv7w1mmZ0GA/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 47553581,
          "mode": "list",
          "cachedResultName": "sylvia_hub_operations.csv",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1yUNbvxxxEv5erYj8aFQk0ZRE6P9hDSHNgv7w1mmZ0GA/edit#gid=47553581"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.6,
      "position": [
        832,
        592
      ],
      "id": "d0c45586-67f1-48fd-9816-c5bc85f48c2f",
      "name": "Fetch Store Operations & Delivery Rules",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "+1234567890",
        "recipientPhoneNumber": "={{ $('Incoming WhatsApp Message').item.json.messages[0].from }}",
        "textBody": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        992,
        240
      ],
      "id": "6aa14d4f-da47-4d37-b0ba-19f8f2771e7e",
      "name": "Reply to WhatsApp Customer",
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Input\n",
        "height": 384,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -896,
        80
      ],
      "id": "88042dd9-3649-46e4-8b43-87684412e7c7",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Processing",
        "height": 656,
        "width": 1088,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -592,
        -48
      ],
      "id": "ef4da469-eb99-4b22-8b9c-06f7419e8e51",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## Brain",
        "height": 752,
        "width": 400,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        528,
        0
      ],
      "id": "7799db89-3c2d-466a-9c1c-e90ee24dce65",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "## Output",
        "height": 512,
        "width": 272
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        944,
        16
      ],
      "id": "88467ff6-a89c-4e2c-94bd-ff70f7d41262",
      "name": "Sticky Note3"
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Sylvia Hub Sales Assistant",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Incoming WhatsApp Message": {
      "main": [
        [
          {
            "node": "Detect Message Type (Text / Audio / Image)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Detect Message Type (Text / Audio / Image)": {
      "main": [
        [
          {
            "node": "Extract Text Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fetch Audio Media Metadata",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fetch Image Media Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text Message": {
      "main": [
        [
          {
            "node": "Sylvia Hub Sales Assistant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Audio Media Metadata": {
      "main": [
        [
          {
            "node": "Download Audio File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Audio File": {
      "main": [
        [
          {
            "node": "Transcribe Voice Note",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe Voice Note": {
      "main": [
        [
          {
            "node": "Normalize Transcribed Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Transcribed Text": {
      "main": [
        [
          {
            "node": "Sylvia Hub Sales Assistant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Image Media Metadata": {
      "main": [
        [
          {
            "node": "Download Image File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Image Content (Vision AI)": {
      "main": [
        [
          {
            "node": "Normalize Image Description",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Image Description": {
      "main": [
        [
          {
            "node": "Sylvia Hub Sales Assistant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Conversation Memory Buffer": {
      "ai_memory": [
        [
          {
            "node": "Sylvia Hub Sales Assistant",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Sylvia Hub Sales Assistant": {
      "main": [
        [
          {
            "node": "Reply to WhatsApp Customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Jewellery Inventory": {
      "ai_tool": [
        [
          {
            "node": "Sylvia Hub Sales Assistant",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Store Operations & Delivery Rules": {
      "ai_tool": [
        [
          {
            "node": "Sylvia Hub Sales Assistant",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d7955eab-300d-47a3-b218-372c33b7da1f",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "w61PsDneDXA4AP5p",
  "tags": []
}