{
  "name": "Tutorial: text yourself about qualified leads with SelfPing",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "selfping-lead-saved",
        "authentication": "headerAuth",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "7c03d159-eebc-4896-bcb8-0d66552d2706",
      "name": "Lead saved",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "c9be348e-dd9d-4ab1-948b-04a92fef637b"
    },
    {
      "parameters": {
        "jsCode": "return $input.all().flatMap((item, index) => {\n  const body = item.json.body;\n  if (!body || body.event !== 'lead.saved') return [];\n  const id = body.lead_id;\n  if (typeof id !== 'string' || !/^[A-Za-z0-9_-]{1,100}$/.test(id)) {\n    throw new Error('lead.saved requires lead_id: 1-100 letters, digits, underscores, or hyphens.');\n  }\n  if (typeof body.qualified !== 'boolean') {\n    throw new Error('lead.saved requires qualified: true or false.');\n  }\n  if (!body.qualified) return [];\n  return [{ json: { lead_id: id }, pairedItem: { item: index } }];\n});"
      },
      "id": "f95ef2cf-08c5-487e-aea7-b730e3829522",
      "name": "Keep qualified leads",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        260,
        0
      ]
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $json.lead_id }}",
        "options": {
          "historySize": 10000
        }
      },
      "id": "c407b8db-3924-469f-b091-094f402b0d3a",
      "name": "Skip seen lead IDs",
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        520,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://www.selfping.com/api/sms",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "{\"message\":\"A qualified lead was saved. Check your CRM to follow up.\"}",
        "options": {
          "timeout": 10000
        }
      },
      "id": "abf90210-78ac-4ade-8387-69e7194e10c2",
      "name": "Text myself",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        780,
        0
      ],
      "retryOnFail": false
    },
    {
      "parameters": {
        "content": "### How it works\nThis tutorial helps solo founders turn a saved, qualified lead into an SMS to their own phone. Your app saves the lead and decides qualification. The authenticated webhook accepts one event, the Code node validates and filters it, and Remove Duplicates checks the lead ID before SelfPing sends a short alert. Other event types and qualified:false are ignored. Missing or malformed lead fields fail the execution.\n\n### Setup\nUse n8n and a SelfPing account. In Lead saved, create Header Auth with name X-Webhook-Secret and a long random value. In Text myself, create a separate Header Auth credential with name Authorization and value Bearer followed by a space and your SelfPing key.\n\nChoose Listen for test event. POST this JSON to the Test URL using the inbound secret header:\n`{\"event\":\"lead.saved\",\"lead_id\":\"sample-001\",\"qualified\":true}`\nThis sends one real text and uses one credit. Check your phone and final delivery in SelfPing. Free accounts get 10 texts/month; Hobby is $5/month for 100.\n\nPublish and switch to the Production URL. Replay the same ID: no second text. Send qualified:false: no text. Omit lead_id: the execution fails. Use globally unique IDs with 1-100 letters, digits, underscores, or hyphens. Do not send personal lead details.\n\n### Customization\nEdit the fixed SMS to name your CRM. Keep lead storage and qualification in your app. See the delivery note before retrying a failed send. Tested with n8n 2.47.7.\n\n[Full setup guide](https://www.selfping.com/recipes/n8n-sms-alert?utm_source=n8n&utm_medium=template&utm_campaign=qualified_lead)",
        "height": 900,
        "width": 560,
        "color": 1
      },
      "id": "5d1821e1-7b8a-4d68-8d60-7bcd345be14b",
      "name": "Start here",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -680,
        -200
      ]
    },
    {
      "parameters": {
        "content": "## Validate saved-lead events\nAccept an authenticated event after your app saves a lead. Ignore unrelated events and unqualified leads; reject malformed lead fields. Only the lead ID continues.",
        "height": 330,
        "width": 520,
        "color": 7
      },
      "id": "0d624291-cf1d-49bd-9117-7b1d7d97db91",
      "name": "Validate saved-lead events",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -130
      ]
    },
    {
      "parameters": {
        "content": "## Suppress repeats and notify\nKeep a history of 10,000 lead IDs. Only Kept reaches the SMS node. Clearing history or evicting old IDs allows them through again; suppression is best effort.",
        "height": 330,
        "width": 520,
        "color": 7
      },
      "id": "85288a72-a003-4f3f-87f1-995e15bdcc3c",
      "name": "Suppress repeats and notify",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        500,
        -130
      ]
    },
    {
      "parameters": {
        "content": "## Check delivery before retrying\nNo automatic retries. A timeout can leave delivery uncertain, and the ID may remain in history after failure. Inspect SelfPing delivery status before deliberately retrying Text myself. Never change an ID to bypass the filter. Notification failures must not undo saved leads. The webhook response confirms receipt only.",
        "height": 270,
        "width": 520,
        "color": 3
      },
      "id": "cbcebf4d-71db-43a0-a039-39a929ed199f",
      "name": "Check before retrying",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        500,
        250
      ]
    }
  ],
  "connections": {
    "Lead saved": {
      "main": [
        [
          {
            "node": "Keep qualified leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep qualified leads": {
      "main": [
        [
          {
            "node": "Skip seen lead IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip seen lead IDs": {
      "main": [
        [
          {
            "node": "Text myself",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "tags": []
}
