{
  "name": "Multi-channel client onboarding",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "onboarding/lead",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "cf7663a7-b820-4810-a608-83f99605f147",
      "name": "New lead",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "webhookId": "924270bd-c627-453d-a903-5ca9c3c8c16c"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_ME",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Leads",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        }
      },
      "id": "7d79d408-fbd9-4d77-a2b7-c0ae137436fb",
      "name": "Log lead",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        512,
        300
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "REPLACE_ME",
          "name": "Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "REPLACE_ME",
        "recipientPhoneNumber": "={{ $json.phone }}",
        "textBody": "Hi {{ $json.name }}, to get you set up please reply with your full name, company name and registration number."
      },
      "id": "2f090c6e-413e-4600-ada4-708b3a1bb1ea",
      "name": "Ask for KYC details",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        784,
        300
      ],
      "credentials": {
        "whatsAppApi": {
          "id": "REPLACE_ME",
          "name": "WhatsApp Business"
        }
      }
    },
    {
      "parameters": {
        "updates": [
          "messages"
        ]
      },
      "id": "7decaff0-79e4-46fa-ab4e-baf00dc673a1",
      "name": "KYC reply",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "typeVersion": 1,
      "position": [
        240,
        592
      ],
      "credentials": {
        "whatsAppTriggerApi": {
          "id": "REPLACE_ME",
          "name": "WhatsApp trigger"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const text = ($json.messages?.[0]?.text?.body || '').trim();\nconst has = (re) => re.test(text);\nconst missing = [];\nif (text.split(/\\s+/).length < 4) missing.push('full name');\nif (!has(/[A-Za-z]{3,}\\s+(LLC|Ltd|Pvt|Inc|FZE|FZCO)/i)) missing.push('company name');\nif (!has(/\\b[A-Z0-9-]{6,}\\b/)) missing.push('registration number');\nreturn [{ json: { phone: $json.contacts?.[0]?.wa_id, text, missing, complete: missing.length === 0 } }];"
      },
      "id": "78d03b6b-97ce-475d-a801-c4b22f64c2e0",
      "name": "Validate details",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        512,
        592
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.complete }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "8f79b674-bec7-4511-a6ff-f83cad7a54ce",
      "name": "Complete?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        784,
        592
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "REPLACE_ME",
        "recipientPhoneNumber": "={{ $json.phone }}",
        "textBody": "Thanks. I still need: {{ $json.missing.join(', ') }}."
      },
      "id": "89e98a40-f593-4c05-a0c5-582935c30a1e",
      "name": "Ask again",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        1056,
        723
      ],
      "credentials": {
        "whatsAppApi": {
          "id": "REPLACE_ME",
          "name": "WhatsApp Business"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.razorpay.com/v1/payment_links",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { amount: 4900000, currency: \"INR\", description: \"Onboarding fee\", customer: { contact: $json.phone }, notify: { sms: false, email: false } } }}"
      },
      "id": "26e98652-0637-40b0-a108-5985169dea84",
      "name": "Create payment link",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1056,
        534
      ],
      "credentials": {
        "httpBasicAuth": {
          "id": "REPLACE_ME",
          "name": "Razorpay key pair"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "REPLACE_ME",
        "recipientPhoneNumber": "={{ $(\"Validate details\").item.json.phone }}",
        "textBody": "Your details are verified. Pay here to finish onboarding: {{ $json.short_url }}"
      },
      "id": "a14a1d29-370a-4f8e-a011-ab4680ff8e7f",
      "name": "Send payment link",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        1328,
        534
      ],
      "credentials": {
        "whatsAppApi": {
          "id": "REPLACE_ME",
          "name": "WhatsApp Business"
        }
      }
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "onboarding/razorpay",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "06931080-1d11-4446-a12f-bf6c629f546a",
      "name": "Payment event",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        913
      ],
      "webhookId": "8e58d694-10d3-477a-a6a6-5faec8cd3e11"
    },
    {
      "parameters": {
        "jsCode": "const crypto = require('crypto');\nconst body = JSON.stringify($json.body);\nconst expected = crypto.createHmac('sha256', $env.RAZORPAY_WEBHOOK_SECRET).update(body).digest('hex');\nif (expected !== $json.headers['x-razorpay-signature']) { throw new Error('Bad Razorpay signature'); }\nreturn [{ json: { order: $json.body.payload.payment_link.entity.id, status: $json.body.event } }];"
      },
      "id": "f0436d93-4f9f-4ba0-a054-c7f0488fe896",
      "name": "Verify signature",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        512,
        913
      ]
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_ME",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Leads",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "order": "={{ $json.order }}",
            "status": "paid"
          },
          "matchingColumns": [
            "order"
          ]
        }
      },
      "id": "d04f6cf1-618d-4936-a5fa-0b6ee23620d2",
      "name": "Mark paid",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        784,
        913
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "REPLACE_ME",
          "name": "Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "onboarding",
          "mode": "name"
        },
        "text": "Onboarding complete and paid: {{ $(\"Verify signature\").item.json.order }}",
        "otherOptions": {}
      },
      "id": "a4e53801-5830-4df1-aa15-71df78174f24",
      "name": "Tell the team",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1056,
        913
      ],
      "credentials": {
        "slackApi": {
          "id": "REPLACE_ME",
          "name": "Slack"
        }
      }
    }
  ],
  "connections": {
    "New lead": {
      "main": [
        [
          {
            "node": "Log lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log lead": {
      "main": [
        [
          {
            "node": "Ask for KYC details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "KYC reply": {
      "main": [
        [
          {
            "node": "Validate details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate details": {
      "main": [
        [
          {
            "node": "Complete?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Complete?": {
      "main": [
        [
          {
            "node": "Create payment link",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ask again",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create payment link": {
      "main": [
        [
          {
            "node": "Send payment link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Payment event": {
      "main": [
        [
          {
            "node": "Verify signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify signature": {
      "main": [
        [
          {
            "node": "Mark paid",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark paid": {
      "main": [
        [
          {
            "node": "Tell the team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "From a new lead to a paid, verified client without a person in the loop."
  },
  "tags": []
}