{
  "id": "I2UoQP8Af3EKxGGX",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Onboardly AI Agent - WhatsApp Document Collection",
  "tags": [],
  "nodes": [
    {
      "id": "e7886fe8-d9c6-4b65-9670-1fe6f4fe3889",
      "name": "AWS GetDocumentAnalysis",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1168,
        -448
      ],
      "parameters": {
        "url": "https://textract.us-east-1.amazonaws.com/",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n   \"JobId\": \"{{ $json.data.parseJson().JobId}}\"\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Amz-Target",
              "value": "Textract.GetDocumentAnalysis"
            },
            {
              "name": "Content-Type",
              "value": "application/x-amz-json-1.1"
            }
          ]
        },
        "nodeCredentialType": "aws"
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "50ea7ddb-e2e3-4c57-be98-1f2db5669201",
      "name": "AWS StartDocumentAnalysis",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1616,
        -448
      ],
      "parameters": {
        "url": "https://textract.us-east-1.amazonaws.com/",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"DocumentLocation\": {\n    \"S3Object\": {\n      \"Bucket\": \"{{ $json.Bucket }}\",\n      \"Name\": \"{{ $json.Key }}\"\n    }\n  },\n  \"FeatureTypes\": [\"FORMS\", \"TABLES\"]\n}\n ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Amz-Target",
              "value": "Textract.StartDocumentAnalysis"
            },
            {
              "name": "Content-Type",
              "value": "application/x-amz-json-1.1"
            }
          ]
        },
        "nodeCredentialType": "aws"
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "ac51229d-ec18-4900-a87f-e572a11ebf8f",
      "name": "Download File from S3",
      "type": "n8n-nodes-base.awsS3",
      "position": [
        -1840,
        -448
      ],
      "parameters": {
        "fileKey": "={{ $json.Key }}",
        "bucketName": "={{ $json.Bucket }}"
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "5c690c78-dac9-4654-a6f2-4c69147f261d",
      "name": "Upload File to S3",
      "type": "n8n-nodes-base.awsS3",
      "position": [
        -2064,
        -448
      ],
      "parameters": {
        "fileName": "={{ $('WhatsApp Trigger').item.json.messages[0].document.filename }}",
        "operation": "upload",
        "bucketName": "onboardly-ai",
        "additionalFields": {}
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "822414b6-a00b-4370-b435-a2361267b4f7",
      "name": "File Download",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2288,
        -448
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        },
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "74c15e4b-acc2-4e80-8001-b8592cf4aa59",
      "name": "Get PDF",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2512,
        -448
      ],
      "parameters": {
        "url": "=https://graph.facebook.com/v24.0/{{ $('WhatsApp Trigger').item.json.messages[0].document.id }}",
        "options": {},
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "phone_number_id",
              "value": "={{ $('WhatsApp Trigger').item.json.metadata.phone_number_id }}"
            }
          ]
        },
        "nodeCredentialType": "whatsAppApi"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "4b4920e8-2fa8-4bf1-913a-e658bea83736",
      "name": "WhatsApp Trigger",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        -2736,
        -448
      ],
      "parameters": {
        "options": {
          "messageStatusUpdates": [
            "all"
          ]
        },
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "29c7c835-7a51-4cc9-abf9-9cf3cb9ce73c",
      "name": "Wait for Processing Time",
      "type": "n8n-nodes-base.wait",
      "position": [
        -1392,
        -448
      ],
      "parameters": {
        "amount": 30
      },
      "typeVersion": 1.1
    },
    {
      "id": "c6d13085-5dc3-4f5e-9085-bf9dd93d8102",
      "name": "Extract Text",
      "type": "n8n-nodes-base.code",
      "position": [
        -944,
        -448
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\nconst results = items.map(item => {\n  const raw = item.json.data;                \n  const textract = typeof raw === 'string'\n    ? JSON.parse(raw)\n    : raw;\n\n  const blocks = textract.Blocks || [];\n\n  const lines = blocks\n    .filter(b => b.BlockType === 'LINE' && b.Text)\n    .map(b => b.Text);\n\n  return {\n    json: {\n      text: lines.join('\\n')\n    }\n  };\n});\n\nreturn results;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "5751ca71-fb58-4506-947d-f95c9ef41a29",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3616,
        -656
      ],
      "parameters": {
        "width": 752,
        "height": 528,
        "content": "## \ud83d\udfe8 **MAIN STICKY \u2014 WhatsApp PDF OCR Workflow**\n\n**How it Works**\n\nThis workflow automatically extracts text from PDF documents sent via WhatsApp. When a message containing a PDF arrives, the file is downloaded from the WhatsApp media URL and uploaded to your AWS S3 bucket. A Textract analysis job is then started to perform OCR on the stored PDF. After a short wait, the workflow retrieves the results from Textract and converts them into clean, ordered text. The extracted output is returned for further processing such as AI analysis, storage, or automation.\n\n**Setup Steps**\n1. Connect your WhatsApp integration (e.g., webhook from WhatsApp Cloud API).\n2. Add AWS credentials with permission for S3 upload and Textract analysis.\n3. Set your S3 bucket name and Textract region in the AWS nodes.\n4. Ensure HTTP Request nodes are authenticated for WhatsApp media access.\n5. Activate the workflow and send a PDF via WhatsApp to test.\n\n**Good to Know**\n* Supports both scanned and digital PDFs.\n* Textract pricing is per page; processing time varies by file size.\n* S3 acts as the required temporary storage layer."
      },
      "typeVersion": 1
    },
    {
      "id": "8eb1a8b8-a3a9-4f77-b6d5-2a92e1f7919d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2800,
        -656
      ],
      "parameters": {
        "color": 7,
        "width": 656,
        "height": 528,
        "content": "## Whatsapp Input"
      },
      "typeVersion": 1
    },
    {
      "id": "dc4fc46b-93d3-4193-ae55-febb76236415",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2128,
        -656
      ],
      "parameters": {
        "color": 7,
        "width": 432,
        "height": 528,
        "content": "## AWS S3 Handling"
      },
      "typeVersion": 1
    },
    {
      "id": "252dd1ba-471d-4cb8-9dad-64c899098a6e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1664,
        -656
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 528,
        "content": "## AWS Textract Processing"
      },
      "typeVersion": 1
    },
    {
      "id": "137923f7-dd0a-4138-b4b8-b298f29a6d49",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1008,
        -656
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 528,
        "content": "## Output Cleanup"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b71bd0f8-1f4f-46e6-9f1d-76698182a335",
  "connections": {
    "Get PDF": {
      "main": [
        [
          {
            "node": "File Download",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text": {
      "main": [
        []
      ]
    },
    "File Download": {
      "main": [
        [
          {
            "node": "Upload File to S3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "Get PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload File to S3": {
      "main": [
        [
          {
            "node": "Download File from S3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File from S3": {
      "main": [
        [
          {
            "node": "AWS StartDocumentAnalysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AWS GetDocumentAnalysis": {
      "main": [
        [
          {
            "node": "Extract Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Processing Time": {
      "main": [
        [
          {
            "node": "AWS GetDocumentAnalysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AWS StartDocumentAnalysis": {
      "main": [
        [
          {
            "node": "Wait for Processing Time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}