{
  "name": "Call Processing \u2014 \u041e\u0446\u0456\u043d\u043a\u0430 \u0434\u0437\u0432\u0456\u043d\u043a\u0456\u0432",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 2
            }
          ]
        }
      },
      "id": "schedule-trigger",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "<YOUR_GOOGLE_SHEETS_URL>",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "mode": "id",
          "value": 0
        },
        "options": {
          "returnAllMatches": false
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "Status",
              "lookupValue": ""
            }
          ]
        }
      },
      "id": "get-unprocessed-call",
      "name": "Get Unprocessed Call",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        224,
        0
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "condition-check",
              "leftValue": "={{ $json.row_number }}",
              "rightValue": "",
              "operator": {
                "type": "number",
                "operation": "exists"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "if-has-call",
      "name": "If Has Call",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        448,
        0
      ]
    },
    {
      "parameters": {
        "url": "={{ $json['Call Link'] }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "download-audio",
      "name": "Download Audio",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        672,
        0
      ]
    },
    {
      "parameters": {
        "audioUrl": "={{ $json['Call Link'] }}",
        "additionalFields": {
          "language_code": "uk",
          "speech_models": "universal-2"
        }
      },
      "id": "assemblyai-transcribe",
      "name": "AssemblyAI Transcribe",
      "type": "n8n-nodes-assemblyai.assemblyAi",
      "typeVersion": 1,
      "position": [
        880,
        0
      ],
      "credentials": {
        "assemblyAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "messages": {
          "values": [
            {
              "content": "\u0422\u0438 \u2014 \u0435\u043a\u0441\u043f\u0435\u0440\u0442 \u0437 \u0430\u043d\u0430\u043b\u0456\u0437\u0443 \u043a\u043b\u0456\u0454\u043d\u0442\u0441\u044c\u043a\u0438\u0445 \u0434\u0437\u0432\u0456\u043d\u043a\u0456\u0432 \u0434\u043b\u044f \u043a\u043e\u043d\u0434\u0438\u0442\u0435\u0440\u0441\u044c\u043a\u043e\u0457 \u043a\u043e\u043c\u043f\u0430\u043d\u0456\u0457.\n\n\u0422\u0432\u043e\u0454 \u0437\u0430\u0432\u0434\u0430\u043d\u043d\u044f \u2014 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0456\u0437\u0443\u0432\u0430\u0442\u0438 \u0442\u0440\u0430\u043d\u0441\u043a\u0440\u0438\u043f\u0446\u0456\u044e \u0434\u0437\u0432\u0456\u043d\u043a\u0430 \u0442\u0430 \u043f\u043e\u0432\u0435\u0440\u043d\u0443\u0442\u0438 JSON \u0437 \u0434\u0432\u043e\u043c\u0430 \u043f\u043e\u043b\u044f\u043c\u0438:\n\n1. \"tonality\" \u2014 \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u0456\u0441\u0442\u044c \u0434\u0437\u0432\u0456\u043d\u043a\u0430. \u041c\u043e\u0436\u043b\u0438\u0432\u0456 \u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044f \u0422\u0406\u041b\u042c\u041a\u0418:\n   - \"positive\" \u2014 \u043a\u043b\u0456\u0454\u043d\u0442 \u0437\u0430\u0434\u043e\u0432\u043e\u043b\u0435\u043d\u0438\u0439, \u0445\u0432\u0430\u043b\u0438\u0442\u044c\n   - \"negative\" \u2014 \u043a\u043b\u0456\u0454\u043d\u0442 \u043d\u0435\u0437\u0430\u0434\u043e\u0432\u043e\u043b\u0435\u043d\u0438\u0439, \u0441\u043a\u0430\u0440\u0436\u0438\u0442\u044c\u0441\u044f\n   - \"neutral\" \u2014 \u043a\u043b\u0456\u0454\u043d\u0442 \u043d\u0435\u0439\u0442\u0440\u0430\u043b\u044c\u043d\u0438\u0439, \u0456\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0456\u0439\u043d\u0438\u0439 \u0437\u0430\u043f\u0438\u0442\n\n2. \"category\" \u2014 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0456\u044f \u0437\u0432\u0435\u0440\u043d\u0435\u043d\u043d\u044f. \u0412\u0438\u0437\u043d\u0430\u0447 \u0441\u0430\u043c\u043e\u0441\u0442\u0456\u0439\u043d\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0456 \u0437\u043c\u0456\u0441\u0442\u0443. \u041f\u0440\u0438\u043a\u043b\u0430\u0434\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0456\u0439:\n   - \"\u042f\u043a\u0456\u0441\u0442\u044c \u0442\u043e\u0440\u0442\u0430\"\n   - \"\u042f\u043a\u0456\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438\"\n   - \"\u041e\u0431\u0441\u043b\u0443\u0433\u043e\u0432\u0443\u0432\u0430\u043d\u043d\u044f\"\n   - \"\u0426\u0456\u043d\u0430\"\n   - \"\u0417\u0430\u043c\u043e\u0432\u043b\u0435\u043d\u043d\u044f\"\n   - \"\u0406\u043d\u0448\u0435\"\n\n\u0412\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u0430\u0439 \u0422\u0406\u041b\u042c\u041a\u0418 \u0432\u0430\u043b\u0456\u0434\u043d\u0438\u043c JSON \u0431\u0435\u0437 \u0434\u043e\u0434\u0430\u0442\u043a\u043e\u0432\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0443.\n\n\u041f\u0440\u0438\u043a\u043b\u0430\u0434 \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u0456:\n{\"tonality\": \"negative\", \"category\": \"\u042f\u043a\u0456\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438\"}",
              "role": "system"
            },
            {
              "content": "=\u041f\u0440\u043e\u0430\u043d\u0430\u043b\u0456\u0437\u0443\u0439 \u0446\u044e \u0442\u0440\u0430\u043d\u0441\u043a\u0440\u0438\u043f\u0446\u0456\u044e \u0434\u0437\u0432\u0456\u043d\u043a\u0430:\n\n{{ $json.text }}"
            }
          ]
        },
        "options": {
          "temperature": 0.1
        }
      },
      "id": "openai-classify",
      "name": "Classify Call",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        1104,
        0
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const input = $input.first().json;\nconst callLink = $('Get Unprocessed Call').first().json['Call Link'];\nconst rowNumber = $('Get Unprocessed Call').first().json['row_number'];\n\nlet analysis;\ntry {\n  const content = input.message?.content || input.text || JSON.stringify(input);\n  analysis = typeof content === 'string' ? JSON.parse(content) : content;\n} catch(e) {\n  analysis = { tonality: 'neutral', category: '\u0406\u043d\u0448\u0435' };\n}\n\nreturn [{\n  json: {\n    callLink: callLink,\n    tonality: analysis.tonality || 'neutral',\n    category: analysis.category || '\u0406\u043d\u0448\u0435',\n    date: new Date().toISOString().split('T')[0],\n    rowNumber: rowNumber,\n    'Call Link': callLink,\n    'Status': 'Done'\n  }\n}];"
      },
      "id": "parse-result",
      "name": "Parse Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1328,
        0
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "<YOUR_GOOGLE_SHEETS_URL>"
        },
        "sheetName": {
          "__rl": true,
          "mode": "id",
          "value": 1
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Call Link": "={{ $json.callLink }}",
            "Tonality": "={{ $json.tonality }}",
            "Category": "={{ $json.category }}",
            "Date": "={{ $json.date }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Call Link",
              "displayName": "Call Link",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "type": "string"
            },
            {
              "id": "Tonality",
              "displayName": "Tonality",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "type": "string"
            },
            {
              "id": "Category",
              "displayName": "Category",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "type": "string"
            },
            {
              "id": "Date",
              "displayName": "Date",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "save-to-data-table",
      "name": "Save to Call Results",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1552,
        0
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "<YOUR_GOOGLE_SHEETS_URL>"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "\u0414\u0437\u0432\u0456\u043d\u043a\u0438"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        },
        "options": {}
      },
      "id": "update-status",
      "name": "Update Status \u2192 Done",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1760,
        0
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Unprocessed Call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Unprocessed Call": {
      "main": [
        [
          {
            "node": "If Has Call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Has Call": {
      "main": [
        [
          {
            "node": "Download Audio",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Download Audio": {
      "main": [
        [
          {
            "node": "AssemblyAI Transcribe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AssemblyAI Transcribe": {
      "main": [
        [
          {
            "node": "Classify Call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify Call": {
      "main": [
        [
          {
            "node": "Parse Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Result": {
      "main": [
        [
          {
            "node": "Save to Call Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Call Results": {
      "main": [
        [
          {
            "node": "Update Status \u2192 Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false
  }
}