{
  "nodes": [
    {
      "id": "8973e5ac-fe72-4a8f-a293-a1bf673cefb9",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -912,
        64
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "14665c0e-7229-4145-a323-fe08472b8db9",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -704,
        64
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "searchQuery",
              "type": "string",
              "value": "Cafes in Shibuya"
            },
            {
              "id": "id-2",
              "name": "maxPlaces",
              "type": "number",
              "value": 5
            },
            {
              "id": "id-3",
              "name": "apifyActorId",
              "type": "string",
              "value": "compass/google-maps-scraper"
            },
            {
              "id": "id-4",
              "name": "serviceName",
              "type": "string",
              "value": "Reservierungssystem für Restaurants"
            },
            {
              "id": "id-5",
              "name": "serviceStrength",
              "type": "string",
              "value": "Einfaches Reservieren ohne Telefonanruf"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "644f99ed-f731-43a3-b108-f42d6b025650",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -240,
        64
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "db5a7927-9b40-49a1-9356-68cda2575e93",
      "name": "Check Website URL Exists",
      "type": "n8n-nodes-base.if",
      "position": [
        -32,
        80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={ { $json.website } }"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "fac6fc69-635f-43bb-8d7f-d07b14eede3a",
      "name": "Fetch Website HTML",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        224,
        64
      ],
      "parameters": {
        "url": "={ { $json.website } }",
        "options": {}
      },
      "typeVersion": 4.3
    },
    {
      "id": "fa8d0479-4c34-4c53-b240-de0cb65267ff",
      "name": "Extract Text from HTML",
      "type": "n8n-nodes-base.code",
      "position": [
        432,
        64
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const html = $input.item.json.data || '';\nconst text = html.replace(/<script[^>]*>.*?<\\/script>/gi, '').replace(/<style[^>]*>.*?<\\/style>/gi, '').replace(/<[^>]+>/g, ' ').replace(/\\s+/g, ' ').trim().substring(0, 2000);\n\nreturn {\n  json: {\n    site_text: text,\n    title: $('Loop Over Items').item.json.title,\n    categoryName: $('Loop Over Items').item.json.categoryName,\n    website: $('Loop Over Items').item.json.website,\n    address: $('Loop Over Items').item.json.address,\n    phone: $('Loop Over Items').item.json.phone\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "864e927b-98e1-4f64-936b-b4b6534f2bda",
      "name": "Generate Personalized Email",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        656,
        64
      ],
      "parameters": {
        "operation": "message"
      },
      "typeVersion": 2
    },
    {
      "id": "f87d5128-c0a5-44df-892a-0cbe99e06d32",
      "name": "Save to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1008,
        208
      ],
      "parameters": {
        "columns": {
          "value": {
            "住所": "={ { $('Loop Over Items').item.json.address } }",
            "店舗名": "={ { $('Loop Over Items').item.json.title } }",
            "Webサイト": "={ { $('Loop Over Items').item.json.website } }",
            "電話番号": "={ { $('Loop Over Items').item.json.phone } }",
            "生成されたメール件名": "={ { $json.message.content } }",
            "生成されたメール本文": "={ { $json.message.content } }",
            "サイトから取得した情報": "={ { $('Extract Text from HTML').item.json.site_text } }"
          },
          "schema": [
            {
              "id": "店舗名",
              "required": false,
              "displayName": "店舗名",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "住所",
              "required": false,
              "displayName": "住所",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Webサイト",
              "required": false,
              "displayName": "Webサイト",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "電話番号",
              "required": false,
              "displayName": "電話番号",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "サイトから取得した情報",
              "required": false,
              "displayName": "サイトから取得した情報",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "生成されたメール件名",
              "required": false,
              "displayName": "生成されたメール件名",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "生成されたメール本文",
              "required": false,
              "displayName": "生成されたメール本文",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "店舗名"
          ]
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Lead_Sheet"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "Google_Sheet_ID"
        }
      },
      "typeVersion": 4.7
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Check Website URL Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Website HTML": {
      "main": [
        [
          {
            "node": "Extract Text from HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Google Sheets": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text from HTML": {
      "main": [
        [
          {
            "node": "Generate Personalized Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Website URL Exists": {
      "main": [
        [
          {
            "node": "Fetch Website HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Personalized Email": {
      "main": [
        [
          {
            "node": "Save to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}