ComercialRS — Investigação Dispatcher WhatsApp — 26/jun/2026
Resumo Executivo
Problema reportado: Notificações WhatsApp de reunião criada não chegam.
Causa raiz: O dispatcher dispatch-automation.py (porta 9002) está PARCIALMENTE quebrado — envia mensagens mas não consegue logar no message_log (token service_role inválido). Mensagens PODEM estar sendo enviadas.
Arquitetura do Dispatcher (3 implementações)
1. dispatch-automation.py — PORTA 9002 (systemd) — STATUS: PARCIALMENTE QUEBRADO
- - Rodando? SIM (pid 838152, uptime Jun 25)
- - Escutando em
0.0.0.0:9002→ MAS conexões caem por timeout (não consegue se conectar) - - Roteado por Kong? NÃO — Kong envia para
172.23.0.1:9085(firecrawl_server) - - Token service_role:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InJvY2hhc2FsZXMiLCJyb2xlIjoic2VydmljZV9yb2xlIi...→ HTTP 401 INVALID via Kong REST - - Log:
/var/log/dispatch-automation.log— último POST em 25/jun 21:01 - - Método de envio: Texto plain via Meta API v18.0 (NÃO é template com botões)
- - Problema: Não consegue logar em
message_log(service_role quebrado) e não consegue enviar via Meta API (timeout de conexão) - - Rodando? SIM (pid 1434848, uptime Jun 25)
- - Aceita:
/functions/v1/firecrawl-extract-meeting✅ (auto-fill) - - Aceita:
/functions/v1/dispatch-automation✅ (dispatch) - - Token: Anon key funciona perfeitamente via Kong REST
- - Log de mensagem: Console apenas (não grava message_log)
- - Método de envio: Texto plain via Meta API v18.0 (NÃO é template com botões)
- - Auto-fill: FUNCIONA — extrai nome, data, canal do Painel do Corretor
- -
supabase/functions/dispatch-automation/index.ts - - Supabase Cloud excedeu egress quota
- - Rota específica:
/functions/v1/dispatch-automation→firecrawl-server:9085 - - Sem plugin JWT (pass-through)
- - Funciona: wget interno ao Kong confirma
{"dispatched": true, "sent_to": "...", "message_id": "wamid..."} - - 14:31:15 POST 400 (curl sem payload correto)
- - 14:31:24 POST 200 ✅ (curl com payload correto)
- - 14:40:19 POST 200 ✅
- - 14:47:23 POST 200 ✅
- - 14:56:02 POST 200 ✅
- -
firecrawl_server.pyenvia texto plain viasend_text_message()(linha 217) - - Deveria enviar
nova_reuniao_criadabutton template para ativar botões "iniciada/concluída/remarketing" - - Sem botão, corretor não consegue marcar reunião como iniciada/concluída pelo WhatsApp
- - firecrawl_server tenta INSERT com anon key → HTTP 400 (RLS ou permissão)
- - Sem log, não há rastreamento de quais mensagens foram enviadas
- - dispatch-automation.py tenta com service_role → HTTP 401 (token inválido)
- - Token em
dispatch-automation.py:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIwMDAwMDAwMC... - - Assinado com JWT secret antigo do Kong
- - Kong atual usa:
OyIoGm7w#k$NX9!pQ2yF&jRm8Z@TvL5sX - - Resultado: qualquer tentativa de INSERT/UPDATE com service_role → 401
- - Pietra (1cfbe04c): phone=NULL → Brunna Stival, Gean Motos não recebem WhatsApp
- - Nayara (64f9449f): phone=NULL → Ricardo Minholi não recebe
- - Rayca, Maju, Raissa: NULL (não afeta tasks de hoje)
- - ✅ Kong → firecrawl_server (dispatch-automation): 200 OK, wamid retornado
- - ✅ Kong REST → automations_config: anon key funciona
- - ✅ Kong REST → message_log INSERT: anon key → HTTP 400
- - ✅ Kong REST → message_log INSERT: service_role → HTTP 401
- - ✅ Meta API v18.0: envio direto funciona
- - ✅ Auto-fill firecrawl-extract-meeting: funciona perfeitamente
- - ❌ dispatch-automation.py (porta 9002): conexão timeout
- - VPS: 31.97.243.106
- - Kong: 8000 (ext), 8001 (admin)
- - Kong PostgREST JWT secret:
OyIoGm7w#k$NX9!pQ2yF&jRm8Z@TvL5sX - - Anon key:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InJvY2hhc2FsZXMiLCJyb2xlIjoiYW5vbiIsImlhdCI6MTc4MjE0MDAxMiwiZXhwIjoxODEzNjc2MDEyfQ.zSTyXFB2i9xsPJQ0rTCEhEL0JnMTj0brfExdqa85VWU - - firecrawl_server:
/var/www/comercialrs/firecrawl_server.py - - dispatch-automation.py (9002):
/var/www/comercialrs/dispatch-automation.py - - Kong access log: dentro do container
deploy-vps-kong-1:/usr/local/kong/logs/access.log
2. firecrawl_server.py — PORTA 9085 (systemd) — STATUS: FUNCIONANDO
3. Supabase Edge Function — STATUS: NÃO ATIVO
Kong Routing — /functions/v1/dispatch-automation
Kong roteia para: http://172.23.0.1:9085 (firecrawl_server)
Logs de Acesso — Kong /functions/v1/dispatch-automation
###Hoje (26/jun) — Browser requests:
`
13:44:04 POST 400 35 Chrome → falha
13:55:51 POST 200 59 OPR → sucesso?
14:11:52 POST 200 59 OPR → sucesso?
14:12:19 POST 400 35 Chrome → falha
14:12:20 POST 200 126 Chrome → sucesso
14:12:21 POST 200 126 Chrome → sucesso
14:12:21 POST 400 35 OPR → falha
14:12:29 POST 400 35 Chrome → falha
14:12:30 POST 200 126 Chrome → sucesso
14:12:52 POST 400 35 Chrome → falha
14:13:00 POST 200 128 OPR → sucesso
14:13:05 POST 400 35 OPR → falha
14:13:14 POST 400 35 Chrome → falha
14:27:42 POST 200 128 Chrome → sucesso (último antes de ir pra reuniões)
14:27:48 POST 400 35 Chrome → falha
14:27:52 POST 400 35 Chrome → falha
14:28:48 POST 200 59 Chrome → sucesso
14:29:32 POST 200 128 OPR → sucesso
14:29:35 POST 400 35 OPR → falha
14:29:50 POST 400 35 Chrome → falha
`
Análise: 20 requests de browser entre 13:44-14:29. ~60% 200, ~40% 400.
O dispatcher ESTAVA sendo chamado pelo browser durante uso normal.
###mysqld CURL tests (ignorar):
Tasks Criadas Hoje (26/jun) — 23 total
| Hora | Título | Responsável | Telefone | Status |
| ------ | -------- | ------------- | ---------- | -------- |
| 13:41 | Gean Motos | Pietra | NULL | Sem WhatsApp |
| 13:43 | Kundalini Yoga/ Tâmisa | Victoria | 5511983877212 | ✅ |
| 13:55 | Brunna Stival | Pietra | NULL | Sem WhatsApp |
| 14:11 | Michele Garcia | Raiany | 11944404184 | ✅ |
| 14:12 | Daniela Costa | Rafael | 5511989793356 | ✅ |
| 14:27 | Sirley Moura | Victoria | 5511983877212 | ✅ |
| 14:28 | Ricardo Minholi | Nayara | NULL | Sem WhatsApp |
| 14:29 | Onceição Teixeira | Rafael | 5511989793356 | ✅ |
message_log: ZERO entradas para hoje (INSERT falha com anon key — RLS)
Problemas Identificados
###1. Mensagem NÃO é template com botões
###2. message_log não é gravado
###3. service_role token quebrado
###4. responsible_phone NULL em team_members
Fluxo Atual
`
Browser → Kong :8000 → Kong route /functions/v1/dispatch-automation
→ Kong upstream: http://172.23.0.1:9085
→ firecrawl_server.py (Python, pid 1434848)
→ get_meta_config() via Kong REST (anon key ✅)
→ send_text_message() via Meta API v18.0 ✅
→ console.log only (não grava message_log)
`
Correções Necessárias
###Crítico (agora):
1. firecrawl_server deve enviar template com botões — não texto plain
2. Corrigir INSERT message_log — usar anon key com RLS correto, ou remover essa dependência
###Médio prazo:
3. Adicionar telefones NULL em team_members (Pietra, Nayara)
4. Remover dispatch-automation.py (porta 9002) quebrado para evitar confusão
5. Considerar migrar toda lógica pro firecrawl_server