{
  "name": "My workflow 6",
  "tags": [],
  "nodes": [
    {
      "id": "713c93c4-7a8a-4bed-910f-e4f1a7126c66",
      "name": "Cron (every 6h)",
      "type": "n8n-nodes-base.cron",
      "position": [
        -112,
        64
      ],
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyX"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "66a02cab-fd51-43e4-8cab-d5e6e76cc759",
      "name": "Window (last 2h)",
      "type": "n8n-nodes-base.code",
      "position": [
        80,
        64
      ],
      "parameters": {
        "jsCode": "const now=Math.floor(Date.now()/1000);return[{json:{from:now-2*3600,to:now}}];"
      },
      "typeVersion": 2
    },
    {
      "id": "917b32a0-29be-4037-ae3b-a4482769ff52",
      "name": "HTTP \u2192 Razorpay Orders",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        320,
        64
      ],
      "parameters": {
        "url": "https://api.razorpay.com/v1/orders",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth"
      },
      "credentials": {
        "httpBasicAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "dfa0f90a-8449-4595-9ed9-e50e765f8f7f",
      "name": "Filter status=created + Format",
      "type": "n8n-nodes-base.code",
      "position": [
        528,
        64
      ],
      "parameters": {
        "jsCode": "function rupees(p){ return Math.round((p||0)/100); }\nfunction sumPromo(ps){ return (ps||[]).reduce((s,p)=> s + (p?.value||0), 0); }\nfunction pickName(o){ return o?.customer_details?.shipping_address?.name || o?.customer_details?.name || o?.notes?.name || 'Unknown'; }\nfunction pickContact(o){ return o?.customer_details?.contact || o?.customer_details?.shipping_address?.contact || o?.notes?.contact || '-'; }\nfunction pickEmail(o){ return o?.customer_details?.email || o?.notes?.email || '-'; }\nfunction fmtIST(sec){ return new Date((sec||Math.floor(Date.now()/1000))*1000).toLocaleString('en-IN',{ timeZone:'Asia/Kolkata', hour12:false }); }\n\nconst body   = items[0]?.json;\nconst orders = Array.isArray(body) ? body : (body?.items || [body]).filter(Boolean);\nconst wanted = orders.filter(o => ['created','orderpending'].includes(String(o?.status||'').toLowerCase()));\nif (!wanted.length) return [];\n\nconst blocks = wanted.slice(0, 40).map(o => {\n  const line  = (o?.line_items_total ?? o?.customer_details?.line_items_total ?? o?.amount ?? 0);\n  const cod   = o?.cod_fee || 0;\n  const ship  = o?.shipping_fee || 0;\n  const promo = sumPromo(o?.promotions);\n  const val   = Math.max(0, line + cod + ship - promo);\n  const name  = pickName(o);\n  const email = pickEmail(o);\n  const contact = pickContact(o);\n  const rawStatus = String(o?.status||'').toLowerCase();\n  const statusLabel = rawStatus === 'created' ? 'abandoned' : rawStatus;\n  const when  = fmtIST(o?.created_at);\n  return `name: ${name}\\nvalue: ${rupees(val)}\\nstatus: ${statusLabel}\\ncontact: ${contact}\\nemail: ${email}\\ntime: ${when}`;\n}).join('\\n\\n');\n\nconst msg = `\ud83d\udfe1 abandoned via webhook\\n\\n${blocks}`;\nreturn [{ json: { msg } }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "bd3540d8-a723-428d-bccf-f720d8c27cc2",
      "name": "Telegram \u2192 Me",
      "type": "n8n-nodes-base.telegram",
      "position": [
        752,
        64
      ],
      "parameters": {
        "text": "={{$json.msg}}",
        "chatId": "YOUR_TELEGRAM_CHAT_ID",
        "additionalFields": {}
      },
      "typeVersion": 1
    },
    {
      "id": "b1fe8a8c-5e1d-4c47-9b9e-6f05fe076547",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -48
      ],
      "parameters": {
        "width": 176,
        "height": 80,
        "content": "You can set you timer here"
      },
      "typeVersion": 1
    },
    {
      "id": "edaa6b2c-9366-4dce-bc3b-4e32cc8886f7",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        240
      ],
      "parameters": {
        "width": 176,
        "height": 96,
        "content": "Here you can customise the time window that razorpay picks up"
      },
      "typeVersion": 1
    },
    {
      "id": "4c24b401-1cda-4b53-96df-f81e45d95377",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        -64
      ],
      "parameters": {
        "width": 176,
        "height": 96,
        "content": "Add your razorpay creds here "
      },
      "typeVersion": 1
    },
    {
      "id": "8fb5f6ca-bd3c-4ae1-ba1d-ea50ac08aad3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        240
      ],
      "parameters": {
        "width": 176,
        "height": 96,
        "content": "Avoid customising this. This basically sorts and formats the data to send\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ec8ebe56-5e03-4050-80eb-7f556ba25bfb",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        -64
      ],
      "parameters": {
        "width": 176,
        "height": 96,
        "content": "Set your telegram creds here"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "",
  "connections": {
    "Cron (every 6h)": {
      "main": [
        [
          {
            "node": "Window (last 2h)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Window (last 2h)": {
      "main": [
        [
          {
            "node": "HTTP \u2192 Razorpay Orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP \u2192 Razorpay Orders": {
      "main": [
        [
          {
            "node": "Filter status=created + Format",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter status=created + Format": {
      "main": [
        [
          {
            "node": "Telegram \u2192 Me",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}