{
  "name": "Alert when Local Falcon credits are running low",
  "nodes": [
    {
      "parameters": {
        "content": "## Alert When Local Falcon Credits Are Running Low\n\n**Who is this for:** Agencies and power users who need to ensure they never run out of scan credits during critical campaigns.\n\n**What this workflow does:**\n1. Checks your Local Falcon account credits daily\n2. Compares against your configured threshold\n3. Sends Slack/email alert when credits fall below threshold\n4. Includes usage trends to help plan purchases\n\n**How to set up:**\n1. Add your Local Falcon API credentials (get your key at https://www.localfalcon.com/api/credentials)\n2. Set your credit threshold in the Settings node\n3. Connect Slack or configure email for alerts\n4. Activate the workflow\n\n**Requirements:**\n- Local Falcon account with API access\n- Slack workspace or SMTP for alerts\n\n**How to customize:**\n- Add multiple alert thresholds (warning, critical)\n- Include automatic credit purchase integration\n- Create weekly usage reports\n- Alert specific team members based on usage",
        "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 credits every morning.",
        "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 Account\nFetches current credit balance.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step2",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        300,
        640
      ]
    },
    {
      "parameters": {
        "content": "### Step 3: Check Threshold\nCompares against minimum.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        560,
        640
      ]
    },
    {
      "parameters": {
        "content": "### Step 4: Alert\nSends notification if low.",
        "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": 7
            }
          ]
        }
      },
      "id": "schedule",
      "name": "Every Day 7am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        140,
        420
      ]
    },
    {
      "parameters": {
        "resource": "account",
        "operation": "getInfo"
      },
      "id": "get-account",
      "name": "Get Account Info",
      "type": "@local-falcon/n8n-nodes-localfalcon.localFalcon",
      "typeVersion": 1,
      "position": [
        400,
        420
      ],
      "credentials": {
        "localFalconApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const account = $input.first().json;\nconst credits = account.credits || account.scan_credits || 0;\nconst threshold = 100; // Configure your threshold here\nconst slackChannel = '#local-falcon-alerts';\n\nif (credits >= threshold) {\n  // Credits OK, stop workflow\n  return [];\n}\n\n// Credits low, send alert\nconst urgency = credits < 20 ? ':rotating_light: CRITICAL' : ':warning: Warning';\n\nconst message = `${urgency} *Low Local Falcon Credits*\\n\\n` +\n  `*Current Balance:* ${credits} credits\\n` +\n  `*Threshold:* ${threshold} credits\\n\\n` +\n  `Please purchase additional credits to avoid scan interruptions.\\n\\n` +\n  `_Purchase at: https://www.localfalcon.com/credits_`;\n\nreturn [{\n  json: {\n    slackMessage: message,\n    slackChannel: slackChannel,\n    credits: credits,\n    threshold: threshold,\n    isCritical: credits < 20\n  }\n}];"
      },
      "id": "check-threshold",
      "name": "Check Credit Threshold",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        420
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $json.slackChannel }}"
        },
        "text": "={{ $json.slackMessage }}",
        "otherOptions": {}
      },
      "id": "slack-alert",
      "name": "Send Credit Alert",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        920,
        420
      ],
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Every Day 7am": {
      "main": [
        [
          {
            "node": "Get Account Info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Account Info": {
      "main": [
        [
          {
            "node": "Check Credit Threshold",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Credit Threshold": {
      "main": [
        [
          {
            "node": "Send Credit Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}