{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "a5bab74c-c9ec-44cb-9103-4180ac1ddaa3",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -60
      ],
      "parameters": {
        "width": 1080,
        "height": 540,
        "content": "## Lead Capture Agent"
      },
      "typeVersion": 1
    },
    {
      "id": "1fadce0b-758c-4030-a7cc-d79718097bad",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1180,
        -40
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={{ $('Enquiry Form').item.json['Full Name'] }}",
            "Email": "={{ $('Enquiry Form').item.json.Email }}",
            "Error": "={{ $json.message.content.Reason }}",
            "Notes": "={{ $('Enquiry Form').item.json['How can we help you?'] }}",
            "Phone": "={{ $('Enquiry Form').item.json.Whatsapp }}",
            "Company": "={{ $('Enquiry Form').item.json['Company Name'] }}",
            "Message": "={{ $('OpenAI').item.json.message.content.Message }}",
            "Submitted_at": "={{ $('Enquiry Form').first().json.submittedAt }}"
          },
          "schema": [
            {
              "id": "Submitted_at",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Submitted_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Error",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Error",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Notes",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Chat_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Chat_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Submitted_at"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 352770436,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1JeAwOvYurzX54kGpktXAmQS54owHp7W_2HMbS5i4ghk/edit#gid=352770436",
          "cachedResultName": "Failed"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1JeAwOvYurzX54kGpktXAmQS54owHp7W_2HMbS5i4ghk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1JeAwOvYurzX54kGpktXAmQS54owHp7W_2HMbS5i4ghk/edit?usp=drivesdk",
          "cachedResultName": "Sales Agent"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "d7c49d33-65f7-4c30-bfb5-5ebcd5ac7200",
      "name": "OpenAI",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        560,
        60
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "GPT-4.1-MINI"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are Alex, a friendly, approachable, and slightly humorous human assistant. Your primary role is to personally connect with individuals who have submitted a contact form, gather more details efficiently, and be their main point of contact.\n\nContext of this interaction:\nYou have just reviewed a new Inquiry Form submission.\n\nThe user's full name is {{ $json['Full Name'] }}.\nCheck if they provided context in {{ $json['How can we help you?'] }}\nYour Task:\nCraft a short, to-the-point, and positive opening message to the user. Your message should be from you, Alex. It needs to be personalized and engaging, getting straight to how you can help.\n\nStart your message with \"Hey {{ $('Enquiry Form').item.json['Full Name'].split(\" \")[0] }}\nUse if they provided context in {{ $json['How can we help you?'] }}\nEnd with a clear and concise open-ended question that encourages them to share key details about what they are hoping to achieve or their specific needs.\nCrucially, you are the direct point of contact. Maintain a helpful, enthusiastic, and efficient tone. Do NOT mention that someone else will get back to them or that you are just passing along information.\n\nUSE THE WHATSAPP API TOOL TO ACTUALLY SEND THE MESSAGE\nthe attendees-ids is {{ $json.Whatsapp }}\nAnd if theres WHATSAPP API TOOL SENDS AN ERROR then \n\n#Output \n\n1. IF the Whatsapp API tool Send an error Output:\n{\n \"Status\": \"Fail\",\n \"Message\": \"the personalised message\",\n \"Reason\": \"reason why it failed\"\n}\n\n2. IF the Whatsapp API tool succeeds then output:\n{\n \"Status\": \"Success\",\n \"Message\": \"the personalised message\",\n \"chat_id\": \"the chat id\"\n \"message_id\": \"the message id\"\n}"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "dc8feaeb-0f0a-4b25-9f31-871c451c02fa",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        940,
        60
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "5852aeb9-926d-4aac-9835-77e210f4b38e",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.message.content.Status }}",
              "rightValue": "Fail"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ca0ad300-8589-40df-bbe9-7c1fb60bc5fe",
      "name": "Whatsapp API",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        860,
        320
      ],
      "parameters": {
        "url": "https://<YOUR_DSN>/api/v1/chats",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "attendees_ids",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "text",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', ``, 'string') }}"
            },
            {
              "name": "account_id",
              "value": "<YOUR_ACCOUNT_ID>"
            }
          ]
        },
        "toolDescription": "It Access the whatsapp api and sends the message",
        "headerParameters": {
          "parameters": [
            {
              "name": "X-API-KEY",
              "value": "<YOUR_API_KEY>"
            },
            {
              "name": "accept",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "dfed3abe-95b3-4fff-b383-cbab92eb5c53",
      "name": "Google Sheets3",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1180,
        160
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={{ $('Enquiry Form').first().json['Full Name'] }}",
            "Email": "={{ $('Enquiry Form').first().json.Email }}",
            "Notes": "={{ $('Enquiry Form').first().json['How can we help you?'] }}",
            "Phone": "={{ $('Enquiry Form').first().json.Whatsapp }}",
            "Chat_id": "={{ $('OpenAI').first().json.message.content.chat_id }}",
            "Company": "={{ $('Enquiry Form').first().json['Company Name'] }}",
            "Message": "={{ $('OpenAI').first().json.message.content.Message }}",
            "Message_id": "={{ $('OpenAI').first().json.message.content.message_id }}",
            "Submitted_at": "={{ $('Enquiry Form').first().json.submittedAt }}"
          },
          "schema": [
            {
              "id": "Submitted_at",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Submitted_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Notes",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Chat_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Chat_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Submitted_at"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1JeAwOvYurzX54kGpktXAmQS54owHp7W_2HMbS5i4ghk/edit#gid=0",
          "cachedResultName": "Successful"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1JeAwOvYurzX54kGpktXAmQS54owHp7W_2HMbS5i4ghk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1JeAwOvYurzX54kGpktXAmQS54owHp7W_2HMbS5i4ghk/edit?usp=drivesdk",
          "cachedResultName": "Sales Agent"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "e41f6b86-90ed-4831-adb3-7acc3f6cf0c9",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -200,
        -60
      ],
      "parameters": {
        "width": 500,
        "height": 540,
        "content": "## 1. Resources  \n### Sign up & get 7 days free trial by clicking on the link below.\n- ### [Unipile](https://www.unipile.com/)\n### Copy this Google Sheet Template\n- ### [Template](https://docs.google.com/spreadsheets/d/1YjGBau9aHueh8xCo8HlM1rg6S_qgOVyiDEP_W-ZdNN4/edit?usp=sharing)\n## 2. Setup Guide\n- ### Connect your Open AI credentials.\n- ### Setup the Google Sheet and select it in the workflow\n- ### Replace all the placeholders in Whatsapp API tool with your Unipile Credentials.\n- ### Embed the form on your site or share as it is however, I recommend using your own form and connect it using webhook.\n## 3. Help\n- ### Read This [Detailed Setup Guide](https://drive.google.com/file/d/1ofDtmxYJ46ca50ELkrvfR45SMKQ84Jaj/view?usp=sharing) if need help\n- ### Reach out to us via [Email](mailto:info.gainflow@gmail.com) if need help\n- ### Find more real world use workflows by clicking [HERE](https://docs.google.com/document/d/1RACo90h-QwKA4hEZSlOQZsyw4iB5-43JM2l0s4lpuoY/edit?usp=sharing)"
      },
      "typeVersion": 1
    },
    {
      "id": "1f39b8a1-a42d-424c-b6b1-b14e1d1a50e9",
      "name": "Enquiry Form",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        360,
        60
      ],
      "parameters": {
        "options": {},
        "formTitle": "Inquiry Form",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Full Name",
              "requiredField": true
            },
            {
              "fieldLabel": "Email",
              "requiredField": true
            },
            {
              "fieldLabel": "Whatsapp"
            },
            {
              "fieldLabel": "Company Name"
            },
            {
              "fieldLabel": "How can we help you?"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "63ad7169-79c1-471a-82f1-191d0281bcbd",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        240
      ],
      "parameters": {
        "color": 4,
        "width": 600,
        "height": 220,
        "content": "## Why Unipile? beacause it lets you send messages without any prior chat history and also lets you connect your personal whatsapp."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Google Sheets3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enquiry Form": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Whatsapp API": {
      "ai_tool": [
        [
          {
            "node": "OpenAI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}