{
  "name": "Send Local Falcon rank alerts to Discord",
  "nodes": [
    {
      "parameters": {
        "content": "## Send Local Falcon Rank Alerts to Discord\n\n**Who is this for:** Teams using Discord for communication who want ranking alerts delivered to their server channels.\n\n**What this workflow does:**\n1. Monitors Local Falcon trend reports daily\n2. Detects significant ranking changes\n3. Sends formatted alerts to Discord channel\n4. Color-codes messages (green for improvements, red for drops)\n\n**How to set up:**\n1. Add your Local Falcon API credentials (get your key at https://www.localfalcon.com/api/credentials)\n2. Create a Discord webhook for your channel\n3. Add the webhook URL in Settings\n4. Configure alert thresholds\n5. Activate the workflow\n\n**Requirements:**\n- Local Falcon account with API access\n- Discord server with webhook permissions\n- Existing campaigns with scan data\n\n**How to customize:**\n- Create separate channels for different clients\n- Add role mentions for critical alerts\n- Include embed images with rank charts\n- Set up different alert levels",
        "height": 480,
        "width": 460,
        "color": 5
      },
      "id": "sticky-main",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        100,
        -160
      ]
    },
    {
      "parameters": {
        "content": "### Step 1: Schedule\nChecks for changes daily.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        40,
        640
      ]
    },
    {
      "parameters": {
        "content": "### Step 2: Get Trends\nFetches ranking changes.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step2",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        300,
        640
      ]
    },
    {
      "parameters": {
        "content": "### Step 3: Process\nFilters significant changes.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        560,
        640
      ]
    },
    {
      "parameters": {
        "content": "### Step 4: Discord\nSends alert to channel.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step4",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        820,
        640
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "triggerAtHour": 9
            }
          ]
        }
      },
      "id": "schedule",
      "name": "Every Day 9am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        140,
        420
      ]
    },
    {
      "parameters": {
        "resource": "report",
        "operation": "listTrend",
        "additionalFields": {
          "limit": 50
        }
      },
      "id": "get-trends",
      "name": "Get Trend Reports",
      "type": "@local-falcon/n8n-nodes-localfalcon.localFalcon",
      "typeVersion": 1,
      "position": [
        400,
        420
      ],
      "credentials": {
        "localFalconApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const reports = $input.first().json.reports || [];\nconst threshold = 2;\nconst webhookUrl = 'YOUR_DISCORD_WEBHOOK_URL';\n\nconst alerts = reports.filter(r => {\n  const change = Math.abs(parseFloat(r.rank_change) || 0);\n  return change >= threshold;\n});\n\nif (alerts.length === 0) return [];\n\nconst embeds = alerts.map(alert => {\n  const change = parseFloat(alert.rank_change) || 0;\n  const isImprovement = change < 0;\n  \n  return {\n    title: isImprovement ? '\ud83d\udcc8 Rank Improved!' : '\ud83d\udcc9 Rank Dropped',\n    color: isImprovement ? 3066993 : 15158332, // Green or Red\n    fields: [\n      { name: 'Location', value: alert.location_name || 'Unknown', inline: true },\n      { name: 'Keyword', value: alert.keyword || 'Unknown', inline: true },\n      { name: 'Change', value: `${alert.previous_avg_rank} \u2192 ${alert.avg_rank}`, inline: true }\n    ],\n    footer: { text: 'Local Falcon Alert' },\n    timestamp: new Date().toISOString()\n  };\n});\n\nreturn [{\n  json: {\n    webhookUrl: webhookUrl,\n    content: `**Local Falcon Daily Alert** - ${alerts.length} ranking change(s) detected`,\n    embeds: embeds.slice(0, 10) // Discord limit\n  }\n}];"
      },
      "id": "process",
      "name": "Process Alerts",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        420
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $json.webhookUrl }}",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "content",
              "value": "={{ $json.content }}"
            },
            {
              "name": "embeds",
              "value": "={{ JSON.stringify($json.embeds) }}"
            }
          ]
        },
        "options": {}
      },
      "id": "discord",
      "name": "Send to Discord",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        920,
        420
      ]
    }
  ],
  "connections": {
    "Every Day 9am": {
      "main": [
        [
          {
            "node": "Get Trend Reports",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Trend Reports": {
      "main": [
        [
          {
            "node": "Process Alerts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Alerts": {
      "main": [
        [
          {
            "node": "Send to Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}