📄 SKILL.md

← Vault

name: chatwoot-painel-kanban-integration

description: "Build a Kanban dashboard inside Chatwoot that mirrors Painel do Corretor stages, with bidirectional sync: Chatwoot webhook → Painel API, and Painel polling → Chatwoot labels."

category: devops


Chatwoot + Painel do Corretor — Kanban Integration

Architecture

`

┌─────────────────────┐ webhook ┌──────────────────────────────┐

│ Chatwoot (VPS) │ ───────────────► │ Edge Function chatwoot-webhook │

│ conversation_new │ │ → INSERT chatwoot_painel_map │

└─────────────────────┘ │ → POST /api/crm/negocios │

▲ └──────────────────────────────┘

│ polling 15min │

│ ┌──────────────────────────────────┘

│ ▼

┌─────────────────────┐ polling ┌──────────────────────────────┐

│ Painel do Corretor │ ◄─────────────── │ Edge Function sync-painel-to-chatwoot │

│ (api.paineldocorretor) │ │ → GET /api/crm/negocios │

└─────────────────────┘ │ → PUT conversation labels │

│ └──────────────────────────────────┘

│ │

▼ ▼

┌──────────────────────────────────────────────────────────────────┐

│ Chatwoot Kanban Dashboard App (React, served at /kanban/) │

│ 6 columns: Novos Leads / Qualificação / Reunião agendada / │

│ Proposta Enviada / Remarketing / Fechado │

└──────────────────────────────────────────────────────────────────┘

`

Etapas (Painel stages) — 10 colunas no Kanban

Etapas (Panel stages) — 10 colunas no Kanban

`

Novos Leads | Qualificação | Remarketing | Reunião agendada |

Proposta Enviada p/cliente | Análise Seguradora | Aguardando Pagamento |

Fechado | Declinado | Sem Interesse

`

Nota: etapa é TEXT (nome da etapa, ex: "Novos Leads"). Mapeamento:

`

1 → novos_leads

2 → aguard_retorno

3 → conversao

4 → aguard_aceitacao

5 → proposta_enviada

6 → aguard_proposta

7 → aguard_seguro

8 → vendido

9 → sem_interesse

`

Cores por etapa:

`

1 (Novos Leads): #6B7280 (cinza)

2 (Aguard. Retorno): #F59E0B (âmbar)

3 (Conversão): #3B82F6 (azul)

4 (Aguard. Aceitação):#8B5CF6 (roxo)

5 (Proposta Enviada): #06B6D4 (cyan)

6 (Aguard. Proposta): #EAB308 (amarelo)

7 (Aguard. Seguro): #10B981 (verde)

8 (Vendido): #22C55E (verde forte)

9 (Sem Interesse): #EF4444 (vermelho)

`

Database Table

`sql

CREATE TABLE public.chatwoot_painel_map (

id uuid DEFAULT gen_random_uuid() PRIMARY KEY,

account_id INTEGER DEFAULT 1,

contato TEXT NOT NULL, -- nome do lead

telefone TEXT, -- normalizado: só números, sem + (Chatwoot tem, Panel NÃO)

email TEXT, -- Panel tem email, Chatwoot NÃO

seguimento TEXT, -- ex: "SEGURO DE VIDA"

etapa TEXT DEFAULT 'Novos Leads', -- nome da etapa no Panel (ex: "Novos Leads", "Remarketing")

etapa_anterior TEXT,

origem TEXT, -- fonte do lead

ultima_interacao TIMESTAMPTZ,

painel_negocio_id UUID, -- ID do lead no Panel (para PUT etapa)

chatwoot_conversation_id BIGINT,

criado_em TIMESTAMPTZ DEFAULT now(),

atualizado_em TIMESTAMPTZ DEFAULT now(),

UNIQUE(painel_negocio_id)

);

`

Coluna correta: contato (NÃO nome), telefone (NÃO chatwoot_contact_phone), etapa é INTEGER (não TEXT).

RLS Policies (required for REST API access)

`bash

npx supabase db query "CREATE POLICY \"Allow all read\" ON public.chatwoot_painel_map FOR SELECT USING (true);" --linked

npx supabase db query "CREATE POLICY \"Allow all insert\" ON public.chatwoot_painel_map FOR INSERT WITH CHECK (true);" --linked

npx supabase db query "CREATE POLICY \"Allow all update\" ON public.chatwoot_painel_map FOR UPDATE USING (true);" --linked

`

Edge Functions

chatwoot-webhook