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.
How it works
- Receive the incoming WhatsApp message.
- Look up the sender's phone in your Leads sheet.
- If they're new, add them with their name, first message and date.
- Alert your sales team on Telegram so someone replies quickly.
Diagram
Code
JavaScript used in the Code step — already included in the template below.
// 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.
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": []
}In Make, create a new scenario and add these modules in order:
- WhatsApp Business Cloud › Watch Events (messages)
- Tools › Set variable / Iterator + Array aggregator (same logic as the Code step)
- Google Sheets › Search Rows (by order_id)
- Filter on the next route: “New contact?”
- If yesGoogle Sheets › Add a Row
- If yesTelegram Bot › Send a Text Message or a Reply
- Every module run uses Make operations — the free plan includes a monthly quota.
- Make's built-in functions (map, sum, formatDate…) can replace most Code steps; for complex logic use a code module.
- Module and step names can differ slightly as Make and Zapier update their apps.
In Zapier, create a new Zap and add these steps in order:
- WhatsApp — New Message
- Code by Zapier — Run JavaScript (paste the code from the Code section)
- Google Sheets — Lookup Spreadsheet Row
- Filter by Zapier: “New contact?”
- If yesGoogle Sheets — Create Spreadsheet Row
- If yesTelegram — Send Message
- Zaps with more than two steps need a paid Zapier plan.
- Webhooks, Filters/Paths and Code by Zapier are premium features on some Zapier plans.
- Code by Zapier runs JavaScript: reuse the code shown above, reading inputs from inputData instead of $json.
- Module and step names can differ slightly as Make and Zapier update their apps.
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
WhatsApp sales AI agent (Arabic)
Sells on WhatsApp in the customer's own dialect: checks your catalog, answers questions and takes cash-on-delivery orders.
Automatic follow-up when a lead doesn't reply
If someone hasn't replied 3 days after your email, send a polite follow-up automatically.
Order & returns AI agent on WhatsApp (Arabic)
Answers "where's my order?", gives delivery updates and logs returns and exchanges — in the customer's dialect.