{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "93118333-81b4-48a6-b5e4-ccc1eb2915df",
      "name": "WhatsApp Message Received",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        -592,
        0
      ],
      "parameters": {
        "options": {
          "messageStatusUpdates": [
            "all"
          ]
        },
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c2db53c3-7a90-444a-a785-a439ef835434",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -416,
        144
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c528b6af-a39d-4e86-9542-1c1dd066af22",
      "name": "Is Message?",
      "type": "n8n-nodes-base.if",
      "position": [
        -416,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "0655157c-cac4-4993-af22-d167b2343297",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ !!$json.messages?.[0]?.from }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "4c6e405c-53f8-477d-a55a-9fdc3ae7fbaf",
      "name": "Transcribe audio",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        320,
        -32
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "transcribe"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "df6ac069-fe1e-41d3-a872-571bae411220",
      "name": "Download Voice",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        0,
        -32
      ],
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].audio.id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8f30d58e-2eb3-47d7-b39f-92b85678b962",
      "name": "Get Audio",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        160,
        -32
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "4090b5c6-fa50-4350-8f29-c18be5aea6f0",
      "name": "get_schedule",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        1168,
        224
      ],
      "parameters": {
        "limit": 3,
        "options": {},
        "timeMax": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Before', ``, 'string') }}",
        "timeMin": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('After', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "user@example.com",
          "cachedResultName": "user@example.com"
        },
        "operation": "getAll"
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "85f332ff-cda7-43c1-9042-3a601d96075d",
      "name": "ai_memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        720,
        32
      ],
      "parameters": {
        "sessionKey": "={{ $json.chat_id }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "dc0b8085-4b5b-4ff9-aaf2-99c291caa1d4",
      "name": "set_appointment",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        1408,
        224
      ],
      "parameters": {
        "end": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('End', ``, 'string') }}",
        "start": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "user@example.com",
          "cachedResultName": "user@example.com"
        },
        "additionalFields": {}
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "0efd193c-a796-4ca1-905b-a3bdd6aac5e2",
      "name": "Customer Service Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        720,
        -160
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "=**System Prompt for WhatsApp Customer Service Bot**\n\nYou are a helpful and professional **WhatsApp customer service assistant**.\nYou always respond politely, concisely, and in a friendly tone.\nYou can answer FAQs, provide service information, and schedule appointments.\nYou must always use the provided tools to complete tasks. Do not invent answers.\n\n### Tools you must use:\n\n1. **faq_base**\n   * Retrieves FAQs from a Google Sheet.\n   * Returns a table with: `id | question | answer`.\n   * Use when the user asks a general or frequently asked question.\n   * Your job: search for the closest matching question and return the most relevant answer.\n\n2. **get_services**\n   * Retrieves service information from a Google Sheet.\n   * Returns a table with: `id | service_name | service_description | price`.\n   * Use when the user asks about services, details, or prices.\n\n3. **get_schedule**\n   * Checks Google Calendar for available time slots.\n   * Input: service type, preferred day/time.\n   * Returns 3 available slot options.\n   * Ask the user to choose one.\n\n4. **set_appointment**\n   * Books the confirmed appointment in Google Calendar.\n   * Input: chosen service, date/time, and customer details (name, email, phone).\n\n5. **agent_reply**\n   * Sends messages back to the user on WhatsApp.\n   * Always use this tool to answer back to the user.\n\n### Rules of Behavior\n\n* Always use `agent_reply` to send every response.\n* Never make up answers \u2014 always rely on the tools.\n* If the user\u2019s request is unclear, ask clarifying questions.\n* For FAQs: query `faq_base`.\n* For service details: query `get_services`.\n* For scheduling:\n\n  1. Ask the user which service they want.\n  2. Ask for preferred day and time.\n  3. Call `get_schedule` and show 3 options.\n  4. Collect name, email, phone number.\n  5. Call `set_appointment`.\n  6. Confirm booking with the user.\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "3d698916-6647-4f37-8d25-14d5f6b8ef51",
      "name": "faq_base",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        672,
        224
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "",
          "cachedResultName": "FAQ"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1YEf9xuQGoOFKOxiTHDCJSz-m-Oke-SPj8dY6Nd4Np4c",
          "cachedResultUrl": "",
          "cachedResultName": "Database"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "24d7069b-7738-47cd-8932-c557676fc9c2",
      "name": "Agent Context",
      "type": "n8n-nodes-base.set",
      "position": [
        544,
        -160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7182b6f8-b1b2-4dd8-a5a0-d0c820816767",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $('WhatsApp Message Received').item.json.metadata.phone_number_id }}"
            },
            {
              "id": "433cf6ab-8939-412b-aa92-6fca6af534e9",
              "name": "from",
              "type": "string",
              "value": "={{ $('WhatsApp Message Received').item.json.messages[0].from }}"
            },
            {
              "id": "f19e6d2a-6ffa-41e3-8ff3-44b70976d0d4",
              "name": "text",
              "type": "string",
              "value": "={{ $json.text || $('WhatsApp Message Received').item.json.messages[0]?.text?.body || ''}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9e7842c0-de0f-4aac-a830-bc70a4e4b614",
      "name": "Chat Router",
      "type": "n8n-nodes-base.switch",
      "position": [
        -208,
        -144
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a561aab7-4c3b-4c96-9bb7-078281b5c7d5",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.messages[0].type }}",
                    "rightValue": "text"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "voice",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b7f1055d-6651-416f-b0cd-c46e003d4f3a",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.messages[0].type }}",
                    "rightValue": "audio"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "8fb27413-ab5f-4757-afe8-1df81dcf578d",
      "name": "get_services",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        928,
        224
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1356596420,
          "cachedResultUrl": "",
          "cachedResultName": "SERVICES"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1YEf9xuQGoOFKOxiTHDCJSz-m-Oke-SPj8dY6Nd4Np4c",
          "cachedResultUrl": "",
          "cachedResultName": "Database"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "b83be440-9e12-44fd-b003-7526dd835905",
      "name": "ai_chat",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        608,
        32
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ef0a1451-f68b-40f5-a7d6-c0a0fa4ea87d",
      "name": "Send message",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        1360,
        -160
      ],
      "parameters": {
        "textBody": "={{ $json.output }}",
        "operation": "send",
        "phoneNumberId": "={{ $('Agent Context').item.json.chat_id }}",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('Agent Context').item.json.from }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cb3bc335-7def-4ed5-962d-8dcd33e383f6",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1200,
        -640
      ],
      "parameters": {
        "width": 864,
        "height": 608,
        "content": "## WhatsApp customer service bot with FAQ and appointment scheduling\n\n### Who\u2019s it for\nThis template is designed for businesses that provide customer support and appointment-based services over WhatsApp. It\u2019s ideal for service providers (e.g., clinics, salons, repair shops, consultants) that want to automate FAQs, share service information, and schedule appointments without manual effort.\n\n### How it works\n- Answers FAQs by querying a Google Sheet knowledge base.\n- Provides service information (name, description, price) from a Google Sheet.\n- Schedules appointments by:\n  1. Asking which service the customer wants.\n  2. Collecting preferred day and time.\n  3. Checking Google Calendar for availability.\n  4. Offering 3 slots and letting the customer choose.\n  5. Collecting name, email, and phone.\n  6. Creating the appointment in Google Calendar.\n- Sends all replies through WhatsApp.\n\n### Requirements\n- Google Sheets (for FAQs and Services)\n- Google Calendar\n- WhatsApp integration in n8n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "cbd8557c-b7cf-4c3b-819f-185627c444c9",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        592,
        256
      ],
      "parameters": {
        "color": 5,
        "height": 368,
        "content": "\n\n\n\n\n\n\n\n\n## FAQ Handling\nThis step checks the FAQ Google Sheet (columns: id | question | answer).  \nIt retrieves the closest match to the customer\u2019s question and returns the answer.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "1f6d9f0f-6bfb-4b4d-ae94-5af40e4c395e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        256
      ],
      "parameters": {
        "color": 5,
        "height": 368,
        "content": "\n\n\n\n\n\n\n\n\n## Service Information\nThis step looks up the Services Google Sheet (columns: id | service_name | service_description | price).  \nIt provides details about available services and pricing.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2738b689-a5ab-4e15-bf33-c133cc07dc98",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1104,
        256
      ],
      "parameters": {
        "color": 6,
        "height": 368,
        "content": "\n\n\n\n\n\n\n\n\n## Schedule Availability\nThis step asks the customer for their preferred service, day, and time.  \nIt then queries Google Calendar for available slots and returns 3 options.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "796d6a12-5046-4d6a-aae2-b659d7bebe30",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1360,
        256
      ],
      "parameters": {
        "color": 6,
        "width": 224,
        "height": 368,
        "content": "\n\n\n\n\n\n\n\n\n## Appointment Confirmation\nOnce the customer selects a slot, we collect their name, email, and phone number.  \nThen, we create a Google Calendar event with this info using the set_appointment node.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a795a3d0-5f77-46ed-af14-8c68c057c88c",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        -336
      ],
      "parameters": {
        "color": 4,
        "width": 320,
        "height": 336,
        "content": "## WhatsApp Replies\nAll communication with the user is done through the agent_reply node (WhatsApp integration).  \nThis ensures the customer gets confirmations, slot options, and service details directly in chat.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "beef1f37-e019-49f3-a64b-944b3a448fe0",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        -48
      ],
      "parameters": {
        "color": 2,
        "width": 512,
        "height": 288,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n## Voice note transcribe\n** Voice Notes sent by customers are transformed into text for further processing by the AI Agent,"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "ai_chat": {
      "ai_languageModel": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "faq_base": {
      "ai_tool": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Audio": {
      "main": [
        [
          {
            "node": "Transcribe audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ai_memory": {
      "ai_memory": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Chat Router": {
      "main": [
        [
          {
            "node": "Agent Context",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download Voice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Message?": {
      "main": [
        [
          {
            "node": "Chat Router",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_schedule": {
      "ai_tool": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "get_services": {
      "ai_tool": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Agent Context": {
      "main": [
        [
          {
            "node": "Customer Service Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Voice": {
      "main": [
        [
          {
            "node": "Get Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set_appointment": {
      "ai_tool": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe audio": {
      "main": [
        [
          {
            "node": "Agent Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Customer Service Agent": {
      "main": [
        [
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Message Received": {
      "main": [
        [
          {
            "node": "Is Message?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}