{
  "name": "wf_serp_search_tool",
  "nodes": [
    {
      "parameters": {
        "inputSource": "jsonExample",
        "jsonExample": "{\n  \"intent\": \"an interest\",\n  \"location\": \"a place to look for events\"\n}"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -304,
        -288
      ],
      "id": "02b0b089-f143-4659-9ee2-5ba00affb9c8",
      "name": "workflow_trigger",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "wRCvCmRGcILIoLjy",
          "mode": "list",
          "cachedResultName": "Underfoot \u2014 wf_error_notifications"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "callingWorkflow": "={{ $workflow }}",
            "input": "={{ $input.all() }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "callingWorkflow",
              "displayName": "callingWorkflow",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "object"
            },
            {
              "id": "input",
              "displayName": "input",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "array",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {}
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "position": [
        1488,
        -208
      ],
      "id": "f167f2ba-cae4-4474-88a8-1b3a08000fce",
      "name": "trigger_discord_notifier"
    },
    {
      "parameters": {
        "useCustomSchema": true,
        "schema": "underfoot",
        "operation": "getAll",
        "tableId": "google_geotarget_lookup",
        "limit": 1,
        "filters": {
          "conditions": [
            {
              "keyName": "canonical_name",
              "condition": "ilike",
              "keyValue": "=*{{ $json.results[0].city }}*"
            },
            {
              "keyName": "canonical_name",
              "condition": "ilike",
              "keyValue": "=*{{ $json.results[0].state }}*"
            },
            {
              "keyName": "name",
              "condition": "ilike",
              "keyValue": "=*{{ $json.results[0].city }}*"
            },
            {
              "keyName": "name",
              "condition": "ilike",
              "keyValue": "=*{{ $json.results[0].state }}*"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        144,
        -448
      ],
      "id": "49959e20-5549-4362-a34a-68ba38577bfd",
      "name": "find_canonical_location",
      "alwaysOutputData": false,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "zone": {
          "__rl": true,
          "value": "unlocker_serp",
          "mode": "list",
          "cachedResultName": "unlocker_serp"
        },
        "country": {
          "__rl": true,
          "mode": "list",
          "value": "us"
        },
        "url": "=https://www.google.com/search?q={{ $json.intent }}&gl={{ $json.country_code }}&uule={{ $json.location }}&hl=en&num=10&tbs=qdr:w2&brd_json=1",
        "format": "json",
        "requestOptions": {
          "timeout": 1200000
        }
      },
      "type": "@brightdata/n8n-nodes-brightdata.brightData",
      "typeVersion": 1,
      "position": [
        592,
        -208
      ],
      "id": "4c08c06c-1839-4345-846a-2cf3fbf1b992",
      "name": "google_serp_search",
      "credentials": {
        "brightdataApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const intent = encodeURI($('workflow_trigger').item.json.intent);\nconst location = $json.canonical_name || $json.query.text;\nconst country_code = $json.country_code || $json.results[0].country_code;\n\nreturn { intent, location: encodeURI(location), country_code: country_code.toLowerCase() };"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        368,
        -208
      ],
      "id": "c278437d-8509-42bb-ae97-2dc14e9b2f4c",
      "name": "generate_search_terms"
    },
    {
      "parameters": {
        "url": "https://api.geoapify.com/v1/geocode/search",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "sendQuery": true,
        "specifyQuery": "json",
        "jsonQuery": "={\n  \"format\": \"json\",\n  \"limit\": 1,\n  \"text\": \"{{ $json.location }}\",\n  \"lang\": \"en\"\n}",
        "options": {
          "timeout": 10000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -80,
        -288
      ],
      "id": "1963fc52-509a-40c9-9309-7b63e4da1997",
      "name": "call_geoapify_search",
      "credentials": {
        "httpQueryAuth": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "useCustomSchema": true,
        "schema": "underfoot",
        "tableId": "search_cache",
        "dataToSend": "autoMapInputData"
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        1264,
        -48
      ],
      "id": "f9ace4ba-d03a-47a6-a134-00d9d786f045",
      "name": "insert_rows",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "return JSON.parse($json.body);"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        816,
        -144
      ],
      "id": "1ca6a0f2-65cd-4943-83b6-578339594351",
      "name": "parse_content_to_json",
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "jsCode": "const blockedResults = ['youtube'];\n\nreturn $input.all().map(input => {\n    return input.json.organic.map(x => {\n      return {\n        title: x.link,\n        description: x.description || '',\n        source_type: $('workflow_trigger').context,\n        url: x.link,\n        created_at: $now.toISO(),\n        latitude: null,\n        longitude: null,\n        user_intent: $('workflow_trigger').item.json.intent,\n        user_location: $('workflow_trigger').item.json.location\n      };    \n    }).filter(x => !blockedResults.includes(x.url));\n}).flat();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1040,
        -16
      ],
      "id": "2efcdf42-1812-4607-814e-ba59a35d7e20",
      "name": "normalize_result_set",
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "jsCode": "return $input.all().map(resp => {\n  return resp.json;\n}).flat();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1488,
        80
      ],
      "id": "6e796bd4-153e-4a90-8042-75ac00bc5e66",
      "name": "format_for_hosted_chat_display"
    }
  ],
  "connections": {
    "workflow_trigger": {
      "main": [
        [
          {
            "node": "call_geoapify_search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "find_canonical_location": {
      "main": [
        [
          {
            "node": "generate_search_terms",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "trigger_discord_notifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "google_serp_search": {
      "main": [
        [
          {
            "node": "parse_content_to_json",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "trigger_discord_notifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "generate_search_terms": {
      "main": [
        [
          {
            "node": "google_serp_search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "call_geoapify_search": {
      "main": [
        [
          {
            "node": "find_canonical_location",
            "type": "main",
            "index": 0
          },
          {
            "node": "generate_search_terms",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "insert_rows": {
      "main": [
        [
          {
            "node": "format_for_hosted_chat_display",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "trigger_discord_notifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "parse_content_to_json": {
      "main": [
        [
          {
            "node": "normalize_result_set",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "trigger_discord_notifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "normalize_result_set": {
      "main": [
        [
          {
            "node": "insert_rows",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "trigger_discord_notifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner",
    "errorWorkflow": "g0RA1ILyuSMHbt6q"
  },
  "versionId": "0f935829-3365-42e1-8308-e6ea488d7e02",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "So4ty17033VQwdOO",
  "tags": []
}