← story.propek
STORY 7.1
Integracao Melhor Envio Tracking (CRM Fase 1)
Epic: CRM Propek
IN PROGRESS
2026-03-22
Integrar webhooks do Melhor Envio ao bot WhatsApp para rastreamento automatico de envios. Quando o status de um envio muda, o bot notifica o cliente via WhatsApp. O bot tambem responde "cade meu pedido?" consultando o status atual.
ACCEPTANCE CRITERIA (10/10)
1. Config module `melhor-envio.ts` com env vars e singleton pattern
2. Migration `021_create_shipments_table.sql` com tabela shipments
3. Service `melhor-envio.service.ts` com cliente da API (tracking + webhook registration)
4. Handler `melhor-envio.handler.ts` com webhook handler (processa status changes)
5. Webhook verification via X-ME-Signature (HMAC-SHA256)
6. Rotas registradas em `index.ts` (GET verify + POST handler)
7. Bot envia notificacao WhatsApp quando status muda (6 templates)
8. Bot responde "cade meu pedido?" consultando tabela shipments (service pronto)
9. Idempotencia: mesmo webhook processado 2x nao duplica notificacao
10. TypeScript compila sem erros (`npx tsc --noEmit`)