{
  "name": "Organize handwritten memos from LINE using Gemini OCR, Drive and Sheets",
  "nodes": [
    {
      "id": "d966c63b-0c81-4ae4-b39f-cea2e1bc262b",
      "name": "LINE_Receive_Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -352,
        -352
      ]
    },
    {
      "id": "24b6f4c9-f787-4a76-b810-73f8ce3c13d0",
      "name": "LINE_Check_MessageType",
      "type": "n8n-nodes-base.if",
      "position": [
        112,
        -352
      ]
    },
    {
      "id": "65504c18-86a1-43b4-ba30-73034b424a3c",
      "name": "LINE_Download_ImageContent",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        560,
        -368
      ]
    },
    {
      "id": "d818cc9f-74b8-4df2-832e-8c4ad0bea0f0",
      "name": "Binary_Restore_From_LINE",
      "type": "n8n-nodes-base.code",
      "position": [
        944,
        -368
      ]
    },
    {
      "id": "6560682c-aea1-40ff-8883-07e6346da25c",
      "name": "Drive_Upload_Image",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        752,
        -368
      ]
    },
    {
      "id": "e70fef6c-4191-4ec8-8676-2f1d9692b9be",
      "name": "AI_OCR_Analyze_Image",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1152,
        -368
      ]
    },
    {
      "id": "63af5fcc-e079-48c2-9548-f47f5bd5459d",
      "name": "AI_Model_Gemini",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1200,
        -176
      ]
    },
    {
      "id": "629c2e2c-9fe6-4dc0-9055-a62c83a02091",
      "name": "Data_Parse_OCR_JSON",
      "type": "n8n-nodes-base.code",
      "position": [
        1600,
        -368
      ]
    },
    {
      "id": "490147c4-3b25-4868-89db-410367e97af5",
      "name": "AI_Check_OCR_Failure",
      "type": "n8n-nodes-base.if",
      "position": [
        1888,
        -368
      ]
    },
    {
      "id": "8ce58f94-0c8f-4796-8082-7fa7af4f1eaf",
      "name": "LINE_Reply_NoImage",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        320,
        -176
      ]
    },
    {
      "id": "77b6636b-89a7-4ca7-9266-80ab17312250",
      "name": "Sheets_Get_Metadata",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2272,
        -352
      ]
    },
    {
      "id": "3c6d4ce3-d628-4973-a921-f8df9bfce102",
      "name": "Sheets_Check_Category_Exists",
      "type": "n8n-nodes-base.code",
      "position": [
        2480,
        -352
      ]
    },
    {
      "id": "cea2f7b2-3ec4-4602-8840-f17011641121",
      "name": "Sheets_Branch_Category",
      "type": "n8n-nodes-base.if",
      "position": [
        2688,
        -352
      ]
    },
    {
      "id": "9fd98944-f097-420e-9f18-9a1c8e2a6404",
      "name": "Sheets_Create_Category",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2832,
        -240
      ]
    },
    {
      "id": "835f1e29-373f-41b8-bdf0-b0235c7bd4ac",
      "name": "Sheets_Append_Row",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3344,
        -368
      ]
    },
    {
      "id": "b9403280-7d7c-49be-9267-17fbfabcd74e",
      "name": "LINE_Push_Completion_Message",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3696,
        -368
      ]
    },
    {
      "id": "6cec1e96-0f19-43e4-92b5-4a4719ce0018",
      "name": "Data_Prepare_Sheet_Row",
      "type": "n8n-nodes-base.set",
      "position": [
        3040,
        -240
      ]
    },
    {
      "id": "e69bd4e7-c264-44d1-adcc-a8ef27d5a369",
      "name": "Config_Set_Environment",
      "type": "n8n-nodes-base.set",
      "position": [
        -128,
        -352
      ]
    },
    {
      "id": "01086742-e02d-431b-a8e2-894cc045908e",
      "name": "LINE_Reply_Processing",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        320,
        -368
      ]
    },
    {
      "id": "265726ac-ccc0-4a59-8831-01d9066621a2",
      "name": "LINE_Push_NoSummary",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2064,
        -528
      ]
    },
    {
      "id": "6e3926bb-93e7-4571-a552-f8fefbca4dfc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        496,
        -608
      ],
      "parameters": {
        "width": 608,
        "height": 416,
        "content": "##  Image Handling\n\nProcesses the incoming image:\n\n• Downloads image from LINE API\n• Uploads image to Google Drive\n• Restores binary data\n\nEnsures persistent storage for later use."
      }
    },
    {
      "id": "b4988f99-7b80-4e3e-b80f-2e3fc284e400",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1136,
        -720
      ],
      "parameters": {
        "width": 688,
        "height": 960,
        "content": "## AI Handwritten Memo Organizer – Overview\nThis workflow receives handwritten memo images sent via LINE and automatically extracts, summarizes, and organizes the content using AI.\n\n## Step-by-step pr"
      }
    },
    {
      "id": "7801b3d3-d0eb-4711-a946-a457acf5f17c",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -416,
        -608
      ],
      "parameters": {
        "width": 896,
        "height": 608,
        "content": "## LINE Input & Validation\n\nReceives messages via LINE Webhook.\n\n• Validates that the input is an image\n• Non-image messages are rejected with guidance\n• Ensures only valid data enters the workflow\n• "
      }
    },
    {
      "id": "ac47a850-0fe3-4aef-a804-aa5b43abdfce",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        -656
      ],
      "parameters": {
        "width": 400,
        "height": 608,
        "content": "##  OCR & AI Processing\n\nExtracts and structures data from the image:\n\n• Performs OCR on handwritten content\n• Generates structured JSON:\n  - title\n  - category\n  - summary\n  - tags\n\nTransforms unstru"
      }
    },
    {
      "id": "41e2fac1-ece2-4101-a4f3-20f2cb2c3aa8",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1536,
        -656
      ],
      "parameters": {
        "width": 272,
        "height": 464,
        "content": "##  JSON Parsing\n\nSafely parses AI output:\n\n• Removes invalid wrappers (e.g. ```json)\n• Extracts JSON content\n• Handles malformed responses with fallback\n\nPrevents workflow crashes from AI inconsisten"
      }
    },
    {
      "id": "cba9d1aa-eb5f-4538-a89c-4fd282e7e43a",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1840,
        -752
      ],
      "parameters": {
        "width": 368,
        "height": 592,
        "content": "## OCR Failure Detection\n\nValidates OCR result quality:\n\n• Detects missing or invalid summary\n• Stops workflow if text is not recognized\n\nPrevents saving incorrect data."
      }
    },
    {
      "id": "e9b8bc3f-5148-49a4-970d-02e19fb0cc44",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2224,
        -608
      ],
      "parameters": {
        "width": 976,
        "height": 544,
        "content": "## Sheet Management\n\nManages Google Sheets structure:\n\n• Checks if category sheet exists\n• Creates new sheet if needed\n\nEnables scalable data organization."
      }
    },
    {
      "id": "4739a0a1-b1e0-4acd-b023-0b9d3ba244d7",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3216,
        -624
      ],
      "parameters": {
        "width": 320,
        "height": 416,
        "content": "## Data Storage\n\nStores structured data:\n\n• Title\n• Summary\n• Tags\n• Date\n• Image URL\n\nAll data is appended to the correct sheet."
      }
    },
    {
      "id": "ac129a5a-5345-48b4-972d-66b07fc042dd",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3552,
        -576
      ],
      "parameters": {
        "width": 304,
        "height": 384,
        "content": "## Completion Response\n\nSends results back to user:\n\n• Confirms successful processing\n• Provides organized output\n\nCloses the workflow clearly."
      }
    }
  ],
  "connections": {
    "AI_Model_Gemini": {
      "ai_languageModel": [
        [
          {
            "node": "AI_OCR_Analyze_Image",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Sheets_Append_Row": {
      "main": [
        [
          {
            "node": "LINE_Push_Completion_Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Drive_Upload_Image": {
      "main": [
        [
          {
            "node": "Binary_Restore_From_LINE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Data_Parse_OCR_JSON": {
      "main": [
        [
          {
            "node": "AI_Check_OCR_Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sheets_Get_Metadata": {
      "main": [
        [
          {
            "node": "Sheets_Check_Category_Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI_Check_OCR_Failure": {
      "main": [
        [
          {
            "node": "LINE_Push_NoSummary",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Sheets_Get_Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI_OCR_Analyze_Image": {
      "main": [
        [
          {
            "node": "Data_Parse_OCR_JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LINE_Receive_Webhook": {
      "main": [
        [
          {
            "node": "Config_Set_Environment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LINE_Reply_Processing": {
      "main": [
        [
          {
            "node": "LINE_Download_ImageContent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config_Set_Environment": {
      "main": [
        [
          {
            "node": "LINE_Check_MessageType",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Data_Prepare_Sheet_Row": {
      "main": [
        [
          {
            "node": "Sheets_Append_Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LINE_Check_MessageType": {
      "main": [
        [
          {
            "node": "LINE_Reply_Processing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "LINE_Reply_NoImage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sheets_Branch_Category": {
      "main": [
        [
          {
            "node": "Sheets_Append_Row",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Sheets_Create_Category",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sheets_Create_Category": {
      "main": [
        [
          {
            "node": "Data_Prepare_Sheet_Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Binary_Restore_From_LINE": {
      "main": [
        [
          {
            "node": "AI_OCR_Analyze_Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LINE_Download_ImageContent": {
      "main": [
        [
          {
            "node": "Drive_Upload_Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sheets_Check_Category_Exists": {
      "main": [
        [
          {
            "node": "Sheets_Branch_Category",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}