Log every new WhatsApp contact as a lead

The first time someone messages your business on WhatsApp, save them to a Leads sheet and alert your sales team.

Medium Saves ~5 hours/month Sales & CRMBy Flowngn team

Works with n8n · Make · Zapier

How it works

Trigger: WhatsApp — a message arrives
  1. Receive the incoming WhatsApp message.
  2. Look up the sender's phone in your Leads sheet.
  3. If they're new, add them with their name, first message and date.
  4. Alert your sales team on Telegram so someone replies quickly.

Diagram

trueWIncoming messageWhatsApp Trigger{ }Get senderCodeGFind in LeadsGoogle Sheets⑂New contact?IfGAdd leadGoogle SheetsTAlert sales teamTelegram
Trigger App Logic Code

Code

JavaScript used in the Code step — already included in the template below.

Get sender · Code node
// Pulls the sender's phone, profile name and first message out of the WhatsApp event.
const data = $input.first().json;
const msg = data.messages?.[0];
if (!msg) return [];

return [{
  json: {
    phone: msg.from,
    name: data.contacts?.[0]?.profile?.name || "",
    message: msg.type === "text" ? msg.text.body : `(${msg.type})`,
    date: new Date(Number(msg.timestamp) * 1000).toISOString(),
  },
}];

Build it

Pick your tool — same automation, step by step.

Copy and paste straight into an n8n canvas (Ctrl+V), or download and use Import from File. Then connect your own credentials and replace every YOUR_… placeholder.

Workflow JSON
Show code (231 lines)
{
  "name": "Log every new WhatsApp contact as a lead (Flowngn)",
  "nodes": [
    {
      "parameters": {
        "content": "## Log every new WhatsApp contact as a lead\nThe first time someone messages your business on WhatsApp, save them to a Leads sheet and alert your sales team.\n\n**Setup**\n1. Open each node and connect your own credentials.\n2. Replace every YOUR_… placeholder.\n3. Test once, then activate.\n\nFree template from Flowngn",
        "height": 260,
        "width": 340
      },
      "id": "3f36c28d-dcaa-4fe7-afb0-dde2cffcb7d1",
      "name": "Setup notes",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -420,
        -60
      ]
    },
    {
      "parameters": {
        "updates": [
          "messages"
        ]
      },
      "id": "3f36c28d-dcaa-4fe7-afb0-dde2cffcb7d1",
      "name": "Incoming message",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "webhookId": "3f36c28d-dcaa-4fe7-afb0-dde2cffcb7d1"
    },
    {
      "parameters": {
        "jsCode": "// Pulls the sender's phone, profile name and first message out of the WhatsApp event.\nconst data = $input.first().json;\nconst msg = data.messages?.[0];\nif (!msg) return [];\n\nreturn [{\n  json: {\n    phone: msg.from,\n    name: data.contacts?.[0]?.profile?.name || \"\",\n    message: msg.type === \"text\" ? msg.text.body : `(${msg.type})`,\n    date: new Date(Number(msg.timestamp) * 1000).toISOString(),\n  },\n}];"
      },
      "id": "3f36c28d-dcaa-4fe7-afb0-dde2cffcb7d1",
      "name": "Get sender",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        300,
        0
      ]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "YOUR_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Leads",
          "mode": "name"
        },
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "phone",
              "lookupValue": "={{ $json.phone }}"
            }
          ]
        }
      },
      "id": "3f36c28d-dcaa-4fe7-afb0-dde2cffcb7d1",
      "name": "Find in Leads",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        600,
        0
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.phone }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "3f36c28d-dcaa-4fe7-afb0-dde2cffcb7d1",
      "name": "New contact?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        0
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "YOUR_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Leads",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "date": "={{ $('Get sender').item.json.date }}",
            "phone": "={{ $('Get sender').item.json.phone }}",
            "name": "={{ $('Get sender').item.json.name }}",
            "first_message": "={{ $('Get sender').item.json.message }}",
            "status": "new"
          }
        },
        "options": {}
      },
      "id": "3f36c28d-dcaa-4fe7-afb0-dde2cffcb7d1",
      "name": "Add lead",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1200,
        0
      ]
    },
    {
      "parameters": {
        "chatId": "YOUR_CHAT_ID",
        "text": "=New WhatsApp lead: {{ $('Get sender').item.json.name || 'no name' }} (+{{ $('Get sender').item.json.phone }})\n\"{{ $('Get sender').item.json.message }}\"",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "3f36c28d-dcaa-4fe7-afb0-dde2cffcb7d1",
      "name": "Alert sales team",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1500,
        0
      ]
    }
  ],
  "connections": {
    "Incoming message": {
      "main": [
        [
          {
            "node": "Get sender",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get sender": {
      "main": [
        [
          {
            "node": "Find in Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find in Leads": {
      "main": [
        [
          {
            "node": "New contact?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New contact?": {
      "main": [
        [
          {
            "node": "Add lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add lead": {
      "main": [
        [
          {
            "node": "Alert sales team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}

Open in the playground to edit →

Tips

  • Add a source column and ask your ads to use a pre-filled message, so you know which campaign each lead came from.

Related flows