{
  "name": "Pickup Reminders via WhatsApp & Voice Call",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 10
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -272,
        -80
      ],
      "id": "0f962ad6-1304-4da1-b3b3-143fec9106c4",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "from": "+14155238886",
        "to": "=+15555550102",
        "toWhatsapp": true,
        "message": "={{ $json.message_text }}",
        "options": {}
      },
      "id": "24512dbb-6b03-48d0-9844-6994af2be604",
      "name": "Send WhatsApp Notification",
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        576,
        -64
      ],
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg",
          "mode": "list",
          "cachedResultName": "Return Pickup Data"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1"
        },
        "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": "895539a4-1a98-492e-a724-9cd07594afe0",
      "name": "Get Pickup Scheduled Data",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "GojUvCMDXbhY8HrB",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        336,
        -80
      ],
      "id": "ebbd0a07-d31c-48c1-9b40-bc13944031f5",
      "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": "+15555550102"
            },
            {
              "name": "From",
              "value": "+15555550104"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        736,
        -64
      ],
      "id": "0493d74f-2862-41a6-9cf9-3b0105b87b31",
      "name": "Place Voice Call Reminder",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1P-rwG-J_Wqj_SAVIgQC49qzp6bA42v-S5Y9vwBASwDg",
          "mode": "list",
          "cachedResultName": "Return Pickup Data"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1"
        },
        "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": "050de8ae-8815-4bff-afc9-490e9a26f549",
      "name": "Update Reminder Status",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        912,
        -64
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "GojUvCMDXbhY8HrB",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "426f7377-f5df-49d5-87f8-c896a6e93493",
      "name": "Create WhatsApp & Voice Call Message",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        128,
        -80
      ]
    },
    {
      "parameters": {
        "content": "## Google sheet\nCreate your own spreadsheet with these tabs/columns, then select it in the Google Sheets nodes:\n- **Return Pickup Data → Sheet1**: `Pickup Date`, `Status`, `Phone Number`",
        "height": 144,
        "width": 352
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -272,
        -256
      ],
      "id": "7c0aa5b5-a689-4c0e-81f9-900474f9611f",
      "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": "69324e5d-1337-4484-b904-7d78005bba60",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "f1c26778ec36097a9722a22c47c5e9c01f00b8862dadd0121ec118026a370fa6"
  },
  "id": "QpU1z2QZgml6PC5R",
  "tags": []
}