Workflow de n8n que recibe mensajes de WhatsApp vía WAHA, transcribe audios con Groq Whisper, usa un asistente (OpenAI) y responde por WhatsApp con formato compatible.
Creado: 2025-09-08
14 nodos
Instrucciones
Editar Workflow
Visualización del Workflow
{
"name": "WAHA - WhatsApp Agent",
"nodes": [
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "d142e8ae-030d-45eb-b814-dc664af65c45",
"name": "remoteJid",
"value": "={{ $('Configuration').item.json.from }}",
"type": "string"
},
{
"id": "ea41c29b-9e61-4cbe-8cf7-833fbff0a8ee",
"name": "message",
"value": "={{ $json.input || $json.text }} ",
"type": "string"
},
{
"id": "667922c6-125e-4e3b-bd7c-8cbb11365a99",
"name": "",
"value": "=",
"type": "string"
}
]
},
"options": {}
},
"id": "675dcc9f-3564-4c53-97ba-4d1ae79bff41",
"name": "retrieve",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
-560,
-144
]
},
{
"parameters": {
"rules": {
"values": [
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 1
},
"conditions": [
{
"leftValue": "={{ $('Webhook').item.json.body.payload._data.type }}",
"rightValue": "chat",
"operator": {
"type": "string",
"operation": "equals"
},
"id": "641ab462-5b67-4b00-98d1-f1defd776238"
}
],
"combinator": "and"
},
"renameOutput": true,
"outputKey": "Texto"
},
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 1
},
"conditions": [
{
"id": "8af4d57e-018e-4f4f-aa0e-313a21a79cea",
"leftValue": "={{ $('Webhook').item.json.body.payload._data.type }}",
"rightValue": "ptt",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
}
],
"combinator": "and"
},
"renameOutput": true,
"outputKey": "Audio"
}
]
},
"options": {
"fallbackOutput": "extra"
}
},
"id": "0f887f3f-4da9-4573-906f-13c9c34f189f",
"name": "Switch",
"type": "n8n-nodes-base.switch",
"typeVersion": 3,
"position": [
-1904,
-88
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "wahaestorio",
"options": {}
},
"id": "b26fd474-02eb-4e1c-b3e8-e096eb80ce41",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-2352,
-72
],
"webhookId": "218d2d4a-0f53-498f-b802-45dd6f999898"
},
{
"parameters": {
"name": "date_tool",
"description": "Call this tool to get the current timestamp (in ISO format). No parameters necessary, transform date to human entendible",
"jsCode": "let now = DateTime.now()\nreturn now.toISO()"
},
"id": "d711c7ae-65fc-4da1-a131-3f3f0fb67dec",
"name": "Tool: Get current date and time",
"type": "@n8n/n8n-nodes-langchain.toolCode",
"position": [
-328,
80
],
"typeVersion": 1
},
{
"parameters": {},
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-1680,
120
],
"id": "1831e99a-236b-4508-9c46-5a3b175af505",
"name": "No Operation, do nothing"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "fb5f6e40-23b7-46ac-a01b-a538d68b01e7",
"name": "audio",
"value": "={{ $('Webhook').item.json.body.payload.media.url.replace('http://localhost:3000', $('Configuration').item.json.WAHA) }}",
"type": "string"
}
]
},
"options": {}
},
"id": "a73d9576-ad64-4464-ad23-db0a3b2d3506",
"name": "ReplaceInternalURL",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
-1680,
-72
]
},
{
"parameters": {
"url": "={{ $json.audio }}",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "X-Api-Key",
"value": "={{ $('Configuration').item.json['X-Api-Key'] }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-1456,
-72
],
"id": "002cc5bd-9481-4f5f-8ec8-88d65446b15a",
"name": "Download Audio"
},
{
"parameters": {
"operation": "write",
"fileName": "/data/audio.ogg",
"options": {}
},
"type": "n8n-nodes-base.readWriteFile",
"typeVersion": 1,
"position": [
-1232,
-72
],
"id": "c26af927-18cd-49d9-983b-3d13a4a7833f",
"name": "Write Audio"
},
{
"parameters": {
"fileSelector": "/data/audio.ogg",
"options": {
"mimeType": "audio/ogg",
"dataPropertyName": "data"
}
},
"type": "n8n-nodes-base.readWriteFile",
"typeVersion": 1,
"position": [
-1008,
-72
],
"id": "93f712c3-eaa6-4d4c-bda2-254ad6bd56fd",
"name": "Change Data - Send"
},
{
"parameters": {
"method": "POST",
"url": "https://api.groq.com/openai/v1/audio/transcriptions",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "=bearer {{ $('Configuration').item.json[\"ApiKeyGroq\"] }}"
},
{
"name": "Content-type",
"value": "application/json"
}
]
},
"sendBody": true,
"contentType": "multipart-form-data",
"bodyParameters": {
"parameters": [
{
"name": "model",
"value": "whisper-large-v3"
},
{
"name": "temperature",
"value": "0.7"
},
{
"name": "response_format",
"value": "json"
},
{
"parameterType": "formBinaryData",
"name": "file",
"inputDataFieldName": "data"
}
]
},
"options": {}
},
"id": "b9bd569e-e213-4e05-8f21-dabf5275afcc",
"name": "Transcribe",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-784,
-72
]
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "66f1b455-0f91-4380-acb3-3d3c515b3513",
"name": "WAHA",
"value": "=https://waha.yourdomain.com",
"type": "string"
},
{
"id": "7e5476d8-9c66-4525-9e6c-c01182f0eaf3",
"name": "X-Api-Key",
"value": "=z3jxckA3zhKiNwheC",
"type": "string"
},
{
"id": "cd42d461-5c60-4023-8602-d545009b4d55",
"name": "Estancia",
"value": "=default",
"type": "string"
},
{
"id": "18339a2f-8a33-489e-9a78-2534d9d194fe",
"name": "ApiKeyGroq",
"value": "YOUR GROQ API KEY",
"type": "string"
},
{
"id": "cfdbb252-b830-400d-b237-3847aefbc794",
"name": "input",
"value": "={{ $('Webhook').item.json.body.payload.media.url?.replace(\n 'http://localhost:3000',\n $parameter.assignments.assignments.find(a => a.name === 'WAHA')?.value.replace(\"=\", \"\")\n ) ?? $json.body.payload._data.body }}",
"type": "string"
},
{
"id": "b61a542c-d8aa-46aa-ae3c-e5f9558f47f7",
"name": "from",
"value": "={{ $json.body.payload.from }}",
"type": "string"
}
]
},
"options": {}
},
"id": "be6fb23c-d43f-4091-b027-119f0bc30679",
"name": "Configuration",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
-2128,
-72
]
},
{
"parameters": {
"jsCode": "const items = $input.all();\n\n// --- Formateo Markdown -> WhatsApp ---\nfunction formatText(text = \"\") {\n // **negritas** -> *negritas*\n text = text.replace(/\\*\\*(.*?)\\*\\*/g, '*$1*');\n // #, ##, ### -> *negritas*\n text = text.replace(/^### (.*$)/gim, '*$1*');\n text = text.replace(/^## (.*$)/gim, '*$1*');\n text = text.replace(/^# (.*$)/gim, '*$1*');\n // [texto](url) -> texto (url)\n text = text.replace(/\\[(.*?)\\]\\((.*?)\\)/g, '$1 ($2)');\n return text;\n}\n\n// Texto de entrada\nlet receivedMessage = items?.[0]?.json?.output ?? \"\";\nreceivedMessage = formatText(receivedMessage);\n\n// chatId (prioriza remoteJid; si no, usa from / _data.from)\nconst remoteJid =\n $('Webhook').item.json?.body?.data?.key?.remoteJid ??\n $('Webhook').item.json?.body?.payload?.from ??\n $('Webhook').item.json?.body?.payload?._data?.from ??\n null;\n\n// Si por lo que sea viene s\u00f3lo el n\u00famero, lo normalizamos a [email protected]\nlet chatId = remoteJid;\nif (chatId && !chatId.includes('@c.us')) {\n const digits = chatId.replace(/[^0-9]/g, '');\n if (digits) chatId = `${digits}@c.us`;\n}\n\n// session desde Info Base (Estancia), por defecto \"default\"\nconst session = $('Configuration').item.json?.Estancia ?? 'default';\n\nreturn [{\n json: {\n chatId,\n reply_to: null,\n text: receivedMessage,\n linkPreview: true,\n linkPreviewHighQuality: false,\n session\n }\n}];\n"
},
"id": "ed643f26-00a1-46b0-9f60-76008829863a",
"name": "Format JSON",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
16,
-144
]
},
{
"parameters": {
"method": "POST",
"url": "={{ $('Configuration').item.json[\"WAHA\"] }}/api/sendText",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "X-Api-Key",
"value": "={{ $('Configuration').item.json[\"X-Api-Key\"] }}"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ $json.toJsonString() }}",
"options": {}
},
"id": "ba257f3a-3062-4f79-9ce5-eff278f3a994",
"name": "Send WhatsApp",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
240,
-144
]
},
{
"parameters": {
"resource": "assistant",
"assistantId": {
"__rl": true,
"value": "asst_BFcBQCtfM2mukKnv5WanSGPk",
"mode": "list",
"cachedResultName": "Asistente para Geriatricos"
},
"prompt": "define",
"text": "=Eres un asistente amable, claro y resolutivo. Siempre respondes con educaci\u00f3n y cercan\u00eda, sin ser demasiado formal. Usa un lenguaje natural, directo y positivo. Si no sabes algo, lo dices con sinceridad y ofreces alternativas.\n\nUsa la herramienta date_tool si necesitas manejar preguntas con fechas.\n\nResponde a la siguiente pregunta:\n\n{{ $json.message }}",
"options": {}
},
"id": "353c5f1a-a5f0-4a05-8502-40299fb874ff",
"name": "Assistant",
"type": "@n8n/n8n-nodes-langchain.openAi",
"typeVersion": 1.4,
"position": [
-336,
-144
],
"credentials": {
"openAiApi": {
"id": "KaWlbphI3J5GpoAs",
"name": "GrupVL"
}
}
}
],
"pinData": {},
"connections": {
"retrieve": {
"main": [
[
{
"node": "Assistant",
"type": "main",
"index": 0
}
]
]
},
"Switch": {
"main": [
[
{
"node": "retrieve",
"type": "main",
"index": 0
}
],
[
{
"node": "ReplaceInternalURL",
"type": "main",
"index": 0
}
],
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "Configuration",
"type": "main",
"index": 0
}
]
]
},
"Tool: Get current date and time": {
"ai_tool": [
[
{
"node": "Assistant",
"type": "ai_tool",
"index": 0
}
]
]
},
"ReplaceInternalURL": {
"main": [
[
{
"node": "Download Audio",
"type": "main",
"index": 0
}
]
]
},
"Download Audio": {
"main": [
[
{
"node": "Write Audio",
"type": "main",
"index": 0
}
]
]
},
"Write Audio": {
"main": [
[
{
"node": "Change Data - Send",
"type": "main",
"index": 0
}
]
]
},
"Change Data - Send": {
"main": [
[
{
"node": "Transcribe",
"type": "main",
"index": 0
}
]
]
},
"Transcribe": {
"main": [
[
{
"node": "retrieve",
"type": "main",
"index": 0
}
]
]
},
"Configuration": {
"main": [
[
{
"node": "Switch",
"type": "main",
"index": 0
}
]
]
},
"Format JSON": {
"main": [
[
{
"node": "Send WhatsApp",
"type": "main",
"index": 0
}
]
]
},
"Assistant": {
"main": [
[
{
"node": "Format JSON",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "5a3ff172-ff8f-4626-94b8-fb1677071c3e",
"meta": {
"instanceId": "33738330930e3881dd5571eca013f36ddf8aab20e4ea5c1f2ebaf4a2b4668ac6"
},
"id": "opN2OyFJdVKEOhI9",
"tags": []
}