{
  "name": "e-POD (Electronic Proof of Delivery) System",
  "nodes": [
    {
      "parameters": {
        "url": "={{ $json.body.MediaUrl0 }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "pod_image"
            }
          }
        }
      },
      "id": "1973e0e8-c4e0-48b5-af8b-0f26ec2888d4",
      "name": "Download POD Image",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -304,
        224
      ],
      "credentials": {
        "twilioApi": {
          "id": "1reoIdfIK8A8CfHr",
          "name": "heet infyom - Twilio"
        },
        "httpBasicAuth": {
          "id": "jXSy8JNaKt36c3EV",
          "name": "twilio - credential 6"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=You are given a POD image URL.\n\nAnalyze this delivery POD image and extract:\n\n- customer_name\n- delivery_date\n- invoice_number\n- signature_present (true/false)\n- stamp_present (true/false)\n- is_valid_pod (true/false)\n\nReturn ONLY valid JSON.\nDo NOT return any text.",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "=You are a delivery verification assistant. Analyze POD (Proof of Delivery) images and extract key information accurately."
        }
      },
      "id": "71b8c1a7-04c4-487d-a24a-35306d8fb7e9",
      "name": "Analyze POD Image",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        368,
        224
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "gpt-4o"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "9aa4b98a-3f73-491e-82cd-1f96ab3b3523",
      "name": "GPT-4 Vision Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        352,
        448
      ],
      "credentials": {
        "openAiApi": {
          "id": "zHTJ5AI7kBmTnuvv",
          "name": "InfyOm"
        }
      }
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"customer_name\": { \"type\": \"string\" },\n    \"delivery_date\": { \"type\": [\"string\", \"null\"] },\n    \"invoice_number\": { \"type\": [\"string\", \"null\"] },\n    \"signature_present\": { \"type\": \"boolean\" },\n    \"stamp_present\": { \"type\": \"boolean\" },\n    \"is_valid_pod\": { \"type\": \"boolean\" }\n  }\n}"
      },
      "id": "88c7068b-1596-4109-a1a2-50eea6022d26",
      "name": "POD Data Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        512,
        448
      ]
    },
    {
      "parameters": {
        "inputDataFieldName": "pod_image",
        "name": "={{ 'POD_' + $('POD WhatsApp Webhook Trigger').item.json.body.WaId + '_' + $now.toFormat('yyyyLLdd') + '.jpg' }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "value": "1tFdTx-tE7OzKMmolGvE9ZxK9nTJGVbD5",
          "mode": "list",
          "cachedResultName": "E-POD n8n Demo",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1tFdTx-tE7OzKMmolGvE9ZxK9nTJGVbD5"
        },
        "options": {}
      },
      "id": "6a711d8c-41f7-4a61-aa76-843f098201ff",
      "name": "Save POD to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -80,
        160
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Zi3zTOHN5WQkSTmP",
          "name": "Heet - Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "mode": "chooseBranch",
        "useDataOfInput": 2
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        144,
        224
      ],
      "id": "34343341-c868-40f7-8ee4-5d31d2bb5223",
      "name": "Merge POD Data"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "id-1",
              "leftValue": "={{ $json.output.signature_present }}",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            },
            {
              "id": "id-2",
              "leftValue": "={{ $json.output.is_valid_pod }}",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "bcd779ca-de53-4dcc-a5bd-5e0099c86032",
      "name": "Validate POD Conditions",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        720,
        224
      ]
    },
    {
      "parameters": {
        "from": "={{ $('POD WhatsApp Webhook Trigger').item.json.body.To }}",
        "to": "={{ $('POD WhatsApp Webhook Trigger').item.json.body.From }}",
        "message": "=⚠️ POD Issue Detected\n\nThe image you sent is unclear or missing a signature.\n\nPlease resend a clear POD image with signature to proceed.\n\nThank you!",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        944,
        320
      ],
      "id": "8a57beb0-86bd-4a81-8c81-3e07b3b26497",
      "name": "Send message to Request Clear POD",
      "credentials": {
        "twilioApi": {
          "id": "R6dWWTJFACSwxUGe",
          "name": "tarec16401 - twilio account"
        }
      }
    },
    {
      "parameters": {
        "from": "={{ $('POD WhatsApp Webhook Trigger').item.json.body.To }}",
        "to": "={{ $('POD WhatsApp Webhook Trigger').item.json.body.From }}",
        "message": "=✅ Delivery Completed!\n\nInvoice #{{ $json.output.invoice_number }} has been successfully delivered.\nBilling has been initiated.\n\nThank you!",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1168,
        128
      ],
      "id": "bae3e150-41cc-480d-9b31-cc57f0d5119e",
      "name": "Send POD Confirmation",
      "credentials": {
        "twilioApi": {
          "id": "R6dWWTJFACSwxUGe",
          "name": "tarec16401 - twilio account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1ivjZzcSOkGtojuqWW72r1yzAIGi6COkzL7QzcksWLrI",
          "mode": "list",
          "cachedResultName": "POD Tracking",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ivjZzcSOkGtojuqWW72r1yzAIGi6COkzL7QzcksWLrI/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ivjZzcSOkGtojuqWW72r1yzAIGi6COkzL7QzcksWLrI/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "customer_name": "={{ $json.output.customer_name }}",
            "invoice_number": "={{ $json.output.invoice_number ?? null }}",
            "signature_present": "={{ $json.output.signature_present }}",
            "stamp_present": "={{ $json.output.stamp_present }}",
            "is_valid_pod": "={{ $json.output.is_valid_pod }}",
            "created_at": "={{ $now }}",
            "status": "Delivered",
            "phone": "={{ $('POD WhatsApp Webhook Trigger').item.json.body.From.replace('whatsapp:+', '') }}",
            "pod_image_url": "={{ $node[\"Save POD to Google Drive\"].json.webViewLink }}",
            "invoice_date": "={{ $json.output.invoice_date }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "phone",
              "displayName": "phone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "customer_name",
              "displayName": "customer_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "invoice_number",
              "displayName": "invoice_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "invoice_date",
              "displayName": "invoice_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "signature_present",
              "displayName": "signature_present",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "stamp_present",
              "displayName": "stamp_present",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "is_valid_pod",
              "displayName": "is_valid_pod",
              "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": "pod_image_url",
              "displayName": "pod_image_url",
              "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
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "61958e0b-0ebe-4351-9b8e-f83bc463af66",
      "name": "Save POD Record",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        944,
        128
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "content": "## Google Sheet\nhttps://docs.google.com/spreadsheets/d/1ivjZzcSOkGtojuqWW72r1yzAIGi6COkzL7QzcksWLrI/edit?pli=1&gid=0#gid=0"
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -864,
        224
      ],
      "id": "cf507886-5332-45cb-ad42-05592df414a6",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "## Google Drive \nhttps://drive.google.com/drive/folders/1tFdTx-tE7OzKMmolGvE9ZxK9nTJGVbD5"
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -864,
        416
      ],
      "id": "7112e69e-ea73-489b-9d22-9b227825678e",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "e-pod-message",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        -528,
        224
      ],
      "id": "cbf9aa39-58e5-4b84-a197-46afe422051e",
      "name": "POD WhatsApp Webhook Trigger",
      "webhookId": "477b78b1-53b9-425c-b5f2-a5fcd66ecc62"
    }
  ],
  "pinData": {},
  "connections": {
    "Download POD Image": {
      "main": [
        [
          {
            "node": "Save POD to Google Drive",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge POD Data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Analyze POD Image": {
      "main": [
        [
          {
            "node": "Validate POD Conditions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GPT-4 Vision Model": {
      "ai_languageModel": [
        [
          {
            "node": "Analyze POD Image",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "POD Data Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Analyze POD Image",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Save POD to Google Drive": {
      "main": [
        [
          {
            "node": "Merge POD Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge POD Data": {
      "main": [
        [
          {
            "node": "Analyze POD Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate POD Conditions": {
      "main": [
        [
          {
            "node": "Save POD Record",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send message to Request Clear POD",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send POD Confirmation": {
      "main": [
        []
      ]
    },
    "Save POD Record": {
      "main": [
        [
          {
            "node": "Send POD Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "POD WhatsApp Webhook Trigger": {
      "main": [
        [
          {
            "node": "Download POD Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "ea801e32-18f2-4559-9bec-3a4790d7b611",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "9272721148ea09184b6bbb7ce6219dab088562dd450e2df8280d57c2e34c7d84"
  },
  "id": "nsCvrYvrsq7ujS9w",
  "tags": []
}