{
  "id": "",
  "name": "LINE BOT - Google Sheets File Lookup with AI Agent",
  "tags": [],
  "nodes": [
    {
      "id": "",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1100,
        480
      ],
      "parameters": {
        "path": "line-webhook",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "Google Sheets Lookup",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -340,
        480
      ],
      "parameters": {
        "range": "=A:B",
        "options": {
          "returnAllMatches": true
        },
        "sheetId": "",
        "operation": "lookup",
        "lookupValue": "={{ $json.output }}",
        "lookupColumn": "Filename",
        "authentication": "oAuth2"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "retryOnFail": false,
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "",
      "name": "IF File Exists",
      "type": "n8n-nodes-base.if",
      "position": [
        -160,
        480
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json['File URL'] }}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -680,
        480
      ],
      "parameters": {
        "text": "={{ $json.textinput }}",
        "agent": "conversationalAgent",
        "options": {
          "systemMessage": "You are an AI chatbot that helps extract filenames from user messages.\nUsers will send messages related to file searches, such as:\n\n\"Please find file 1.pdf for me.\"\n\"Can you get me file 2.pdf?\"\n\"Is there a file related to project ABC?\"\n\"Show me all my documents.\"\nAnalyze the message and extract the filename the user is requesting. Respond with only the filename, such as:\n\n\"1.pdf\"\n\"Project ABC Document.pdf\"\nIf no filename is found in the message, respond with \"No filename detected.\""
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -680,
        720
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -880,
        480
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "",
              "name": "textinput",
              "type": "string",
              "value": "={{ $json.body.events[0].message.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "",
      "name": "HTTP Request - Found",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        80,
        620
      ],
      "parameters": {
        "url": "https://api.line.me/v2/bot/message/reply",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"replyToken\": \"{{ $('Webhook').item.json.body.events[0].replyToken }}\",\n  \"messages\": [\n    {\n      \"type\": \"text\",\n      \"text\": \"{{ $json['File URL'] }}\"\n    }\n  ]\n}\n",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "",
      "name": "HTTP Request - Not Found",
      "type": "n8n-nodes-base.httpRequest",
      "disabled": true,
      "position": [
        80,
        400
      ],
      "parameters": {
        "url": "https://api.line.me/v2/bot/message/reply",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"replyToken\": \"{{ $('Webhook').item.json.body.events[0].replyToken }}\",\n  \"messages\": [\n    {\n      \"type\": \"text\",\n      \"text\": \"\"\n    }\n  ]\n}\n",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "",
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Google Sheets Lookup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF File Exists": {
      "main": [
        [],
        [
          {
            "node": "HTTP Request - Found",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Lookup": {
      "main": [
        [
          {
            "node": "IF File Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}