{
  "id": "DoqotzYD6e73F67k",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "2Chat Support AI Chatbot with Google Sheets",
  "tags": [],
  "nodes": [
    {
      "id": "cb4f1cf1-9534-4cc2-8aa6-ecad0b69a829",
      "name": "2Chat Trigger",
      "type": "@2chat/n8n-nodes-twochat.twoChatTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "event": "whatsapp.message.received",
        "whatsappNumber": "+1234567890"
      },
      "credentials": {
        "twoChatApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "44fc834f-6209-4902-bef6-2faae1bb9851",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        344,
        0
      ],
      "parameters": {
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "Situation\nYou are a customer support representative for a business. Customers will contact you with inquiries in various languages, and you have access to two specific tools to help resolve their questions: a FAQ database and a product catalog.\n\nTask\nThe assistant should respond to customer inquiries by:\n\nMatching the customer's language and maintaining a polite, professional tone throughout all interactions\nUsing the \"Get FAQ answers\" tool when customers ask questions or seek information\nUsing the \"Get Product Catalog\" tool when customers inquire about products, pricing, availability, or specifications\nProviding responses exclusively based on information retrieved from these two tools\u2014do not use external knowledge or make assumptions beyond what these tools provide\nObjective\nDeliver accurate, helpful customer support by directing inquiries to the appropriate tool and ensuring customers receive consistent, reliable information sourced only from your business's official FAQ and product databases.\n\nKnowledge\n\nYou have access to two tools only: \"Get FAQ answers\" and \"Get Product Catalog\"\nCustomers may write in any language; respond in their language\nOnly provide information that exists in these tools; do not supplement with general knowledge or assumptions\nIf a customer's question cannot be answered by either tool, acknowledge this limitation politely and offer to escalate or suggest alternative assistance"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "c348b648-a824-460a-97ed-371387e56802",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        224,
        224
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5b1f0699-e7b4-4bb9-b5dd-2b10413a1a4c",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        352,
        224
      ],
      "parameters": {
        "sessionKey": "={{ $json.remote_phone_number }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "c54f6dbe-2a71-4d14-a195-6a6cc83990ef",
      "name": "Send a whatsapp message",
      "type": "@2chat/n8n-nodes-twochat.twoChat",
      "position": [
        864,
        0
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "toNumber": "={{ $('2Chat Trigger').item.json.remote_phone_number }}",
        "pinLocation": {},
        "whatsappNumber": "+1234567890"
      },
      "credentials": {
        "twoChatApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "32b9361a-3387-4a89-b763-5ccabc4c197f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -672,
        -272
      ],
      "parameters": {
        "width": 528,
        "height": 688,
        "content": "### This n8n template demonstrates how to build an **AI-powered WhatsApp customer support chatbot** using **2Chat** for WhatsApp integration and **OpenAI** for natural language understanding. The chatbot is designed to answer customer inquiries about products and business information by querying **Google Sheets** for relevant data.\n\n**Good to know**\n- This workflow uses **2Chat** to connect with WhatsApp, so you\u2019ll need a 2Chat account and a connected WhatsApp number.\n- OpenAI\u2019s API is used for AI responses, so you\u2019ll need an OpenAI API key.\n- The chatbot retrieves product and business information from **Google Sheets**, so ensure your sheets are properly formatted and accessible.\n- Costs depend on your OpenAI usage, 2Chat pricing tier, and Google Sheets access.\n\n---\n### How it works\n- **Trigger:** The workflow starts when a new WhatsApp message is received via **2Chat**.\n- **AI Agent:** The chatbot uses an **AI Agent powered by OpenAI** to understand the customer\u2019s query and determine the context (product or business-related).\n- **Data Lookup:**\n  - If the query is about **products**, the AI Agent searches a designated **Google Sheet** for relevant product information.\n  - If the query is about **business information**, the AI Agent searches another **Google Sheet** for the most appropriate response.\n- **Response Generation:** The AI Agent crafts a response based on the retrieved data.\n- **Reply:** The response is sent back to the customer via WhatsApp using **2Chat\u2019s Send WhatsApp Message** node."
      },
      "typeVersion": 1
    },
    {
      "id": "6a34f366-8283-4fd8-b74b-0600512e24ba",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        -176
      ],
      "parameters": {
        "color": 7,
        "height": 336,
        "content": "## Trigger the chatbot with every new message received\n"
      },
      "typeVersion": 1
    },
    {
      "id": "908dc4df-8d82-4043-b12b-732101939618",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        -176
      ],
      "parameters": {
        "color": 4,
        "width": 720,
        "height": 544,
        "content": "## AI Agent \nThe agent will use the knowledge in the System prompt. You must customize it to your business needs"
      },
      "typeVersion": 1
    },
    {
      "id": "069578ee-14e1-42c3-a223-a7cabbb0cce9",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        816,
        -176
      ],
      "parameters": {
        "color": 7,
        "height": 336,
        "content": "## Return the message generated\n"
      },
      "typeVersion": 1
    },
    {
      "id": "57547f6b-301b-4b6a-a15f-f6e0592a2996",
      "name": "Get Product Catalog",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        480,
        224
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1UAu7ikRyKli42gCxSE3hAoP9GIZX3JMx9_xjI9ZjsKk/edit#gid=0",
          "cachedResultName": "Products"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1UAu7ikRyKli42gCxSE3hAoP9GIZX3JMx9_xjI9ZjsKk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1UAu7ikRyKli42gCxSE3hAoP9GIZX3JMx9_xjI9ZjsKk/edit?usp=drivesdk",
          "cachedResultName": "2Chat Beauty Store"
        },
        "descriptionType": "manual",
        "toolDescription": "Get row(s) in sheet in Google Sheets when the customer asks about products or about what the store sells"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "a12586ff-db51-48a4-8d19-6c59071f6e98",
      "name": "Get FAQ answers",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        608,
        224
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 2147231528,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1UAu7ikRyKli42gCxSE3hAoP9GIZX3JMx9_xjI9ZjsKk/edit#gid=2147231528",
          "cachedResultName": "FAQ"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1UAu7ikRyKli42gCxSE3hAoP9GIZX3JMx9_xjI9ZjsKk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1UAu7ikRyKli42gCxSE3hAoP9GIZX3JMx9_xjI9ZjsKk/edit?usp=drivesdk",
          "cachedResultName": "2Chat Beauty Store"
        },
        "descriptionType": "manual",
        "toolDescription": "Get row(s) in sheet in Google Sheets when the customer asks common questions not related to specific products"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "bfaf5683-6c79-48bd-b31d-858478005b98",
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send a whatsapp message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2Chat Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Get FAQ answers": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Product Catalog": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}