← Blog

How to create automation flows from scratch

Automating tasks doesn't have to be complicated. In this guide, you will learn to design and publish a simple flow: from objective to trigger, passing through actions, conditions, and tests. We will use n8n and integrate with Kommo CRM, showing practical steps, webhooks, and VPS hosting. In the end, you will have a functional and replicable workflow, with good security and monitoring practices.

From objective to the right trigger

Look: good automation starts with the business problem and ends in an action that generates money. No frills. The rule is simple — define the target, choose the trigger, and cut the rest. Let's get practical.

  • Objective: respond to new leads within 5 minutes during business hours, move to Qualification and ensure an automatic follow-up task.
  • Trigger: new lead received (form, forwarded email, or WhatsApp) creating the lead in Kommo.
  • Inputs: name, phone and/or email, origin/campaign, interest, date/time, responsible. Outputs: initial message sent, task created, stage updated, origin tag, first contact log.
  • Success criteria: 90% of leads responded to in < 5 min; 100% with task created; duplication rate < 5%; implementation within 2 calendar days; daily report with SLA.

Pocket rule: if it doesn't improve speed, priority, or predictability, there's excess in the flow.

  1. Event: new lead created in Kommo at the stage New.
  2. Normalize data: standardize phone (DDD+9), email, and name.
  3. Deduplication: if already exists by phone/email, merge and keep history.
  4. Validation: if contact is missing, mark tag incomplete-contact and create research task (10 min).
  5. Initial response: send short message (WhatsApp/Email) with introduction + closed question (“can I call you now or do you prefer tomorrow morning?”).
  6. Create task: follow-up in 15 min if no response; assign responsible and high priority.
  7. Move stage: from New to Qualification.
  8. Register: origin, tags, field “primeiro_contato_at” and SLA.
  9. Next action: if qualified, prepare Proposal; if won/lost, move to Closed with reason.

That's it: flow starts at new lead event and ends with initial message sent + task created. Next step, we plug this into a lightweight workflow (n8n) to run smoothly.

First flow in n8n

Let's get practical, no fluff. Installation: local (machine with Docker) or on a cheap VPS runs smoothly. n8n starts fast and runs via browser; at the end of the article there's an installation tutorial. Here, focus on the minimum viable flow.

  1. Trigger: choose Webhook (recommended for leads) or Cron (routines). In Webhook, use the test URL to validate and then the production one. Goal: receive the lead in real time.
  2. Set: normalize fields. Standardize keys like name, email, phone, source, timestamp. This avoids mess downstream.
  3. IF: validate required fields. If missing email and phone, divert to an “incomplete” output (you can just log and end). If OK, continue.
  4. HTTP Request: simple enrichment. Ex.: verify email in a validation service or fetch data by ZIP/CNPJ. Return only useful info (city, score, segment).
  5. Wait: add 1–3s to respect cadence and rate limits. In campaigns, this saves your sending reputation.
  6. HTTP Request: initial response to lead (email/WhatsApp via your provider). Short, useful message with clear next step.
  7. HTTP Request: log in spreadsheet/database (your repository API). Save payload, status, and timestamp.

Save, activate and version: name the flow clearly (e.g., “Inbound — Capture and Response 1.0”), save and activate. Use descriptions in nodes and

tags like “prod”, “test”, “lead”.

Monitor in Executions (logs), set error alerts. Credentials: create in Credentials, never in plain text; use environment variables on the server. Version: export the flow and version in your Git. That's it. Let's go.

Connect to Kommo CRM

Look: integrating the n8n flow with Kommo is what turns leads into sales, okay? No fluff. Focus on proper authentication, create/update records and react to real-time events.

  • OAuth (recommended): create the app in Kommo, get Client ID/Secret and domain. Store in n8n Credentials (encrypted), minimum access and periodic rotation.
  • API Key (legacy/old accounts): use only if necessary. Store in Credentials/environment variables/secret manager. Never in node parameters.
  • Security: disable credential editing by non-admins, avoid logs with PII and don't version secrets in the repository.

Creation and update in Kommo (practical result):

  • Lead: define pipeline and initial stage; if already exists (email/phone linked to contact), update and avoid duplicates.
  • Contact: name; email and phone in standard fields; normalize phone (E.164) to match deduplication.
  • Task: define clear text and deadline; link to lead to request follow-up.
  • Quick mapping: name → lead.name/contact.name; email → contact.email; phone → contact.phone; origin → tag “Origem:X” or custom field “source”.

Webhooks in real time: configure in Kommo the events “new lead” and “status change” pointing to your n8n webhook public URL. Validate secret/signature and deduplicate by event_id.

  1. Lead arrived (Kommo webhook): get payload.
  2. Search contact by email/phone; update or create.
  3. Create/update lead in pipeline, initial stage; link contact.
  4. Add note and task D+1 (or 2h if hot inbound), responsible assigned.
  5. Send welcome message and log message ID in lead.
  • Rate limits: handle 429 with incremental backoff (2s, 4s, 8s + jitter) and concurrency control.
  • Idempotent retries: use external_id/dedupe keys to avoid duplicates.
  • Audit logs: save request_id/event_id/lead_id and PII masks. This will ease testing and scaling. Let's go.

Test, errors and scale

Look: before opening the tap, validate the end-to-end flow with your real funnel data, but anonymized. Let's get practical, no fluff: prove the flow responds, decides and logs correctly, okay?

  • Tests: real samples with PII replaced by tokens; initial volume of 50–100 events.
  • Success/error cases: valid lead, duplicate lead, invalid phone, CRM down.
  • IF paths: qualification “fit/unfit”, business hours/outside, origin organic/paid.
  • Light load test: 10–20 events/min for 10 min to find bottleneck.

Error workflows must exist before the incident:

  • Retries with incremental wait (e.g., 1m, 5m, 15m) and clear limit.
  • Timeouts per step to avoid silent hangs.
  • Alerts: email/Slack on repeated failures, with lead ID and step.
  • Quarantine problematic records for manual reprocessing.
  • Metrics: E2E response time, failure rate per step, volume per hour.
  • Define thresholds and action: e.g., failure >3% in 15 min = pause input.
  • Security: secrets outside the flow (vault/variables) and minimum access by role.
  • PII cleanup: mask, expire and remove from logs.
  • Audit logs without sensitive data.

Daily capacity: 650 calls; 30% answered; 3 min cadence ≈ 585 min/day. Without queue and Wait, you crash the operation.

  • Scale: queues for peaks, debouncing of duplicates and Wait for cadence.
  • Backpressure: limit of active executions per worker.
  • VPS upgrade when CPU >70% for 15 min or queue >5x throughput.

  • Checklist: test cases covering 80% of scenarios and active metrics.
  • Alerts with responsible parties and incident playbook.
  • Secrets protected and PII sanitized.
  • Queue, Wait and debouncing configured.
  • Next steps: flow template, field standards, SLAs and tags.
  • Replicate in new processes changing IF rules and cadence. Let's go.

Conclusion

You saw how to turn a goal into a real flow: define trigger, configure actions, branch with conditions, test, handle errors and publish. With n8n and Kommo CRM, you can start small and evolve safely on a VPS. Next step: standardize templates, monitor metrics and iterate continuous improvements to scale without losing quality.

I want to implement this in my company → More articles →