{
  "name": "E-commerce Return Pickup Auto Reminder",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 10
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -272,
        -80
      ],
      "id": "11c2e641-96e5-4503-af57-f9d68e1067a9",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "from": "+14155238886",
        "to": "=+917984780565",
        "toWhatsapp": true,
        "message": "={{ $json.message_text }}",
        "options": {}
      },
      "id": "e2a40e76-f691-4d64-8099-1b0c39ce718e",
      "name": "Send WhatsApp Notification",
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        576,
        -64
      ],
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg",
          "mode": "list",
          "cachedResultName": "Return Pickup Data",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg/edit#gid=0"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "Pickup Date",
              "lookupValue": "={{ $today.format('MM-dd-yyyy') }}"
            },
            {
              "lookupColumn": "Status",
              "lookupValue": "Pending"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        -64,
        -80
      ],
      "id": "bf7129d5-5543-4660-a43f-ce27d453764d",
      "name": "Get Pickup Scheduled Data",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "WdaCQmtoNquNSoAA",
          "name": "Suresh_Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        336,
        -80
      ],
      "id": "6fe2c5f3-5084-4cf0-a7b7-393fa6b27b11",
      "name": "Loop Over Items"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.twilio.com/2010-04-01/Accounts/AC04242f0bc72f9e169f149705db3ac498/Calls.json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "twilioApi",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "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": "+917984780565"
            },
            {
              "name": "From",
              "value": "+15707984747"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        736,
        -64
      ],
      "id": "b45b1bbe-5dfe-4021-8e65-3efeb7cb06f6",
      "name": "Place Voice Call Reminder",
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg",
          "mode": "list",
          "cachedResultName": "Return Pickup Data",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Status": "Reminder Sent",
            "Phone Number": "={{ $('Loop Over Items').item.json.phone }}"
          },
          "matchingColumns": [
            "Phone Number"
          ],
          "schema": [
            {
              "id": "Order ID",
              "displayName": "Order ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Customer Name",
              "displayName": "Customer Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Phone Number",
              "displayName": "Phone Number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Product",
              "displayName": "Product",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Customer Address",
              "displayName": "Customer Address",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Return Reason",
              "displayName": "Return Reason",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Pickup Date",
              "displayName": "Pickup Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Status",
              "displayName": "Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "2c535d13-7515-4d5b-99ff-199e1390fc4e",
      "name": "Update Reminder Status",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        912,
        -64
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "WdaCQmtoNquNSoAA",
          "name": "Suresh_Google Sheets"
        }
      }
    },
    {
      "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"
      },
      "id": "d75236a6-7790-4853-885c-4f77aa243952",
      "name": "Create WhatsApp & Voice Call Message",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        128,
        -80
      ]
    },
    {
      "parameters": {
        "content": "## Google sheet\n\nhttps://docs.google.com/spreadsheets/d/1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg/edit?usp=sharing",
        "height": 144,
        "width": 352
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -272,
        -256
      ],
      "id": "51e18e45-8703-4d99-9bfc-ad577d629ebb",
      "name": "Sticky Note"
    }
  ],
  "pinData": {},
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Pickup Scheduled Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp Notification": {
      "main": [
        [
          {
            "node": "Place Voice Call Reminder",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Get Pickup Scheduled Data": {
      "main": [
        [
          {
            "node": "Create WhatsApp & Voice Call Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Send WhatsApp Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Place Voice Call Reminder": {
      "main": [
        [
          {
            "node": "Update Reminder Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create WhatsApp & Voice Call Message": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Reminder Status": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "0c11bf64-29c2-4990-9ff7-334002b8e72a",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "9272721148ea09184b6bbb7ce6219dab088562dd450e2df8280d57c2e34c7d84"
  },
  "id": "Lia33yeHMTNLyBkH",
  "tags": []
}