{ "name": "M5 — OpenWA → Twenty CRM", "description": "Recebe evento WhatsApp do OpenWA e cria/atualiza Company + Person + Note no Twenty CRM", "active": true, "nodes": [ { "id": "webhook-in", "name": "Webhook OpenWA", "type": "n8n-nodes-base.webhook", "typeVersion": 1, "position": [240, 300], "webhookId": "m5-openwa-in", "parameters": { "httpMethod": "POST", "path": "openwa-incoming", "responseMode": "responseNode", "options": { "authentication": "none" } } }, { "id": "if-message", "name": "Filtra message.received", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [460, 300], "parameters": { "conditions": { "string": [ { "value1": "={{$jsonBody.event}}", "operation": "equals", "value2": "message.received" } ] } } }, { "id": "extract-contact", "name": "Extrai Contato", "type": "n8n-nodes-base.set", "typeVersion": 1, "position": [680, 300], "parameters": { "values": { "number": [ { "name": "phone", "value": "={{$jsonBody.payload.from.replace(/@.*$/, '')}}" }, { "name": "name", "value": "={{$jsonBody.payload.notifyName || $jsonBody.payload.pushName || $jsonBody.payload.from}}" }, { "name": "message", "value": "={{$jsonBody.payload.body}}" }, { "name": "sessionId", "value": "={{$jsonBody.sessionId}}" }, { "name": "timestamp", "value": "={{$jsonBody.payload.timestamp}}" } ] } } }, { "id": "http-twenty-search", "name": "Twenty: buscar Contact por phone", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [900, 300], "parameters": { "method": "POST", "url": "https://crm.m5digital.net.br/graphql", "sendBody": true, "contentType": "json", "body": { "query": "query SearchPersonByPhone($phone: String!) { people(filter: { phone: { eq: $phone } }) { edges { node { id firstName lastName displayName } } } }", "variables": "={{ { phone: $json.phone } }}" }, "options": { "timeout": 10000 } } }, { "id": "if-exists", "name": "Já existe no CRM?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [1120, 300], "parameters": { "conditions": { "number": [ { "value1": "={{$json.data.people.edges.length}}", "operation": "largerEqual", "value2": 1 } ] } } }, { "id": "http-twenty-update", "name": "Twenty: criar Note", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [1340, 160], "parameters": { "method": "POST", "url": "https://crm.m5digital.net.br/graphql", "sendBody": true, "contentType": "json", "body": { "query": "mutation CreateNote($personId: String!, $body: String!) { createNote(data: { personId: $personId, body: $body, type: TEXT }) { id body createdAt } }", "variables": "={{ { personId: $json.data.people.edges[0].node.id, body: $json.message } }}" } } }, { "id": "http-twenty-create", "name": "Twenty: criar Person", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [1340, 440], "parameters": { "method": "POST", "url": "https://crm.m5digital.net.br/graphql", "sendBody": true, "contentType": "json", "body": { "query": "mutation CreatePerson($firstName: String!, $phone: String!) { createPerson(data: { firstName: $firstName, phone: $phone }) { id displayName } }", "variables": "={{ { firstName: $json.name, phone: '+' + $json.phone } }}" } } }, { "id": "respond", "name": "Respond OpenWA", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [1560, 300], "parameters": { "respondWith": "json", "responseBody": "={{ { status: 'ok', person: 'processed' } }}" } } ], "connections": { "webhook-in": { "main": [[{"node": "if-message", "type": "main", "index": 0}]] }, "if-message": { "main": [ [{"node": "extract-contact", "type": "main", "index": 0}], [{"node": "respond", "type": "main", "index": 0}] ] }, "extract-contact": { "main": [[{"node": "http-twenty-search", "type": "main", "index": 0}]] }, "http-twenty-search": { "main": [[{"node": "if-exists", "type": "main", "index": 0}]] }, "if-exists": { "main": [ [{"node": "http-twenty-update", "type": "main", "index": 0}], [{"node": "http-twenty-create", "type": "main", "index": 0}] ] }, "http-twenty-update": { "main": [[{"node": "respond", "type": "main", "index": 0}]] }, "http-twenty-create": { "main": [[{"node": "respond", "type": "main", "index": 0}]] } }, "settings": { "saveExecutionProgress": true, "saveManualExecutions": true, "callerPolicy": "workflowsFromSameOwner" }, "versionId": "m5-openwa-twenty-v1", "triggerCount": 0, "tags": [ {"name": "m5"}, {"name": "openwa"}, {"name": "twenty-crm"}, {"name": "whatsapp"} ], "meta": {"description": "Integração WhatsApp → CRM - Iris Florencio"} }