{
  "name": "Potok Speech API -> CRM Call Analytics (amoCRM / Bitrix24 / Telegram)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "potok-call-webhook",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "1a2b3c4d-0001-4000-8000-000000000001",
      "name": "PBX / Telephony Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.potok.now/app-api/v1/audio/transcriptions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer {{ $env.POTOK_API_KEY }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"url\": \"{{ $json.recording_url }}\",\n  \"model\": \"potok-asr-v3\",\n  \"language\": \"auto\",\n  \"speakers\": true,\n  \"timestamps\": true,\n  \"summary\": true,\n  \"custom_prompt\": \"Extract: 1) Client goal and budget, 2) Key objections, 3) Next step and deadline, 4) Manager script compliance score 1-10.\"\n}",
        "options": {
          "timeout": 180000
        }
      },
      "id": "1a2b3c4d-0002-4000-8000-000000000002",
      "name": "Potok Speech API v1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [520, 300]
    },
    {
      "parameters": {
        "jsCode": "const res = $input.first().json;\nconst call = $('PBX / Telephony Webhook').first().json;\nconst durationMin = ((res.duration || 0) / 60).toFixed(1);\nconst noteText = [\n  `Call Duration: ${durationMin} min | Call ID: ${call.call_id || 'n/a'}`,\n  '',\n  'AI Summary & QA:',\n  res.summary || 'No summary generated',\n  '',\n  'Transcript (abridged):',\n  (res.text || '').slice(0, 3500)\n].join('\\n');\nreturn [{ json: { lead_id: call.lead_id || '', phone: call.phone || '', noteText, duration_s: res.duration || 0 } }];"
      },
      "id": "1a2b3c4d-0003-4000-8000-000000000003",
      "name": "Format CRM Deal Note",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [800, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.CRM_WEBHOOK_URL }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"lead_id\": \"{{ $json.lead_id }}\",\n  \"phone\": \"{{ $json.phone }}\",\n  \"note\": {{ JSON.stringify($json.noteText) }}\n}",
        "options": {}
      },
      "id": "1a2b3c4d-0004-4000-8000-000000000004",
      "name": "Push Note to CRM (amoCRM / Bitrix24)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1080, 300]
    }
  ],
  "connections": {
    "PBX / Telephony Webhook": {
      "main": [
        [{ "node": "Potok Speech API v1", "type": "main", "index": 0 }]
      ]
    },
    "Potok Speech API v1": {
      "main": [
        [{ "node": "Format CRM Deal Note", "type": "main", "index": 0 }]
      ]
    },
    "Format CRM Deal Note": {
      "main": [
        [{ "node": "Push Note to CRM (amoCRM / Bitrix24)", "type": "main", "index": 0 }]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
