{
  "name": "ChatRail — WhatsApp images to Dropbox",
  "nodes": [
    {
      "parameters": {
        "content": "## Setup\n\n1. **WhatsApp Webhook** — copy the Production URL and register it in ChatRail:\n   `POST /v1/webhook-endpoints` with `events: [\"message.received\"]`.\n2. **Download Image** — create an HTTP Bearer credential holding your ChatRail API key\n   (`messages:read`).\n3. **Upload to Dropbox** — connect a Dropbox OAuth2 credential.\n\nDropbox creates the dated folder from the upload path, so there is no find-or-create step.",
        "height": 280,
        "width": 360
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-360, -120],
      "id": "note-setup",
      "name": "Setup notes"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "whatsapp-images",
        "options": {}
      },
      "id": "node-webhook",
      "name": "WhatsApp Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [0, 0],
      "webhookId": "chatrail-whatsapp-images"
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "typeValidation": "strict", "version": 2 },
          "conditions": [
            {
              "id": "only-image",
              "leftValue": "={{ $json.body.data.kind }}",
              "rightValue": "image",
              "operator": { "type": "string", "operation": "equals" }
            },
            {
              "id": "has-url",
              "leftValue": "={{ $json.body.data.media.download_url }}",
              "rightValue": "",
              "operator": { "type": "string", "operation": "exists", "singleValue": true }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "node-only-images",
      "name": "Only Images",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [224, 0]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "dropboxPath",
              "type": "string",
              "value": "=/WhatsApp images/{{ $now.toFormat('yyyy-MM-dd') }}/whatsapp-{{ $now.toFormat('yyyyMMdd-HHmmss') }}.jpg"
            }
          ]
        },
        "options": {}
      },
      "id": "node-prepare",
      "name": "Prepare",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [448, 0]
    },
    {
      "parameters": {
        "url": "={{ \"https://www.chatrail.dev\" + $(\"WhatsApp Webhook\").first().json.body.data.media.download_url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "options": { "response": { "response": { "responseFormat": "file" } } }
      },
      "id": "node-download",
      "name": "Download Image",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.5,
      "position": [672, 0],
      "credentials": { "httpBearerAuth": { "name": "ChatRail API key" } }
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "upload",
        "path": "={{ $('Prepare').item.json.dropboxPath }}",
        "binaryData": true,
        "binaryPropertyName": "data",
        "options": {}
      },
      "id": "node-upload",
      "name": "Upload to Dropbox",
      "type": "n8n-nodes-base.dropbox",
      "typeVersion": 1,
      "position": [896, 0],
      "credentials": { "dropboxOAuth2Api": { "name": "Dropbox account" } }
    }
  ],
  "connections": {
    "WhatsApp Webhook": { "main": [[{ "node": "Only Images", "type": "main", "index": 0 }]] },
    "Only Images": { "main": [[{ "node": "Prepare", "type": "main", "index": 0 }], []] },
    "Prepare": { "main": [[{ "node": "Download Image", "type": "main", "index": 0 }]] },
    "Download Image": { "main": [[{ "node": "Upload to Dropbox", "type": "main", "index": 0 }]] }
  },
  "active": false,
  "settings": { "executionOrder": "v1", "binaryMode": "separate" },
  "tags": [{ "name": "ChatRail" }]
}
