{
  "id": "xzqIjPM9C0AI4Zw0",
  "name": "Lead Qualification and Outreach with CometAPI",
  "tags": [],
  "nodes": [
    {
      "id": "4e06e353-35c5-4097-8a29-dc8c388d768d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        16
      ],
      "parameters": {
        "width": 800,
        "height": 880,
        "content": "## Lead Qualification and Outreach with CometAPI\n\n### How it works\n\nThis workflow monitors a Google Sheet for new leads, scores each lead using CometAPI, and extracts the numeric score for routing. Leads with scores greater than 7 are summarized, used to generate an outreach email, and then emailed via Gmail. Both contacted qualified leads and lower-scoring leads are recorded back into Google Sheets through the final save step.\n\n### Setup steps\n\n- Connect Google Sheets credentials for both the trigger and the results-writing node.\n- Configure the source spreadsheet/range in the New Lead from Sheet trigger and the destination spreadsheet/range in Save Results.\n- Add CometAPI credentials and prompts/settings for the Score Lead, Summarize Lead, and Write Outreach Email nodes.\n- Connect Gmail credentials and configure the sender, recipient mapping, subject, and body fields in Send Outreach Email.\n- Verify the Extract Score code matches the response format returned by the Score Lead CometAPI node.\n\n### Customization\n\nAdjust the qualification threshold in the IF node, update CometAPI prompts for your lead scoring and email tone, and change the Google Sheets columns used for lead data and result logging."
      },
      "typeVersion": 1
    },
    {
      "id": "423e650c-98a0-4f2c-b9ca-e7a511b8f11c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        352,
        96
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 432,
        "content": "## Capture and score lead\n\nThis left-side cluster starts the workflow when a new Google Sheets lead appears, sends the lead to CometAPI for scoring, and parses the returned score into a usable value."
      },
      "typeVersion": 1
    },
    {
      "id": "008ceb3a-424e-4dec-8d48-60b90f396846",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1024,
        176
      ],
      "parameters": {
        "color": 7,
        "width": 272,
        "height": 320,
        "content": "## Check qualification threshold\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e4579168-e0f0-4d98-a0e1-d30495138aab",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1328,
        80
      ],
      "parameters": {
        "color": 7,
        "width": 624,
        "height": 480,
        "content": "## Create and send outreach\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9c900aca-28cd-4e66-bb3c-0b4643f3998d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1984,
        208
      ],
      "parameters": {
        "color": 7,
        "height": 352,
        "content": "## Save lead results\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "b5680c5b-52b5-4de5-b786-c94e9075bec7",
      "name": "When New Lead Added",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "position": [
        432,
        304
      ],
      "parameters": {
        "event": "rowAdded",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1uIJUsfl3CioiIE2glmcds7fpvNYlY84waqSKFKzvW7g/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1uIJUsfl3CioiIE2glmcds7fpvNYlY84waqSKFKzvW7g",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1uIJUsfl3CioiIE2glmcds7fpvNYlY84waqSKFKzvW7g/edit?usp=drivesdk",
          "cachedResultName": "Leads Data"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "135ca732-b4a1-464e-9e79-7488db364ade",
      "name": "Qualify Lead via CometAPI",
      "type": "@cometapi-dev/n8n-nodes-cometapi.cometApi",
      "position": [
        640,
        320
      ],
      "parameters": {
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Score this lead from 1 to 10 based on how likely they are to buy, using this data: name {{ $json.Name }}, company {{ $json.Company }}, message {{ $json.Message }}. Reply with only the number and one short reason."
            }
          ]
        }
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "875cbfe8-aafa-4468-8f35-cdf1f3adc15b",
      "name": "Summarize Lead Info",
      "type": "@cometapi-dev/n8n-nodes-cometapi.cometApi",
      "position": [
        1392,
        176
      ],
      "parameters": {
        "options": {},
        "messages": {
          "values": [
            {
              "content": "= Summarize this lead in 2 to 3 sentences, highlighting their needs and how they found us. Lead message: {{ $node[\"New Lead from Sheet\"].json.Message }}"
            }
          ]
        }
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "7bf70705-c4ed-4ddd-91ab-9509d9678043",
      "name": "Update Lead Data in Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2032,
        320
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={{ $('When New Lead Added').item.json.Name }}",
            "Email": "={{ $('When New Lead Added').item.json.Email }}",
            "Score": "={{ $node[\"Score Lead\"].json.choices[0].message.content }}",
            "Company": "={{ $('When New Lead Added').item.json.Company }}",
            "Message": "={{ $('When New Lead Added').item.json.Message }}",
            "Summary": "={{ $node[\"Summarize Lead\"].json.choices[0].message.content }}",
            "Email Draft": "={{ $json.choices[0].message.content }}"
          },
          "schema": [
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Score",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Score",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email Draft",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email Draft",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LwP-nJeGyZARSvBEaJmWztlktw8jaqc9WHnO3OgPLtI/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1LwP-nJeGyZARSvBEaJmWztlktw8jaqc9WHnO3OgPLtI",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LwP-nJeGyZARSvBEaJmWztlktw8jaqc9WHnO3OgPLtI/edit?usp=drivesdk",
          "cachedResultName": "Leads Data"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "d7c17fac-6bec-4d86-8ac9-c95c69a20b64",
      "name": "Draft Outreach Email",
      "type": "@cometapi-dev/n8n-nodes-cometapi.cometApi",
      "position": [
        1584,
        176
      ],
      "parameters": {
        "options": {},
        "messages": {
          "values": [
            {
              "content": "= Write a short, friendly outreach email to {{ $node[\"New Lead from Sheet\"].json.Name }} at {{ $node[\"New Lead from Sheet\"].json.Company }}, based on this summary: {{ $node[\"Summarize Lead\"].json.choices[0].message.content }}. Keep it under 120 words and end with a clear call to action."
            }
          ]
        }
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "4111c493-4d5b-4398-ade9-fd77a9e75152",
      "name": "Extract Lead Score",
      "type": "n8n-nodes-base.code",
      "position": [
        848,
        304
      ],
      "parameters": {
        "jsCode": " const text = $node[\"Score Lead\"].json.choices[0].message.content;\nconst match = text.match(/\\d+/); \nconst score = match ? parseInt(match[0]) : 0;\n\nreturn [{\n  json: {\n    ...$node[\"New Lead from Sheet\"].json,\n    scoreText: text,\n    scoreNumber: score\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "76dcd7ea-eca4-453e-b3ab-3930c4c8ebd9",
      "name": "Send Email via Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1792,
        176
      ],
      "parameters": {
        "sendTo": "={{ $node[\"New Lead from Sheet\"].json.Email }}",
        "message": "={{ $node[\"Write Outreach Email\"].json.choices[0].message.content }}",
        "options": {},
        "subject": "={{ \"Following up on your inquiry, \" + $node[\"New Lead from Sheet\"].json.Name }}"
      },
      "typeVersion": 2.2
    },
    {
      "id": "425d6e7f-0ffa-4a84-b3ad-d4d3f82f0fa8",
      "name": "Check Lead Score Threshold",
      "type": "n8n-nodes-base.if",
      "position": [
        1088,
        304
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "14ac5f11-5524-4b82-bf4d-00aec48f45b6",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.scoreNumber }}",
              "rightValue": 7
            }
          ]
        }
      },
      "typeVersion": 2.3
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "0ea612d1-d718-4d50-9a90-f6c0573d3c88",
  "nodeGroups": [],
  "connections": {
    "Extract Lead Score": {
      "main": [
        [
          {
            "node": "Check Lead Score Threshold",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Summarize Lead Info": {
      "main": [
        [
          {
            "node": "Draft Outreach Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When New Lead Added": {
      "main": [
        [
          {
            "node": "Qualify Lead via CometAPI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Draft Outreach Email": {
      "main": [
        [
          {
            "node": "Send Email via Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email via Gmail": {
      "main": [
        [
          {
            "node": "Update Lead Data in Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Qualify Lead via CometAPI": {
      "main": [
        [
          {
            "node": "Extract Lead Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Lead Score Threshold": {
      "main": [
        [
          {
            "node": "Summarize Lead Info",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Lead Data in Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}