{
    "name": "ashishgoswami.in — Payments & Leads",
    "nodes": [
        {
            "parameters": {
                "httpMethod": "POST",
                "path": "ag-site",
                "responseMode": "responseNode",
                "options": {
                    "allowedOrigins": "https://www.ashishgoswami.in,https://ashishgoswami.in"
                }
            },
            "id": "a1",
            "name": "Website Webhook",
            "type": "n8n-nodes-base.webhook",
            "typeVersion": 2,
            "position": [
                0,
                0
            ]
        },
        {
            "parameters": {
                "jsCode": "// Normalize website events → one row per order/lead\nconst b = $input.first().json.body || {};\nconst clean = v => String(v ?? '').replace(/[<>]/g, '').trim().slice(0, 500);\nconst now = new Date().toISOString();\nconst biz = /^[A-Z]{3}$/.test(b.biz_code || '') ? b.biz_code : 'GEN'; // services + teacher tags (MTH, SCI…)\nconst isLead = b.event === 'lead';\nconst id = isLead\n  ? 'AG-LEAD-' + biz + '-' + now.slice(2,10).replace(/-/g,'') + '-' + Math.floor(1000 + Math.random()*9000)\n  : clean(b.order_id);\nif (!isLead && !/^AG-[A-Z]{3}-\\d{6}-\\d{4}$/.test(id)) throw new Error('Bad order id');\nconst row = {\n  order_id: id,\n  event: clean(b.event),\n  status: isLead ? 'new_lead' : clean(b.status),\n  biz_code: biz,\n  biz_name: clean(b.biz_name),\n  service_name: clean(b.service_name),\n  amount: isLead ? '' : Number(b.amount) || 0,\n  name: clean(b.name),\n  mobile: clean(b.mobile).replace(/\\D/g,'').slice(-10),\n  email: clean(b.email),\n  company: clean(b.company),\n  city: clean(b.city),\n  utr: clean(b.utr).replace(/\\D/g,''),\n  message: clean(b.message),\n  page: clean(b.page),\n  created_at: clean(b.created_at || b.ts) || now,\n  updated_at: now,\n  sheet: isLead ? 'Leads' : 'Payments',\n  notify: b.event !== 'payment_initiated'\n};\nreturn [{ json: row }];"
            },
            "id": "a2",
            "name": "Normalize & Tag",
            "type": "n8n-nodes-base.code",
            "typeVersion": 2,
            "position": [
                240,
                0
            ]
        },
        {
            "parameters": {
                "operation": "appendOrUpdate",
                "documentId": {
                    "__rl": true,
                    "value": "PASTE_GOOGLE_SHEET_ID",
                    "mode": "id"
                },
                "sheetName": {
                    "__rl": true,
                    "value": "={{ $json.sheet }}",
                    "mode": "name"
                },
                "columns": {
                    "mappingMode": "defineBelow",
                    "value": {
                        "order_id": "={{ $json.order_id }}",
                        "event": "={{ $json.event }}",
                        "status": "={{ $json.status }}",
                        "biz_code": "={{ $json.biz_code }}",
                        "biz_name": "={{ $json.biz_name }}",
                        "service_name": "={{ $json.service_name }}",
                        "amount": "={{ $json.amount }}",
                        "name": "={{ $json.name }}",
                        "mobile": "={{ $json.mobile }}",
                        "email": "={{ $json.email }}",
                        "company": "={{ $json.company }}",
                        "city": "={{ $json.city }}",
                        "utr": "={{ $json.utr }}",
                        "message": "={{ $json.message }}",
                        "page": "={{ $json.page }}",
                        "created_at": "={{ $json.created_at }}",
                        "updated_at": "={{ $json.updated_at }}"
                    },
                    "matchingColumns": [
                        "order_id"
                    ],
                    "schema": [
                        {
                            "id": "order_id",
                            "displayName": "order_id",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "event",
                            "displayName": "event",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "status",
                            "displayName": "status",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "biz_code",
                            "displayName": "biz_code",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "biz_name",
                            "displayName": "biz_name",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "service_name",
                            "displayName": "service_name",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "amount",
                            "displayName": "amount",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "name",
                            "displayName": "name",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "mobile",
                            "displayName": "mobile",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "email",
                            "displayName": "email",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "company",
                            "displayName": "company",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "city",
                            "displayName": "city",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "utr",
                            "displayName": "utr",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "message",
                            "displayName": "message",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "page",
                            "displayName": "page",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "created_at",
                            "displayName": "created_at",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        },
                        {
                            "id": "updated_at",
                            "displayName": "updated_at",
                            "required": false,
                            "defaultMatch": false,
                            "display": true,
                            "type": "string",
                            "canBeUsedToMatch": true
                        }
                    ]
                },
                "options": []
            },
            "id": "a3",
            "name": "Google Sheets (Payments / Leads)",
            "type": "n8n-nodes-base.googleSheets",
            "typeVersion": 4.5,
            "position": [
                480,
                0
            ]
        },
        {
            "parameters": {
                "respondWith": "json",
                "responseBody": "={{ { ok: true, id: $('Normalize & Tag').item.json.order_id } }}",
                "options": []
            },
            "id": "a4",
            "name": "Respond OK",
            "type": "n8n-nodes-base.respondToWebhook",
            "typeVersion": 1.100000000000000088817841970012523233890533447265625,
            "position": [
                720,
                -120
            ]
        },
        {
            "parameters": {
                "conditions": {
                    "options": {
                        "caseSensitive": true,
                        "leftValue": "",
                        "typeValidation": "loose"
                    },
                    "conditions": [
                        {
                            "id": "c1",
                            "leftValue": "={{ $('Normalize & Tag').item.json.notify }}",
                            "rightValue": true,
                            "operator": {
                                "type": "boolean",
                                "operation": "true",
                                "singleValue": true
                            }
                        }
                    ],
                    "combinator": "and"
                },
                "options": []
            },
            "id": "a5",
            "name": "Notify?",
            "type": "n8n-nodes-base.if",
            "typeVersion": 2,
            "position": [
                720,
                100
            ]
        },
        {
            "parameters": {
                "chatId": "PASTE_YOUR_TELEGRAM_CHAT_ID",
                "text": "={{ $('Normalize & Tag').item.json.event === 'lead' ? '🟢 New LEAD — ' + $('Normalize & Tag').item.json.biz_code : '💰 PAYMENT to verify — ' + $('Normalize & Tag').item.json.biz_code }}\nBiz: {{ $('Normalize & Tag').item.json.biz_name }}\nService: {{ $('Normalize & Tag').item.json.service_name }}\nAmount: ₹{{ $('Normalize & Tag').item.json.amount }}\nOrder: {{ $('Normalize & Tag').item.json.order_id }}\nUTR: {{ $('Normalize & Tag').item.json.utr }}\nName: {{ $('Normalize & Tag').item.json.name }} ({{ $('Normalize & Tag').item.json.mobile }})\nCity: {{ $('Normalize & Tag').item.json.city }}\nMsg: {{ $('Normalize & Tag').item.json.message }}\n\nVerify UTR in bank app, then mark 'verified' = YES in Sheet.",
                "additionalFields": {
                    "appendAttribution": false
                }
            },
            "id": "a6",
            "name": "Telegram Alert to Ashish",
            "type": "n8n-nodes-base.telegram",
            "typeVersion": 1.1999999999999999555910790149937383830547332763671875,
            "position": [
                960,
                80
            ]
        }
    ],
    "connections": {
        "Website Webhook": {
            "main": [
                [
                    {
                        "node": "Normalize & Tag",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Normalize & Tag": {
            "main": [
                [
                    {
                        "node": "Google Sheets (Payments / Leads)",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Google Sheets (Payments / Leads)": {
            "main": [
                [
                    {
                        "node": "Respond OK",
                        "type": "main",
                        "index": 0
                    },
                    {
                        "node": "Notify?",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Notify?": {
            "main": [
                [
                    {
                        "node": "Telegram Alert to Ashish",
                        "type": "main",
                        "index": 0
                    }
                ],
                []
            ]
        }
    },
    "settings": {
        "executionOrder": "v1"
    },
    "active": false
}