Lead generation becomes difficult when enquiries arrive from multiple channels and someone has to manually read, qualify, copy, and assign every lead.
A simple automation can remove most of this repetitive work.
In this tutorial, we'll build an AI-powered lead qualification workflow with n8n.
The workflow will:
Receive a lead through a webhook
Extract useful information from the enquiry
Calculate a qualification score
Decide whether the lead is qualified
Prepare the lead for CRM/sales processing
Return a structured response
The architecture looks like this:
Lead Source
↓
Webhook
↓
AI / Lead Analysis
↓
Information Extraction
↓
Lead Scoring
↓
Qualified?
/ \
Yes No
↓ ↓
Sales Nurture
The advantage of this approach is that AI handles the understanding, while n8n handles the business logic.
What we'll build
Imagine a customer sends:
Hi, I'm looking for an AI chatbot for my real estate company in Dubai. We have around 500 enquiries per month and need something urgently. Our budget is around $2,000.
We want the automation to turn that unstructured message into something like:
{
"name": "Unknown",
"company": "Unknown",
"industry": "Real Estate",
"service": "AI Chatbot",
"location": "Dubai",
"budget": 2000,
"urgency": "High",
"leadScore": 90,
"qualified": true
}
The sales team doesn't need to manually interpret the original message.
- Create the n8n workflow
Create a new workflow in n8n.
Add a Webhook node.
Configure it as:
HTTP Method: POST
Path: lead-qualification
Response Mode: Last Node
Your webhook endpoint will look similar to:
https://your-n8n-domain.com/webhook/lead-qualification
For local development, you can use the test URL generated by n8n.
- Send a test lead
You can test the webhook with cURL.
curl -X POST "https://your-n8n-domain.com/webhook/lead-qualification" \
-H "Content-Type: application/json" \
-d '{
"name": "John Smith",
"company": "Example Property Group",
"message": "We are a real estate company in Dubai looking for an AI chatbot. Our budget is around $2000 and we need it urgently."
}'
The Webhook node will now receive the lead.
- Extract the lead information
Next, add a Code node.
Rename it:
Extract Lead Data
For this example, we'll use simple JavaScript to prepare the incoming data.
const lead = $json;
const name = lead.name || "";
const company = lead.company || "";
const message = lead.message || "";
return [
{
json: {
name,
company,
message,
receivedAt: new Date().toISOString()
}
}
];
This gives the rest of the workflow a predictable structure.
- Add AI-powered analysis
Now we can use an AI model to understand the customer's message.
You can use an OpenAI node or another LLM integration available in your n8n setup.
The important part is the prompt.
Use something similar to:
You are a lead qualification assistant.
Analyze the customer enquiry below.
Extract:
- industry
- service
- location
- budget
- urgency
- buying_intent
Return ONLY valid JSON.
Customer message:
{{ $json.message }}
A possible AI response would be:
{
"industry": "Real Estate",
"service": "AI Chatbot",
"location": "Dubai",
"budget": 2000,
"urgency": "High",
"buying_intent": "High"
}
For production systems, validate the AI response before allowing it to trigger business-critical actions.
- Calculate the lead score
Now we move the deterministic business logic into n8n.
Add another Code node called:
Calculate Lead Score
Example:
const lead = $json;
let score = 0;
if (lead.service) {
score += 30;
}
if (lead.budget) {
score += 20;
}
if (lead.urgency === "High") {
score += 20;
}
if (lead.location) {
score += 20;
}
if (lead.industry) {
score += 10;
}
const qualified = score >= 60;
return [
{
json: {
...lead,
leadScore: score,
qualified
}
}
];
Now the workflow has a simple rule:
Score >= 60 → Qualified
Score < 60 → Nurture
- Add an IF node
Add an IF node.
Configure the condition:
Value 1:
{{ $json.leadScore }}
Operation:
larger or equal
Value 2:
60
The workflow now splits into two paths.
Lead Score
|
+------+------+
| |
>= 60 < 60
| |
Qualified Nurture
- Handle qualified leads
For qualified leads, you could connect the workflow to your CRM.
For example:
Qualified Lead
↓
CRM
↓
Sales Notification
↓
Calendar / Follow-Up
You could create a CRM record containing:
{
"name": "John Smith",
"company": "Example Property Group",
"industry": "Real Estate",
"service": "AI Chatbot",
"location": "Dubai",
"leadScore": 90,
"status": "Qualified"
}
You can then notify the sales team through email, Slack, Microsoft Teams, WhatsApp or another communication channel.
- Handle unqualified leads
Not every lead should immediately go to sales.
For lower-scoring leads, create a nurture path.
Unqualified Lead
↓
CRM
↓
Nurture Sequence
↓
Follow-Up
For example, the lead could receive useful information first and be followed up later.
This prevents salespeople from spending their time manually chasing every enquiry.
- Return a response
Finally, return the result to the system that sent the lead.
For example:
{
"success": true,
"leadScore": 90,
"qualified": true,
"message": "Lead successfully qualified"
}
Now another application can immediately know whether the lead was accepted.
The final workflow can look like this:
┌──────────────────┐
│ Lead Source │
│ Website/WhatsApp │
│ Form/API │
└────────┬─────────┘
↓
┌──────────────────┐
│ Webhook │
└────────┬─────────┘
↓
┌──────────────────┐
│ Extract Data │
└────────┬─────────┘
↓
┌──────────────────┐
│ AI Analysis │
└────────┬─────────┘
↓
┌──────────────────┐
│ Lead Scoring │
└────────┬─────────┘
↓
┌────┴────┐
↓ ↓
Score ≥60 Score <60
↓ ↓
Qualified Nurture
↓ ↓
CRM CRM
↓ ↓
Sales Follow-up
Alert
Complete scoring code
Here's the complete scoring logic again so you can copy it directly into an n8n Code node:
const lead = $json;
let score = 0;
if (lead.service) {
score += 30;
}
if (lead.budget) {
score += 20;
}
if (lead.urgency === "High") {
score += 20;
}
if (lead.location) {
score += 20;
}
if (lead.industry) {
score += 10;
}
return [
{
json: {
...lead,
leadScore: score,
qualified: score >= 60
}
}
];
Why separate AI from business logic?
This is one of the most important design decisions in the workflow.
You could ask the AI:
"Is this lead qualified?"
But I wouldn't let an LLM make every business decision directly.
Instead:
AI
↓
Understand the message
↓
Extract structured information
↓
n8n
↓
Apply deterministic rules
↓
CRM / Sales / Follow-up
This makes the workflow easier to test and debug.
If your qualification criteria change, you can modify the n8n scoring logic without changing the AI prompt.
Adding WhatsApp
The same architecture can be connected to WhatsApp.
For example:
WhatsApp Message
↓
WhatsApp API
↓
n8n Webhook
↓
AI Analysis
↓
Lead Qualification
↓
CRM
↓
Sales Team
A customer could simply write:
"I need a website for my construction company. Can someone contact me tomorrow?"
The AI extracts the relevant information and n8n handles the rest.
Adding a CRM
The next step is connecting the workflow to your CRM.
Depending on the CRM you're using, you can create or update a contact automatically.
The workflow could check whether the lead already exists before creating a new record.
New Lead
↓
Search CRM
↓
Existing?
/ \
Yes No
| |
Update Create
\ /
\ /
Continue
This is important because duplicate lead records can create problems for sales teams.
Production improvements
The example above is intentionally simple.
For a production workflow, I'd add:
- AI output validation
Never blindly trust an AI response.
Validate:
Required fields
Data types
Allowed values
Score ranges
JSON structure
- Error handling
If the AI API fails, the workflow should not silently lose the lead.
Store the original enquiry and retry or send it for manual review.
- Duplicate detection
Check whether the email address, phone number or customer ID already exists.
- Human handoff
Some conversations should always go to a human.
For example:
High-value lead
↓
Salesperson
- Logging
Store important workflow events so you can understand what happened when something goes wrong.
Final architecture
A more complete production architecture could look like:
Website
WhatsApp
Facebook
Forms
│
▼
┌───────────────┐
│ n8n │
│ Webhook │
└───────┬───────┘
↓
┌───────────────┐
│ AI Extraction │
└───────┬───────┘
↓
┌───────────────┐
│ Lead Scoring │
└───────┬───────┘
↓
┌────┴─────┐
↓ ↓
Qualified Nurture
↓ ↓
CRM CRM
↓ ↓
Sales Follow-up
The important concept is that AI doesn't need to control the entire workflow.
Use AI where understanding language is difficult.
Use deterministic automation where the rules are known.
That combination gives you a system that is both flexible and predictable.
Conclusion
n8n makes it possible to build sophisticated lead-generation workflows without creating an entire automation backend from scratch.
By combining:
n8n for orchestration
AI for understanding customer messages
CRM for lead management
Webhooks/APIs for integrations
Notifications for sales teams
Automated follow-ups for nurturing
you can turn a simple enquiry into an organized sales process.
The best place to start isn't with the most complicated workflow.
Start with one bottleneck:
slow response, manual qualification, scattered lead data, or forgotten follow-ups.
Automate that process, measure the result, and expand from there.
You can also explore more AI automation solutions at Aiotagen.

Top comments (0)