{
  "name": "crawling data",
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c4b21b80-1e8f-4b32-9a5c-c68e85908e2d",
              "name": "",
              "value": "công ty luật",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -96,
        0
      ],
      "id": "c116ab94-f209-416d-85a8-41eddba102a2",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "fieldToSplitOut": "organic",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        224,
        16
      ],
      "id": "fdca7814-8e40-4ac8-af84-8e173232182b",
      "name": "Split Out"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 7
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -272,
        208
      ],
      "id": "b35aa6a7-3f7d-4ed8-b98e-b1b1bbee7b1e",
      "name": "Schedule Trigger",
      "retryOnFail": true,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://google.serper.dev/search",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-API-KEY",
              "value": "f0f89d06ed31b2a5193cd0262d3a1f66d4da8edf"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"q\": \"{{ $json[''] }}\",\n  \"num\": 5\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        64,
        208
      ],
      "id": "e062c845-4180-4f42-a3c3-7ff1c63753ef",
      "name": "SERPER"
    },
    {
      "parameters": {
        "url": "=https://r.jina.ai/{{ $json.link }}",
        "options": {
          "allowUnauthorizedCerts": true
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        656,
        -144
      ],
      "id": "174abbf8-c25a-450a-a537-cab509f7f300",
      "name": "JINA",
      "notesInFlow": false,
      "retryOnFail": true,
      "waitBetweenTries": 3000,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "e8ee010f-a1c6-4fa1-be4f-45f17ef44e91",
              "leftValue": "={{ $json.link }}",
              "rightValue": "facebook.com",
              "operator": {
                "type": "string",
                "operation": "notContains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        352,
        240
      ],
      "id": "b18ea6dc-bb15-4bf7-b137-23b77239f27a",
      "name": "If"
    },
    {
      "parameters": {
        "resource": "conversation",
        "messages": {
          "values": [
            {}
          ]
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.3,
      "position": [
        1088,
        640
      ],
      "id": "69ba64ef-7570-42a8-87a7-54c77fe5f4ca",
      "name": "Create a conversation",
      "credentials": {
        "openAiApi": {
          "id": "pB1R9kBSdJznpYse",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "serviceAccount",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1zpBY2W-s5tahrmhW5wp2Gk-HxM7KYpwqG8AekT3-u7Q",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "chung",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {
            "Tên Công ty": "={{ $json.ten_cong_ty }}",
            "Link Website": "={{ $json.link_website }}",
            "Email Chào Hàng": "={{ $json.email_sale }}",
            "Số điện thoại": "={{ $json.so_dien_thoai }}",
            "Email liên hệ": "={{ $json.email_lien_he }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Tên Công ty",
              "displayName": "Tên Công ty",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Link Website",
              "displayName": "Link Website",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Email Chào Hàng",
              "displayName": "Email Chào Hàng",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Số điện thoại",
              "displayName": "Số điện thoại",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Email liên hệ",
              "displayName": "Email liên hệ",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1776,
        240
      ],
      "id": "349986ed-0397-4fa3-9652-6d615ae1ee4b",
      "name": "Append row in sheet",
      "credentials": {
        "googleApi": {
          "id": "MZxQJNfoZUfEtS2l",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4-turbo",
          "mode": "list",
          "cachedResultName": "GPT-4-TURBO"
        },
        "responses": {
          "values": [
            {
              "role": "system",
              "content": "Mày là Giám đốc Kinh doanh B2B 25 năm kinh nghiệm của LotusAI. Triết lý của LotusAI: Không chê bất kỳ ca khó nào, bao thầu trọn gói từ A-Z. Khách cần hạ tầng mạng dự phòng (Local Redundancy) -> Có. Khách cần phần mềm LGL-DMS để số hóa hồ sơ -> Có. Khách cần luật sư rà soát hợp đồng mua bán thiết bị -> Bao luôn.\\n\\nNhiệm vụ của mày: Đọc thông tin website của khách và viết 1 email Cold Email gửi thẳng Giám đốc của họ.\\n\\nQUY TẮC SINH TỒN CỦA EMAIL:\\n\\nDung lượng: Cực kỳ ngắn. Tối đa 100 chữ. Rút gọn mọi câu chữ thừa thãi.\\n\\nTiêu đề: Nêu đúng tên công ty họ + Lợi ích sát sườn (VD: Gửi [Tên Khách] - Đề xuất chống sập hạ tầng & Số hóa tài liệu).\\n\\nCâu mở đầu (Móc hàm): Đừng chào hỏi lằng nhằng. Nêu ngay một rủi ro/nỗi đau mà ngành của họ đang gặp phải dựa trên thông tin web. (VD: Luật sư thì sợ lộ hồ sơ thân chủ; Xưởng sản xuất thì sợ sập mạng nội bộ).\\n\\nGiải pháp LotusAI: Khẳng định LotusAI là nhà thầu giải pháp toàn diện. Không bán lẻ tẻ. Bán sự yên tâm. Tùy theo ngành mà lôi LGL-DMS hay Hạ tầng IT ra chốt.\\n\\nChốt hạ (Call to action): Đưa ra đề nghị cực kỳ nhẹ nhàng, ít tốn sức của khách (VD: Xin 15 phút tuần tới để demo).\\n\\nGiọng văn: tế nhị, tử tế, trung lập, ngang hàng với Giám đốc, không cầu xin nài nỉ."
            },
            {
              "content": "=Dựa vào dữ liệu đầu vào sau:\n- Tên công ty/Tổ chức: {{ $('Split Out').item.json.title }}\n- Website: {{ $('Split Out').item.json.link }}\n- Thông tin chuyên sâu (do Jina cào): {{ $json.data.substring(0, 4000) }}\n\nNhiệm vụ của bạn (LotusAI - Giải pháp phần mềm & pháp lý trọn gói):\n1. Đóng vai trò là chuyên gia phân tích nghiệp vụ, viết 1 email ngắn (dưới 150 chữ) chào bán giải pháp của LotusAI. Nhấn mạnh vào việc LotusAI bao thầu toàn bộ từ hạ tầng IT, phần mềm LGL-DMS đến rà soát pháp lý, giải quyết dứt điểm rủi ro cho họ.\n2. Trích xuất chính xác Số điện thoại. Nếu không có: \"Không tìm thấy\".\n3. Trích xuất chính xác Email liên hệ. Nếu không có: \"Không tìm thấy\".\n\nTrả kết quả BẮT BUỘC theo định dạng JSON sau, không giải thích:\n{\n  \"ten_cong_ty\": \"{{ $('Split Out').item.json.title }}\",\n  \"link_website\": \"{{ $('Split Out').item.json.link }}\",\n  \"email_sale\": \"Nội dung email\",\n  \"so_dien_thoai\": \"số điện thoại\",\n  \"email_lien_he\": \"email\"\n}"
            }
          ]
        },
        "simplify": false,
        "builtInTools": {},
        "options": {
          "metadata": "{}"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.3,
      "position": [
        1152,
        -128
      ],
      "id": "075a3a72-6b5b-4d4d-855a-70445c41fa17",
      "name": "Message a model",
      "credentials": {
        "openAiApi": {
          "id": "pB1R9kBSdJznpYse",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Lấy toàn bộ xấp hồ sơ cào được từ các Node trước\nconst allItems = $input.all();\nconst batchData = [];\n\n// Quét từ tờ đầu tiên đến tờ cuối cùng\nfor (let i = 0; i < allItems.length; i++) {\n    try {\n        // Trích xuất text từ con AI cho từng dòng\n        let aiText = allItems[i].json.output[0].content[0].text;\n        \n        // Dọn rác markdown bảo vệ luồng\n        aiText = aiText.replace(/```json/g, \"\").replace(/```/g, \"\").trim();\n        \n        // Ép khuôn dữ liệu\n        let parsedData = JSON.parse(aiText);\n        \n        // Đóng gói thành lô. Lưu ý: Tên cột phải khớp 100% với Google Sheets\n        batchData.push({\n            json: {\n                \"Tên Công ty\": parsedData.ten_cong_ty || \"Trống\",\n                \"Link Website\": parsedData.link_website || \"Trống\",\n                \"Email Chào Hàng\": parsedData.email_sale || \"Trống\",\n                \"Số điện thoại\": parsedData.so_dien_thoai || \"Không tìm thấy\",\n                \"Email liên hệ\": parsedData.email_lien_he || \"Không tìm thấy\",\n                \"Lệnh Phê Duyệt\": \"Chờ duyệt\" // Mấu chốt kiểm soát: Mặc định tất cả phải qua tay sếp\n            }\n        });\n    } catch (error) {\n        // Ca nào AI nhả data quá nát hoặc sai định dạng, cô lập bỏ qua, luồng vét cạn vẫn tiếp tục chạy\n        continue;\n    }\n}\n\n// Trả về nguyên một lô khách hàng để dập thẳng xuống Sheet trong 1 nhịp\nreturn batchData;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1424,
        224
      ],
      "id": "fad29e4d-b263-46f2-8508-12c8581bfbc6",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $json[\"Link Website\"] }}",
        "options": {}
      },
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        1632,
        0
      ],
      "id": "01845bad-43d2-496d-b7a7-039f3b098801",
      "name": "Remove Duplicates nhieu lan"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        912,
        192
      ],
      "id": "85cad10e-a913-4547-ab32-91340ef71656",
      "name": "Remove Duplicates mot lan"
    },
    {
      "parameters": {
        "url": "=https://r.jina.ai/{{ $json.link }}",
        "options": {
          "allowUnauthorizedCerts": true
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        464,
        656
      ],
      "id": "0ce7cd28-07bd-4723-8ae3-b8733ad63ce6",
      "name": "JINA1",
      "notesInFlow": false,
      "retryOnFail": true,
      "waitBetweenTries": 3000,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        800,
        640
      ],
      "id": "78876d25-7161-47dd-849a-19b42478c19f",
      "name": "Remove Duplicates mot lan1"
    },
    {
      "parameters": {
        "authentication": "serviceAccount",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1zpBY2W-s5tahrmhW5wp2Gk-HxM7KYpwqG8AekT3-u7Q",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "chung",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {
            "Tên Công ty": "={{ $json.ten_cong_ty }}",
            "Link Website": "={{ $json.link_website }}",
            "Email Chào Hàng": "={{ $json.email_sale }}",
            "Số điện thoại": "={{ $json.so_dien_thoai }}",
            "Email liên hệ": "={{ $json.email_lien_he }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Tên Công ty",
              "displayName": "Tên Công ty",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Link Website",
              "displayName": "Link Website",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Email Chào Hàng",
              "displayName": "Email Chào Hàng",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Số điện thoại",
              "displayName": "Số điện thoại",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Email liên hệ",
              "displayName": "Email liên hệ",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1904,
        656
      ],
      "id": "0d932447-8c36-4660-ac23-f3c628a94161",
      "name": "Append row in sheet1",
      "credentials": {
        "googleApi": {
          "id": "MZxQJNfoZUfEtS2l",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Lấy toàn bộ xấp hồ sơ cào được từ các Node trước\nconst allItems = $input.all();\nconst batchData = [];\n\n// Quét từ tờ đầu tiên đến tờ cuối cùng\nfor (let i = 0; i < allItems.length; i++) {\n    try {\n        // Trích xuất text từ con AI cho từng dòng\n        let aiText = allItems[i].json.output[0].content[0].text;\n        \n        // Dọn rác markdown bảo vệ luồng\n        aiText = aiText.replace(/```json/g, \"\").replace(/```/g, \"\").trim();\n        \n        // Ép khuôn dữ liệu\n        let parsedData = JSON.parse(aiText);\n        \n        // Đóng gói thành lô. Lưu ý: Tên cột phải khớp 100% với Google Sheets\n        batchData.push({\n            json: {\n                \"Tên Công ty\": parsedData.ten_cong_ty || \"Trống\",\n                \"Link Website\": parsedData.link_website || \"Trống\",\n                \"Email Chào Hàng\": parsedData.email_sale || \"Trống\",\n                \"Số điện thoại\": parsedData.so_dien_thoai || \"Không tìm thấy\",\n                \"Email liên hệ\": parsedData.email_lien_he || \"Không tìm thấy\",\n                \"Lệnh Phê Duyệt\": \"Chờ duyệt\" // Mấu chốt kiểm soát: Mặc định tất cả phải qua tay sếp\n            }\n        });\n    } catch (error) {\n        // Ca nào AI nhả data quá nát hoặc sai định dạng, cô lập bỏ qua, luồng vét cạn vẫn tiếp tục chạy\n        continue;\n    }\n}\n\n// Trả về nguyên một lô khách hàng để dập thẳng xuống Sheet trong 1 nhịp\nreturn batchData;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1392,
        640
      ],
      "id": "8d637ba3-fd8c-457a-a3d2-d2dde4b742a5",
      "name": "Code in JavaScript1"
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $json[\"Link Website\"] }}",
        "options": {}
      },
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        1664,
        640
      ],
      "id": "4131db01-be5d-4e73-b9c7-b82dc07ab404",
      "name": "Remove Duplicates nhieu lan1"
    },
    {
      "parameters": {
        "filters": {},
        "options": {}
      },
      "type": "n8n-nodes-base.youTubeTool",
      "typeVersion": 1,
      "position": [
        1376,
        432
      ],
      "id": "d3eea509-8923-40b5-a247-6f3bcab7fa1a",
      "name": "Get many channels in YouTube"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.facebookGraphApi",
      "typeVersion": 1,
      "position": [
        1584,
        432
      ],
      "id": "4edde74e-59d2-4261-bbb1-cfbf9bbd144e",
      "name": "Facebook Graph API"
    }
  ],
  "pinData": {},
  "connections": {
    "Edit Fields": {
      "main": [
        [
          {
            "node": "SERPER",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SERPER": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "JINA": {
      "main": [
        [
          {
            "node": "Remove Duplicates mot lan",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "JINA",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "JINA1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Remove Duplicates nhieu lan",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates nhieu lan": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates mot lan": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "JINA1": {
      "main": [
        [
          {
            "node": "Remove Duplicates mot lan1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates mot lan1": {
      "main": [
        [
          {
            "node": "Create a conversation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript1": {
      "main": [
        [
          {
            "node": "Remove Duplicates nhieu lan1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates nhieu lan1": {
      "main": [
        [
          {
            "node": "Append row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a conversation": {
      "main": [
        [
          {
            "node": "Code in JavaScript1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "c809ef0e-ffa3-422e-b88f-243b45d49e09",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "2b801a20c42e2d5fb96f336ac43a50b04473b5870c61aada17e8165745868e94"
  },
  "id": "bPd105FUJupJPwdq",
  "tags": []
}