{ "name": "📱 Evolution API → CRM | Sync WhatsApp", "nodes": [ { "parameters": { "httpMethod": "POST", "path": "evolution-webhook", "responseMode": "responseNode", "options": {} }, "id": "webhook-evolution", "name": "Webhook Evolution", "type": "n8n-nodes-base.webhook", "typeVersion": 1, "position": [240, 300], "webhookId": "evolution-whatsapp-webhook" }, { "parameters": { "conditions": { "string": [ { "value1": "={{$node[\"Webhook Evolution\"].json[\"event\"]}}", "operation": "equal", "value2": "messages.upsert" } ] } }, "id": "filter-new-message", "name": "Filtro: Nova Mensagem", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [460, 300] }, { "parameters": { "jsCode": "// Processar dados da mensagem do Evolution API\nconst webhookData = $node[\"Webhook Evolution\"].json;\n\n// Extrair dados da mensagem\nconst messageData = webhookData.data || {};\nconst fromContact = messageData.key?.remoteJid || '';\nconst messageText = messageData.message?.conversation || \n messageData.message?.extendedTextMessage?.text ||\n messageData.message?.imageMessage?.caption ||\n 'Mídia sem texto';\n\n// Limpar número de telefone (remover sufixos do WhatsApp)\nconst cleanPhoneNumber = (phone) => {\n return phone.replace('@s.whatsapp.net', '')\n .replace('@g.us', '')\n .replace('@c.us', '')\n .replace(/\\D/g, '')\n .replace(/^55/, ''); // Remove código do Brasil se presente\n};\n\n// Verificar se é um grupo\nconst isGroup = fromContact.includes('@g.us');\n\n// Pular grupos por enquanto\nif (isGroup) {\n return { skip: true, reason: 'Mensagem de grupo ignorada' };\n}\n\n// Dados processados\nconst processedData = {\n phone: cleanPhoneNumber(fromContact),\n original_phone: fromContact,\n message_text: messageText,\n timestamp: messageData.messageTimestamp || Math.floor(Date.now() / 1000),\n message_id: messageData.key?.id || '',\n instance: webhookData.instance || 'default',\n formatted_date: new Date((messageData.messageTimestamp || Date.now()) * 1000).toLocaleString('pt-BR'),\n is_from_me: messageData.key?.fromMe || false\n};\n\n// Só processar mensagens recebidas (não enviadas por nós)\nif (processedData.is_from_me) {\n return { skip: true, reason: 'Mensagem enviada por nós - ignorada' };\n}\n\n// Detectar intenção de compra/interesse baseado em palavras-chave\nconst buyingKeywords = [\n 'preço', 'quanto custa', 'valor', 'orçamento', 'comprar', 'adquirir',\n 'interessado', 'interesse', 'como funciona', 'demonstração', 'demo',\n 'teste', 'trial', 'contratar', 'assinar', 'plano', 'proposta',\n 'informação', 'informações', 'detalhes', 'saber mais'\n];\n\nconst messageWords = messageText.toLowerCase();\nconst hasBuyingIntent = buyingKeywords.some(keyword => messageWords.includes(keyword));\n\nprocessedData.buying_intent = hasBuyingIntent;\nprocessedData.priority = hasBuyingIntent ? 'ALTA' : 'NORMAL';\n\nreturn processedData;" }, "id": "process-whatsapp-message", "name": "Processar Mensagem", "type": "n8n-nodes-base.code", "typeVersion": 1, "position": [680, 300] }, { "parameters": { "conditions": { "boolean": [ { "value1": "={{$node[\"Processar Mensagem\"].json[\"skip\"]}}", "value2": true } ] } }, "id": "check-skip", "name": "Pular Processamento?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [900, 300] }, { "parameters": { "method": "GET", "url": "https://crm.memudecore.com.br/api/contacts/search", "authentication": "predefinedCredentialType", "nodeCredentialType": "krayin-api", "sendQuery": true, "queryParameters": { "parameters": [ { "name": "phone", "value": "={{$node[\"Processar Mensagem\"].json[\"phone\"]}}" } ] }, "options": {} }, "id": "search-existing-contact", "name": "Buscar Contato Existente", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4, "position": [1120, 200], "credentials": { "krayin-api": { "id": "krayin-crm-api", "name": "Krayin CRM API" } } }, { "parameters": { "conditions": { "number": [ { "value1": "={{$node[\"Buscar Contato Existente\"].json[\"data\"]?.length || 0}}", "operation": "equal", "value2": 0 } ] } }, "id": "is-new-contact", "name": "Contato Novo?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [1340, 200] }, { "parameters": { "method": "POST", "url": "https://crm.memudecore.com.br/api/contacts", "authentication": "predefinedCredentialType", "nodeCredentialType": "krayin-api", "sendBody": true, "bodyParameters": { "parameters": [ { "name": "name", "value": "Contato WhatsApp {{$node[\"Processar Mensagem\"].json[\"phone\"]}}" }, { "name": "emails[0][value]", "value": "whatsapp+{{$node[\"Processar Mensagem\"].json[\"phone\"]}}@memudecore.com.br" }, { "name": "contact_numbers[0][value]", "value": "{{$node[\"Processar Mensagem\"].json[\"phone\"]}}" }, { "name": "contact_numbers[0][label]", "value": "WhatsApp" } ] }, "options": {} }, "id": "create-new-contact", "name": "Criar Novo Contato", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4, "position": [1560, 100], "credentials": { "krayin-api": { "id": "krayin-crm-api", "name": "Krayin CRM API" } } }, { "parameters": { "method": "POST", "url": "https://crm.memudecore.com.br/api/leads", "authentication": "predefinedCredentialType", "nodeCredentialType": "krayin-api", "sendBody": true, "bodyParameters": { "parameters": [ { "name": "title", "value": "Lead WhatsApp - {{$node[\"Processar Mensagem\"].json[\"formatted_date\"]}}" }, { "name": "description", "value": "Mensagem recebida via WhatsApp:\\n\\n{{$node[\"Processar Mensagem\"].json[\"message_text\"]}}\\n\\nTelefone: {{$node[\"Processar Mensagem\"].json[\"phone\"]}}\\nData: {{$node[\"Processar Mensagem\"].json[\"formatted_date\"]}}\\nPrioridade: {{$node[\"Processar Mensagem\"].json[\"priority\"]}}" }, { "name": "person_id", "value": "={{$node[\"Criar Novo Contato\"].json[\"data\"]?.id || $node[\"Buscar Contato Existente\"].json[\"data\"]?.[0]?.id}}" }, { "name": "lead_source_id", "value": "1" }, { "name": "lead_type_id", "value": "1" } ] }, "options": {} }, "id": "create-lead", "name": "Criar Lead", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4, "position": [1780, 200], "credentials": { "krayin-api": { "id": "krayin-crm-api", "name": "Krayin CRM API" } } }, { "parameters": { "conditions": { "boolean": [ { "value1": "={{$node[\"Processar Mensagem\"].json[\"buying_intent\"]}}", "value2": true } ] } }, "id": "check-buying-intent", "name": "Tem Intenção de Compra?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [1780, 400] }, { "parameters": { "channel": "#whatsapp-leads", "text": "💬 **NOVO LEAD VIA WHATSAPP** {{$node[\"Processar Mensagem\"].json[\"buying_intent\"] ? '🔥' : '📱'}}", "attachments": [ { "color": "{{$node[\"Processar Mensagem\"].json[\"buying_intent\"] ? '#FF6B35' : '#5B49A0'}}", "fields": [ { "title": "📱 Telefone", "value": "{{$node[\"Processar Mensagem\"].json[\"phone\"]}}", "short": true }, { "title": "⏰ Recebido", "value": "{{$node[\"Processar Mensagem\"].json[\"formatted_date\"]}}", "short": true }, { "title": "🎯 Prioridade", "value": "{{$node[\"Processar Mensagem\"].json[\"priority\"]}}", "short": true }, { "title": "💬 Mensagem", "value": "```{{$node[\"Processar Mensagem\"].json[\"message_text\"]}}```", "short": false } ], "actions": [ { "type": "button", "text": "📋 Ver Lead no CRM", "url": "https://crm.memudecore.com.br/admin/leads/view/{{$node[\"Criar Lead\"].json[\"data\"]?.id}}" } ], "footer": "Evolution API → Krayin CRM", "ts": "{{Math.floor(Date.now() / 1000)}}" } ] }, "id": "notify-slack", "name": "Notificar Slack", "type": "n8n-nodes-base.slack", "typeVersion": 1, "position": [2000, 400], "credentials": { "slackApi": { "id": "slack-memude-workspace", "name": "Slack MeMude Workspace" } } }, { "parameters": { "respondWith": "json", "responseBody": "{\n \"status\": \"success\",\n \"message\": \"Mensagem processada e lead criado\",\n \"lead_id\": \"{{$node[\"Criar Lead\"].json[\"data\"]?.id}}\",\n \"contact_id\": \"{{$node[\"Criar Novo Contato\"].json[\"data\"]?.id || $node[\"Buscar Contato Existente\"].json[\"data\"]?.[0]?.id}}\",\n \"priority\": \"{{$node[\"Processar Mensagem\"].json[\"priority\"]}}\",\n \"timestamp\": \"{{new Date().toISOString()}}\"\n}" }, "id": "webhook-response", "name": "Resposta Webhook", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [2220, 300] } ], "connections": { "Webhook Evolution": { "main": [ [ { "node": "Filtro: Nova Mensagem", "type": "main", "index": 0 } ] ] }, "Filtro: Nova Mensagem": { "main": [ [ { "node": "Processar Mensagem", "type": "main", "index": 0 } ] ] }, "Processar Mensagem": { "main": [ [ { "node": "Pular Processamento?", "type": "main", "index": 0 } ] ] }, "Pular Processamento?": { "main": [ [ { "node": "Resposta Webhook", "type": "main", "index": 0 } ], [ { "node": "Buscar Contato Existente", "type": "main", "index": 0 } ] ] }, "Buscar Contato Existente": { "main": [ [ { "node": "Contato Novo?", "type": "main", "index": 0 } ] ] }, "Contato Novo?": { "main": [ [ { "node": "Criar Novo Contato", "type": "main", "index": 0 } ], [ { "node": "Criar Lead", "type": "main", "index": 0 } ] ] }, "Criar Novo Contato": { "main": [ [ { "node": "Criar Lead", "type": "main", "index": 0 } ] ] }, "Criar Lead": { "main": [ [ { "node": "Tem Intenção de Compra?", "type": "main", "index": 0 } ] ] }, "Tem Intenção de Compra?": { "main": [ [ { "node": "Notificar Slack", "type": "main", "index": 0 } ], [ { "node": "Notificar Slack", "type": "main", "index": 0 } ] ] }, "Notificar Slack": { "main": [ [ { "node": "Resposta Webhook", "type": "main", "index": 0 } ] ] } }, "active": true, "settings": { "timezone": "America/Sao_Paulo" }, "createdAt": "2026-01-21T19:15:00.000Z", "updatedAt": "2026-01-21T19:15:00.000Z", "id": "evolution-crm-integration", "tags": [ { "id": "whatsapp", "name": "WhatsApp" }, { "id": "crm", "name": "CRM" }, { "id": "leads", "name": "Leads" } ] }