{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "8ba000c7-4b3d-4877-923e-363d74c5609e",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1472,
        1008
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 10
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "c05c0117-a034-4c42-928e-01edaca1aef8",
      "name": "Send WhatsApp Notification",
      "type": "n8n-nodes-base.twilio",
      "position": [
        2368,
        928
      ],
      "parameters": {
        "to": "=+917984780565",
        "from": "+1234567890",
        "message": "={{ $json.message_text }}",
        "options": {},
        "toWhatsapp": true
      },
      "credentials": {
        "twilioApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cd375f45-06e8-4411-a622-5d3c6b8b4e13",
      "name": "Get Pickup Scheduled Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1696,
        1008
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $today.format('MM-dd-yyyy') }}",
              "lookupColumn": "Pickup Date"
            },
            {
              "lookupValue": "Pending",
              "lookupColumn": "Status"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg/edit?usp=drivesdk",
          "cachedResultName": "Return Pickup Data"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "e872f686-6c13-451f-9487-6c52a3df6099",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        2144,
        1008
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "3510b4bc-0d18-4cd7-b782-66eb1b86edae",
      "name": "Place Voice Call Reminder",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2592,
        928
      ],
      "parameters": {
        "url": "https://api.twilio.com/2010-04-01/Accounts/YOUR_AWS_SECRET_KEY_HERE.json",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "Twiml",
              "value": "=<Response><Say voice='Polly.Joanna'><prosody rate='slow' pitch='medium' volume='loud'> {{ $('Loop Over Items').item.json.voice_message }}</prosody></Say></Response>"
            },
            {
              "name": "To",
              "value": "+1234567890"
            },
            {
              "name": "From",
              "value": "+1234567890"
            }
          ]
        },
        "nodeCredentialType": "twilioApi"
      },
      "typeVersion": 4.3
    },
    {
      "id": "4099920f-0be7-44f0-ab25-a7b85ca91933",
      "name": "Update Reminder Status",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2864,
        1008
      ],
      "parameters": {
        "columns": {
          "value": {
            "Status": "Reminder Sent",
            "Phone Number": "={{ $('Loop Over Items').item.json.phone }}"
          },
          "schema": [
            {
              "id": "Order ID",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Order ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Customer Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone Number",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Phone Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Product",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Product",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer Address",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Customer Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Return Reason",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Return Reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Pickup Date",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Pickup Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Phone Number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg/edit?usp=drivesdk",
          "cachedResultName": "Return Pickup Data"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "53ca04ed-9108-4e4b-b8c6-bbdefdb59b04",
      "name": "Create WhatsApp & Voice Call Message",
      "type": "n8n-nodes-base.code",
      "position": [
        1936,
        1008
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// const customerName = $json[\"Customer Name\"];\n// const phone = $json[\"Phone Number\"];\n// const product = $json.Product;\n// const address = $json[\"Customer Address\"];\n// const returnReason = $json[\"Return Reason\"];\n// const pickupDate = $json[\"Pickup Date\"];\n// const orderId = $json[\"Order ID\"];\n\n// const message = `Hello ${customerName},\\n\\nThis is a reminder that your return pickup for ${product} is scheduled for today ${pickupDate}.\\n\\nPickup Address: ${address}\\nReturn Reason: ${returnReason}\\n\\nPlease keep your package ready for collection.\\n\\nThank you!`;\n\n// return {\n//   message_text: message,\n//   phone: phone,\n//   order_id: orderId,\n//   customer_name: customerName,\n//   product: product,\n//   row_id: $input.item.json.row_id\n// };\n\nconst customerName = $json[\"Customer Name\"];\nconst phone = $json[\"Phone Number\"];\nconst product = $json.Product;\nconst address = $json[\"Customer Address\"];\nconst returnReason = $json[\"Return Reason\"];\nconst pickupDate = $json[\"Pickup Date\"];\nconst orderId = $json[\"Order ID\"];\n\n// SMS / WhatsApp message\nconst message = `Hello ${customerName},\\n\\nThis is a reminder that your return pickup for ${product} is scheduled for today.\\n\\nPickup Address: ${address}\\nReturn Reason: ${returnReason}\\n\\nPlease keep your package ready for collection.Pickup will be completed before 11PM.\\n\\nThank you!`;\n\n// VOICE MESSAGE (for Twilio <Say>)\nconst voiceMessage = \n  `Hello ${customerName}. ` +\n  `This is a reminder that your return pickup for ${product} is scheduled today. ` +\n  `The pickup address is ${address}. ` +\n  `and pickup will be completed before 11PM. ` +\n  `Please keep your package ready for collection. Thank you.`;\n\n// Return both\nreturn {\n  message_text: message,\n  voice_message: voiceMessage,\n  phone: phone,\n  order_id: orderId,\n  customer_name: customerName,\n  product: product,\n  row_id: $input.item.json.row_id\n};\n"
      },
      "typeVersion": 2
    },
    {
      "id": "dfefb95b-f47d-4029-b2b1-ad8e15a024ee",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1440,
        1280
      ],
      "parameters": {
        "color": 6,
        "width": 464,
        "height": 144,
        "content": "## Google sheet\n\nhttps://docs.google.com/spreadsheets/d/1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg/edit?usp=sharing"
      },
      "typeVersion": 1
    },
    {
      "id": "8b8aba48-8b61-4592-9c5e-7b6fac9e3cd5",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1072,
        848
      ],
      "parameters": {
        "width": 356,
        "height": 572,
        "content": "## How it works\nThis workflow automates return pickup reminders for e-commerce orders. Every day at 10 AM, it checks a Google Sheet for pending pickups scheduled for today, then sends personalized WhatsApp messages and voice call reminders to customers. After each notification is sent, the status is updated to \"Reminder Sent\" in the sheet.\n\n## Setup steps\n1. **Connect Google Sheets** - Add OAuth2 credentials to access your pickup data spreadsheet\n2. **Connect Twilio** - Add API credentials for WhatsApp and voice call capabilities\n3. **Update phone numbers** - Replace placeholder numbers (+917984780565, +15707984747) with your actual Twilio and customer numbers\n4. **Verify sheet structure** - Ensure your Google Sheet has columns: Order ID, Customer Name, Phone Number, Product, Customer Address, Return Reason, Pickup Date, Status\n5. **Test with one record** - Create a test entry with today's date and \"Pending\" status"
      },
      "typeVersion": 1
    },
    {
      "id": "bf22edaf-70c9-4f80-83d7-dd578c714f98",
      "name": "Data Retrieval",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1440,
        848
      ],
      "parameters": {
        "color": 7,
        "width": 646,
        "height": 412,
        "content": "## Data Retrieval\nFetches today's pending pickups from Google Sheets and formats notification messages."
      },
      "typeVersion": 1
    },
    {
      "id": "d5341549-8f2c-4cbd-a0d5-25535ae619d3",
      "name": "Customer Notifications",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2304,
        768
      ],
      "parameters": {
        "color": 7,
        "width": 440,
        "height": 492,
        "content": "## Customer Notifications\nProcesses each pickup one-by-one, sending WhatsApp message followed by automated voice call reminder."
      },
      "typeVersion": 1
    },
    {
      "id": "b54c3673-7ef1-4731-bae8-1d051984e483",
      "name": "Status Update",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2752,
        768
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 492,
        "content": "## Status Update\nMarks the pickup status as \"Reminder Sent\" in the sheet, then loops back for the next customer."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Send WhatsApp Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Pickup Scheduled Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Reminder Status": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Pickup Scheduled Data": {
      "main": [
        [
          {
            "node": "Create WhatsApp & Voice Call Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Place Voice Call Reminder": {
      "main": [
        [
          {
            "node": "Update Reminder Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp Notification": {
      "main": [
        [
          {
            "node": "Place Voice Call Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create WhatsApp & Voice Call Message": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}