跳到正文

第 23 课 · Projects and Reference

Project: Lead Intake Pipeline

Build a lead intake workflow in n8n from a form: validate and clean input, prevent duplicates, route by score, notify the team and handle every failure safely.

In this project you design a complete workflow that collects leads from a form, cleans them, avoids duplicates, routes them and reports failures. Use test data only. The runnable stand-ins let you check the logic before you build in n8n.

The specification

Requirement Detail
Input Form: name, email, company, message, consent checkbox
Reject Missing consent or invalid email
Duplicates Same email is updated, not added again
Routing Score of 5 or more goes to sales
Reply The person sees a confirmation page
Failure Team is alerted; no lead is lost

The workflow

flowchart LR
  F["n8n Form"] --> C["Clean fields"]
  C --> V{"Valid?"}
  V -->|no| R["Review list"]
  V -->|yes| U["Upsert contact"]
  U --> S["Score"]
  S --> W{"Score 5+?"}
  W -->|yes| N["Notify sales"]
  W -->|no| L["Newsletter list"]

Invalid entries are kept for review rather than silently discarded.

Build steps

  1. n8n Form trigger with the five fields. Mark name, email and consent required, and explain how you will use the data.
  2. Edit Fields to clean: trim text and lowercase the email.
  3. If node to check consent and email format.
  4. Write to your store with an upsert keyed on email. A data table, spreadsheet or database can work for practice. A unique constraint is the strongest protection.
  5. Edit Fields or Code node to compute a score.
  6. Switch or If to route.
  7. A notification node for sales, with only the data they need.
  8. Set an error workflow in the settings.
  9. Test, then publish and use the production form URL.

Useful expressions:

TEXT
email    = {{ ($json.email ?? '').trim().toLowerCase() }}
name     = {{ ($json.name ?? '').trim() }}
domain   = {{ $json.email.split('@')[1] }}

The exact field names depend on your form labels, so check the trigger's output first.

Test the rules first

Python Stand-in: validation, upsert and scoring

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the second call: it updates Amara's record with an empty company. That is a real design question. You may want to keep old values when new ones are blank. Decide, then test it.

Test plan

Run each case through the test form URL:

  • valid business lead, expect sales;
  • same email again with different capitals, expect one record;
  • missing consent, expect review;
  • very long message and special characters;
  • break the notification credential on purpose in a test copy and check the error alert arrives from a published, automatic run.
JS Stand-in: build a minimal sales message

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Security and privacy review

  • Protect the public form against spam.
  • Do not store more than you need, and set a retention period.
  • Do not paste message text into SQL; use parameters.
  • Restrict who can read the lead store and the execution history.

Extensions

  • Add an AI step that suggests a category, with a validator and a human check (AI Agent).
  • Add a sub-workflow for notifications.
  • Send a weekly summary using Summarize.

Review your design

Before you call the project done, walk through it as three different people. As the visitor, is it clear what the form is for, what happens next and how to ask for your data to be deleted? As the salesperson, does the notification have enough to act on, and no more than that? As the maintainer, can you tell from the execution list why a particular lead was routed the way it was?

Then think about change. Sales may later ask for a new scoring rule, such as extra points for a certain country. Keep all scoring in one node with a short comment for each rule, so you can edit it without hunting through the canvas. Keep your test cases in a list and run them again after every change. If scores start to surprise people, record the reasons, such as "company given" and "asked about pricing", next to the total. A score you can explain is easier to trust and to correct.

Finally, decide how long leads stay in the review list and who looks at it. A review queue that no one opens is the same as losing the data.

Review questions

Answer these before publishing. Where is the lead data stored, who can read it and when is it deleted? What happens if the store is unavailable at the moment someone submits the form? Does the confirmation page promise only what the workflow really does? How does someone withdraw consent? And how would you notice if the form stopped receiving submissions altogether? A project is finished when you can answer these clearly, not merely when one test run turns green.

Keep a change log

Note each change to the rules, with the date, the reason and the test cases you ran. When a salesperson asks why a lead went elsewhere last week, you can answer quickly.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. What should happen to invalid leads in this design?

    Keeping them for review means nothing is lost.
  2. 2. Why lowercase the email before upsert?

    A normalized key matches the same address reliably.
  3. 3. How should you test the error alert?

    Error workflows run for automatic executions.

Summary

  • Write the rules and test cases before building.
  • Clean and validate input, and upsert on a normalized key.
  • Route on a clear score and keep invalid entries for review.
  • Alert on failures and protect personal data.

Next: Project: Daily Digest with AI Summary

你的学习进度保存在此浏览器中,无需账号。