ecom-store/workflows/chatwoot-integration.json
Iris Florencio 0a0061a914 feat(workflows): fase 5 — integração WhatsApp (OpenWA) ↔ Twenty CRM
Work feito nesta sessão:
- Traefik routes.yml: crm.m5digital.net.br → twenty-crm (Twenty substitui Hermes CRM)
- Backup pre-fase3 salvo em /root/backups/2026-07-06_pre-crm-reorg/
- 3 IPs hardcoded substituídos por container names (video, chatwoot, twenty)
- API key OpenWA recuperada do .api-key (regenerada em 29/jun/2026)
- Workflows n8n JSON prontos para WhatsApp → CRM e CRM → WhatsApp
- Documentação completa em workflows/README-FASE5-OPENWA-TWENTY.md

Pendência: import manual dos workflows via n8n UI após login wizard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-06 16:49:26 -03:00

182 lines
4.8 KiB
JSON

{
"name": "Chatwoot Integration",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"url": "https://n8n.m5digital.net.br/webhook/chatwoot",
"authentication": "predefinedCredentialType",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"responseMode": "all",
"options": {}
},
"id": "1",
"name": "Chatwoot Webhook",
"type": "webhook",
"typeVersion": 1,
"position": [
240,
300
]
},
{
"parameters": {
"operation": "create",
"requestBody": true,
"options": {}
},
"id": "2",
"name": "Create Chatwoot Conversation",
"type": "httpRequest",
"typeVersion": 3.1,
"position": [
480,
300
]
},
{
"parameters": {
"operation": "create",
"requestBody": true,
"options": {}
},
"id": "3",
"name": "Create Saleor Order",
"type": "httpRequest",
"typeVersion": 3.1,
"position": [
480,
450
]
},
{
"parameters": {
"jsCode": "// Processar evento do Chatwoot\nconst event = $input.all()[0].json;\n\nif (event.event_type === 'conversation.created') {\n return {\n conversationId: event.payload.id,\n inboxId: event.payload.inbox_id,\n contact: event.payload.contact,\n messages: event.payload.messages\n };\n}\n\nif (event.event_type === 'message.created') {\n return {\n conversationId: event.payload.conversation_id,\n message: event.payload.content,\n sender: event.payload.sender_type\n };\n}\n\nreturn { skip: true };"
},
"id": "4",
"name": "Process Event",
"type": "function",
"typeVersion": 2,
"position": [
360,
300
]
},
{
"parameters": {
"jsCode": "// Criar pedido no Saleor\nconst data = $input.all()[0].json;\n\nconst saleorOrder = {\n query: \"mutation CreateOrder($input: OrderCreateInput!) { orderCreate(input: $input) { order { id number status } } }\",\n variables: {\n input: {\n channel: \"default\",\n customerNote: data.messages?.[0]?.content || \"\",\n lines: [\n {\n variantId: \"\",\n quantity: 1,\n customFields: {\n customerName: data.contact.name,\n customerEmail: data.contact.email,\n customerPhone: data.contact.phone_number\n }\n }\n ]\n }\n }\n};\n\nreturn saleorOrder;"
},
"id": "5",
"name": "Prepare Saleor Order",
"type": "function",
"typeVersion": 2,
"position": [
360,
450
]
},
{
"parameters": {
"jsCode": "// Enviar notificação WhatsApp\nconst data = $input.all()[0].json;\n\nconst message = `Novo pedido #${data.order?.number || 'N/A'} criado!\\n\\nCliente: ${data.contact?.name || 'Desconhecido'}\\nTotal: R$ 0,00\\n\\nAcesse: https://loja.m5digital.net.br/dashboard`;\n\nconst waPayload = {\n name: \"bussines-m5\",\n message: message\n};\n\nreturn waPayload;"
},
"id": "6",
"name": "WhatsApp Notification",
"type": "function",
"typeVersion": 2,
"position": [
600,
375
]
},
{
"parameters": {
"authentication": "predefinedCredentialType",
"sendHeaders": true,
"options": {}
},
"id": "7",
"name": "Send WhatsApp",
"type": "httpRequest",
"typeVersion": 3.1,
"position": [
720,
375
]
}
],
"connections": {
"Chatwoot Webhook": {
"main": [
[
{
"node": "Process Event",
"type": "main",
"index": 0
}
]
]
},
"Process Event": {
"main": [
[
{
"node": "Create Chatwoot Conversation",
"type": "main",
"index": 0
},
{
"node": "Prepare Saleor Order",
"type": "main",
"index": 0
}
]
]
},
"Prepare Saleor Order": {
"main": [
[
{
"node": "Create Saleor Order",
"type": "main",
"index": 0
}
]
]
},
"Create Saleor Order": {
"main": [
[
{
"node": "WhatsApp Notification",
"type": "main",
"index": 0
}
]
]
},
"WhatsApp Notification": {
"main": [
[
{
"node": "Send WhatsApp",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "1"
}