325 lines
9.5 KiB
JSON
325 lines
9.5 KiB
JSON
{
|
|
"name": "plan de incentivo",
|
|
"nodes": [
|
|
{
|
|
"parameters": {
|
|
"updates": [
|
|
"messages"
|
|
],
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.whatsAppTrigger",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
-368,
|
|
-16
|
|
],
|
|
"name": "WhatsApp Trigger"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const body = $input.first().json;\n\n// Evitar procesar payloads sin mensajes reales\nif (!body?.messages?.length) {\n return [];\n}\n\nconst msg = body.messages[0];\nconst phone_id = body.metadata?.phone_number_id;\n\nreturn [\n {\n json: {\n phone: msg.from,\n text: msg.type === 'text' ? (msg.text?.body || '').trim() : '',\n phone_id,\n company_id: 'COMPANY_ID_DEMO'\n }\n }\n];"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
-176,
|
|
-16
|
|
],
|
|
"name": "Code in JavaScript"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://TU_PROYECTO.supabase.co/rest/v1/rpc/process_wa_customer",
|
|
"authentication": "genericCredentialType",
|
|
"genericAuthType": "httpCustomAuth",
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={\n \"p_phone\": \"{{ $('Code in JavaScript').item.json.phone }}\",\n \"p_company_id\": \"{{ $('Code in JavaScript').item.json.company_id }}\"\n}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
32,
|
|
-16
|
|
],
|
|
"name": "HTTP Request"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"rules": {
|
|
"values": [
|
|
{
|
|
"conditions": {
|
|
"options": {
|
|
"caseSensitive": true,
|
|
"leftValue": "",
|
|
"typeValidation": "strict",
|
|
"version": 3
|
|
},
|
|
"conditions": [
|
|
{
|
|
"leftValue": "={{ $json.state }}",
|
|
"rightValue": "NEW",
|
|
"operator": {
|
|
"type": "string",
|
|
"operation": "equals"
|
|
},
|
|
"id": "261c308d-79b6-4229-958f-99ba6b2a14f9"
|
|
}
|
|
],
|
|
"combinator": "and"
|
|
},
|
|
"renameOutput": true,
|
|
"outputKey": "NEW"
|
|
},
|
|
{
|
|
"conditions": {
|
|
"options": {
|
|
"caseSensitive": true,
|
|
"leftValue": "",
|
|
"typeValidation": "strict",
|
|
"version": 3
|
|
},
|
|
"conditions": [
|
|
{
|
|
"id": "5db18bfd-716c-4961-bb65-c3791f8ad202",
|
|
"leftValue": "={{ $json.state }}",
|
|
"rightValue": "AWAITING_NAME",
|
|
"operator": {
|
|
"type": "string",
|
|
"operation": "equals",
|
|
"name": "filter.operator.equals"
|
|
}
|
|
}
|
|
],
|
|
"combinator": "and"
|
|
},
|
|
"renameOutput": true,
|
|
"outputKey": "AWAITING_NAME"
|
|
},
|
|
{
|
|
"conditions": {
|
|
"options": {
|
|
"caseSensitive": true,
|
|
"leftValue": "",
|
|
"typeValidation": "strict",
|
|
"version": 3
|
|
},
|
|
"conditions": [
|
|
{
|
|
"id": "dee9b7b0-f7ca-4ef0-87ea-f43a15a2e52e",
|
|
"leftValue": "={{ $json.state }}",
|
|
"rightValue": "ACTIVE",
|
|
"operator": {
|
|
"type": "string",
|
|
"operation": "equals",
|
|
"name": "filter.operator.equals"
|
|
}
|
|
}
|
|
],
|
|
"combinator": "and"
|
|
},
|
|
"renameOutput": true,
|
|
"outputKey": "ACTIVE"
|
|
}
|
|
]
|
|
},
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.switch",
|
|
"typeVersion": 3.4,
|
|
"position": [
|
|
176,
|
|
-32
|
|
],
|
|
"name": "Switch"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://graph.facebook.com/v22.0/TU_PHONE_NUMBER_ID/messages",
|
|
"authentication": "genericCredentialType",
|
|
"genericAuthType": "httpHeaderAuth",
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={\n \"messaging_product\": \"whatsapp\",\n \"to\": \"={{ $('Code in JavaScript').item.json.phone }}\",\n \"type\": \"text\",\n \"text\": { \"body\": \"¡Hola! 👋 Bienvenido a nuestro Club VIP. Para personalizar tu Billetera Digital, ¿cómo te gusta que te llamen?\" }\n}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
624,
|
|
-240
|
|
],
|
|
"name": "HTTP Request2"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "PATCH",
|
|
"url": "=https://TU_PROYECTO.supabase.co/rest/v1/customers?id=eq.{{ $json.customer_id }}",
|
|
"authentication": "genericCredentialType",
|
|
"genericAuthType": "httpCustomAuth",
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={ \"bot_state\": \"AWAITING_NAME\" }",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
432,
|
|
-240
|
|
],
|
|
"name": "HTTP Request3"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "PATCH",
|
|
"url": "=https://TU_PROYECTO.supabase.co/rest/v1/customers?id=eq.{{ $json.customer_id }}",
|
|
"authentication": "genericCredentialType",
|
|
"genericAuthType": "httpCustomAuth",
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={ \n \"bot_state\": \"ACTIVE\",\n \"name\": \"{{ $('Code in JavaScript').item.json.text }}\"\n}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
448,
|
|
-16
|
|
],
|
|
"name": "HTTP Request4"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://graph.facebook.com/v22.0/TU_PHONE_NUMBER_ID/messages",
|
|
"authentication": "genericCredentialType",
|
|
"genericAuthType": "httpHeaderAuth",
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={\n \"messaging_product\": \"whatsapp\",\n \"to\": \"{{ $('Code in JavaScript').item.json.phone }}\",\n \"type\": \"text\",\n \"text\": { \"body\": \"¡Listo, {{ $('Code in JavaScript').item.json.text }}! 🎉\\n\\nTu perfil está activo. Descarga tu pase VIP y agrégalo a tu Apple/Google Wallet tocando este enlace:\\n\\n👉 https://TU_PORTAL.com/wallet/{{ $('HTTP Request').item.json.pass_id }}\" }\n}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
656,
|
|
-16
|
|
],
|
|
"name": "HTTP Request5"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://graph.facebook.com/v22.0/TU_PHONE_NUMBER_ID/messages",
|
|
"authentication": "genericCredentialType",
|
|
"genericAuthType": "httpHeaderAuth",
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={\n \"messaging_product\": \"whatsapp\",\n \"to\": \"={{ $('Code in JavaScript').item.json.phone }}\",\n \"type\": \"text\",\n \"text\": { \"body\": \"¡Hola de nuevo, {{ $('Switch').item.json.c_name }}! 💳\\n\\nEres nivel *{{ $('Switch').item.json.c_tier }}* y tu saldo actual para gastar es de *$ {{ $('Switch').item.json.c_balance }}*.\\n\\nSi perdiste tu tarjeta, recupérala aquí:\\n👉 https://TU_PORTAL.com/wallet/{{ $('Switch').item.json.pass_id }}\" }\n}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
448,
|
|
160
|
|
],
|
|
"name": "HTTP Request6"
|
|
}
|
|
],
|
|
"pinData": {},
|
|
"connections": {
|
|
"WhatsApp Trigger": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Code in JavaScript",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Code in JavaScript": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "HTTP Request",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"HTTP Request": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Switch",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Switch": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "HTTP Request3",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
],
|
|
[
|
|
{
|
|
"node": "HTTP Request4",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
],
|
|
[
|
|
{
|
|
"node": "HTTP Request6",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"HTTP Request3": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "HTTP Request2",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"HTTP Request4": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "HTTP Request5",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
}
|
|
},
|
|
"active": false,
|
|
"settings": {
|
|
"executionOrder": "v1",
|
|
"binaryMode": "separate",
|
|
"availableInMCP": false
|
|
}
|
|
} |