{
  "name": "02 · AI Voice Agents / Multilingual IVR Intent Router",
  "active": false,
  "nodes": [
    {
      "id": "6c243f4b-c464-4c71-9611-a5c885a40ec0",
      "name": "📘 Guide",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -640,
        -120
      ],
      "parameters": {
        "content": "## 02 · AI Voice Agents · Multilingual IVR Intent Router\n\n### What this does\nDetects language, classifies intent (billing/sales/support), and returns IVR next-step + queue agent handoff payload.\n\n### Setup checklist\n1. Language detect model endpoint\n2. Define department queue numbers\n3. Optional CRM lookup by caller ID\n\n### How to test locally\nPOST `voice-ivr-route` with `{ \"text\":\"Necesito ayuda con mi factura\", \"caller\":\"+34...\" }`\n\n### Tips\n- Keep credentials in n8n Credentials (never hardcode secrets).\n- Use **Test URL** on the Webhook while developing.\n- Activate only after credentials + destinations are configured.\n",
        "width": 560,
        "height": 560,
        "color": 6
      }
    },
    {
      "id": "95549f85-5674-45c8-8b57-f88dcc808de8",
      "name": "⚙️ Config",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -640,
        480
      ],
      "parameters": {
        "content": "## Config map\n\n- **Webhook path:** `voice-ivr-route`\n- **Replace** all `https://httpbin.org/...` calls with real integrations.\n- **Credentials:** create in n8n → Credentials, then select on HTTP nodes.\n- **Activate** workflow only after a successful Test execution.\n\n### Local files\nShared host folder is mounted at `/files` inside n8n.",
        "width": 560,
        "height": 320,
        "color": 2
      }
    },
    {
      "id": "48e6d187-2e7c-4c52-b8e1-cd72c28dcbca",
      "name": "Telephony / Voice Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        220
      ],
      "webhookId": "09fd53e4-9012-423c-9ccc-729a820ab776",
      "parameters": {
        "httpMethod": "POST",
        "path": "voice-ivr-route",
        "responseMode": "responseNode",
        "options": {}
      }
    },
    {
      "id": "4a7f838f-4626-44fb-a9cd-04dcb0354b8f",
      "name": "Normalize Call Event",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        280,
        220
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "callId",
              "value": "={{ ($json.body || $json).callId || $json.body?.CallSid || \"local-call\" }}",
              "type": "string"
            },
            {
              "id": "2",
              "name": "from",
              "value": "={{ ($json.body || $json).from || ($json.body || $json).caller || \"\" }}",
              "type": "string"
            },
            {
              "id": "3",
              "name": "transcript",
              "value": "={{ ($json.body || $json).transcript || ($json.body || $json).text || \"\" }}",
              "type": "string"
            },
            {
              "id": "4",
              "name": "audioUrl",
              "value": "={{ ($json.body || $json).audioUrl || \"\" }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "dfc4bb5c-7a80-4e67-81ad-2391e6c589ab",
      "name": "STT / Intent / Dialog Plan",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        220
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const e = $input.first().json;\nconst text = (e.transcript || '').toLowerCase();\nlet intent = 'general';\nif (/price|pricing|cost|factura|billing|invoice/.test(text)) intent = 'billing';\nelse if (/book|appointment|demo|schedule/.test(text)) intent = 'booking';\nelse if (/agent|human|representative/.test(text)) intent = 'handoff';\nelse if (/help|support|issue|problem/.test(text)) intent = 'support';\nconst say = {\n  billing: 'I can help with billing. Can I confirm the email on the account?',\n  booking: 'Happy to help schedule. What day works best?',\n  handoff: 'Connecting you to a specialist now.',\n  support: 'Sorry you hit an issue. Briefly tell me what went wrong.',\n  general: 'Thanks for calling. How can I help today?',\n}[intent];\nreturn [{ json: {\n  ...e,\n  intent,\n  language: /[ñáéíóú]|necesito|factura/.test(text) ? 'es' : 'en',\n  replyText: say,\n  ttsHint: 'eleven_multilingual_v2',\n  actions: intent === 'handoff' ? ['transfer'] : ['speak', 'listen'],\n}}];"
      }
    },
    {
      "id": "10bdff5b-77ae-4e01-a5c7-3521c439fc52",
      "name": "TTS Provider (replace)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        840,
        100
      ],
      "parameters": {
        "method": "POST",
        "url": "https://httpbin.org/post",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}"
      }
    },
    {
      "id": "2baf4255-ae9b-4e9e-b1ee-e6c9d35663ed",
      "name": "CRM / KB Lookup (replace)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        840,
        340
      ],
      "parameters": {
        "method": "POST",
        "url": "https://httpbin.org/post",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}"
      }
    },
    {
      "id": "fc878afc-1c61-40c4-87bc-7bf2918ca87b",
      "name": "Compose Voice Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1120,
        220
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const parts = $input.all().map(i => i.json);\nconst base = parts[0] || {};\nreturn [{ json: {\n  ok: true,\n  workflow: 'Multilingual IVR Intent Router',\n  callId: base.callId,\n  intent: base.intent,\n  say: base.replyText,\n  actions: base.actions,\n  providerPayloads: parts,\n}}];"
      }
    },
    {
      "id": "62b350a3-2729-4a69-b292-e46a728e9b94",
      "name": "Webhook Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1400,
        220
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Telephony / Voice Webhook": {
      "main": [
        [
          {
            "node": "Normalize Call Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Call Event": {
      "main": [
        [
          {
            "node": "STT / Intent / Dialog Plan",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "STT / Intent / Dialog Plan": {
      "main": [
        [
          {
            "node": "TTS Provider (replace)",
            "type": "main",
            "index": 0
          },
          {
            "node": "CRM / KB Lookup (replace)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "TTS Provider (replace)": {
      "main": [
        [
          {
            "node": "Compose Voice Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM / KB Lookup (replace)": {
      "main": [
        [
          {
            "node": "Compose Voice Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compose Voice Response": {
      "main": [
        [
          {
            "node": "Webhook Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "tags": [],
  "meta": {
    "templateCredsSetupCompleted": true,
    "description": "Detects language, classifies intent (billing/sales/support), and returns IVR next-step + queue agent handoff payload."
  },
  "pinData": {}
}