
CRM tailored for the company Clubinho Corações Preciosos aimed at integrating the sales team, SDR with AI in a customized CRM for the operation.
Event-driven commercial CRM that orchestrates Bia (WhatsApp), closers, and AppMax payments in an 8-step funnel.
The Precious Hearts Club sells subscriptions for Christian children's books to families. The business does not scale with spreadsheets and manual WhatsApp: each checkout abandonment requires precise timing (audio, conversation, link, human follow-up), each annual subscriber needs to be contacted before expiration, and each recurring Pix payment needs a reminder without mixing it with the sales pipeline.
The challenge was to build an integrated business operation — not a generic CRM — that orchestrates people, automation, and AI across three distinct fronts, ensuring that a prospect lead does not receive a renewal message, that Bia does not sell to existing customers, and that confirmed payments do not get lost among resent webhooks.
The solution is an event-driven platform: each external action (abandonment, response on WhatsApp, link sent, AppMax payment, cycle expiration, upcoming Pix) enters as an event, is processed with idempotency, and moves the lead in the correct state machine. The team operates in queues and kanbans; Bia handles the automated phase; closers take over when automation runs out of time.
Problem: leads abandon checkout and cool off within minutes. Without cadence and a clear handoff, the team loses recoverable conversions.
What it does: recovers abandoned carts in eight steps (F1-01 Captured → F1-08 Converted). The journey combines automation (Reportana, Bia) and human work (closers in the Daily Queue).
General flow:
F1-01.F1-02.F1-03.F1-04.F1-05 (Bia stops selling).F1-06.F1-07.F1-08.Screens: Executive dashboard, Daily Queue, Funnel 1 Kanban, Leads, Sales performance, Conversation intelligence (objections detected by AI), Cadence, Templates, Integrations.
Differential: Bia checks the CRM before each shift (can_sell: false for active customers). The cadence has four tracks (silent, inactivity in conversation, post-link, human handoff), each anchored in the stage where the lead is.
Problem: annual subscribers need to renew before expiration. Without a dedicated pipeline, renewal competes with prospecting, commercial numbers get polluted, and the closer does not know whom to prioritize.
What it does: an isolated pipeline for active customers with cycles in subscription_cycles (expiration date, renewal number, plan). Leads from F3 do not appear in global search or in the commercial dashboard of F1; renewal sales use is_renovacao = true.
Stages: F3-01 Upcoming expiration → F3-02 Offer 1 (full price) → F3-03 Offer 2 (coupon RENOVA10) → F3-04 Offer 3 (smart payment) → F3-05 Renewed, F3-06 Lost or F3-07 Blocked.
Operational sequence (related to expiration):
F3-06 Lost.Entry into the pipeline: daily scan at D-30, CSV import from the renewal base, or manual entry. The CRM advances the stage according to the calendar; touches are manual in the Renewal Queue (priority for expired and pending touches).
Screens: Renewal Queue, Funnel 3 Kanban, Renewal Dashboard, Import base.
Problem: subscribers on recurring Pix need reminders before and after expiration, without mixing with leads in prospecting or annual renewal.
What it does: a completely separate pipeline in the crm.cobrancas table, without a sales funnel — its own kanban C-01 / C-02 / C-03.
Flow:
Phone records still in the sales funnel are removed from the pipeline; old paid ones exit the operational kanban.
Screen: Billing (kanban + realtime).
The CRM is not a “form that stores status.” It is an event engine where the lead's stage is a consequence of what happened — never manually updated by external integrations.
| Principle | What it guarantees in practice |
|---|---|
| Idempotency | Resent webhook does not duplicate lead or sale (idempotency_key unique). |
| Immutability | eventos_lead does not accept editing; correction = new event. |
| Atomic write-off | Payment confirms customer, cancels cadences, records sale, and changes stage in one transaction. |
| State machine | Webhooks do not overwrite stage; only validated RPCs transition. |
| Isolated pipelines | F1, F3, and Billing coexist without phone or metric collisions. |
Renderizando diagrama Mermaid...
webhook_events (idempotent), and calls the RPC (ingest_*).eventos_lead documents what occurred.admin, manager, closer, viewer).The Bia agent (n8n workflow) is the conversational interface of the commercial module — not the brain of the CRM:
can_bia_send).webhook-bia).schedule-payment).The critical domain (stages, cadence, sales, multi-funnel conflicts) remains in PostgreSQL — AI converses; the database governs.
Renderizando diagrama Mermaid...
funnel_conflicts with defined precedence.| Layer | Technology | Why |
|---|---|---|
| Frontend | React, Vite, TypeScript, Tailwind | Operational SPA with Realtime and RLS |
| API / ingestion | Supabase Edge Functions (Deno) | Webhooks at the edge, close to the database |
| Domain | PostgreSQL (crm schema) | Transactions, state machine, jobs |
| Jobs | pg_cron + pg_net | Cadence, 24h, temperature, charge C-02, renewal scan |
| Orchestration | n8n | Bia, WhatsApp triggers, source normalization |
| Z-API | Message input and output | |
| Conversational AI | xAI Grok + OpenAI | Bia: reasoning, STT, output formatting |
| Payments | AppMax | Confirmation and atomic write-off |
| Memory / buffer | Postgres + Redis | Bia history + message debounce |
The sales team now operates with real-time visibility: prioritized queue, kanban by stage, performance by closer, objections detected in conversations with Bia. Annual renewal has its own pipeline with a clear prevention and rescue sequence. Pix billing does not pollute the sales funnel. And the event-driven architecture ensures that, even with duplicated webhooks or unstable integrations, the lead's state reflects what actually happened — with an auditable trail in each transition.

Pipeline