{
  "name": "Kommo \u2192 (30min antes) Retell Call \u2192 OpenAI Resumo \u2192 Kommo Nota/Campos/Etapa",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "kommo_in",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0001",
      "name": "Webhook (Kommo)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        220
      ]
    },
    {
      "parameters": {
        "functionCode": "/*\nKommo webhook payload pode variar.\nEste node tenta extrair o lead_id do evento (lead criado ou etapa alterada).\nAjuste os caminhos conforme o JSON real do seu Kommo.\n*/\n\nconst body = $json.body ?? $json;\n\nconst leadId =\n body?.leads?.add?.[0]?.id ??\n body?.leads?.update?.[0]?.id ??\n body?.leads?.status?.[0]?.id ??\n body?.lead?.id ??\n body?.id ??\n '';\n\nreturn [{\n json: {\n source: 'kommo',\n kommo_lead_id: String(leadId || ''),\n raw: body\n }\n}];\n"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0002",
      "name": "Extract Lead ID (Kommo)",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        460,
        220
      ]
    },
    {
      "parameters": {
        "url": "={{$env.KOMMO_BASE_URL + '/api/v4/leads/' + $json.kommo_lead_id + '?with=contacts'}}",
        "method": "GET",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $env.KOMMO_ACCESS_TOKEN}}"
            },
            {
              "name": "accept",
              "value": "application/json"
            }
          ]
        }
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0003",
      "name": "Kommo - Get Lead (with contacts)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        700,
        220
      ]
    },
    {
      "parameters": {
        "functionCode": "/*\nExtrai:\n- status_id atual do lead\n- telefone (contacts/custom_fields)\n- email\n- data/hora da reuni\u00e3o (custom field datetime)\n\nIMPORTANTE:\nIDs via env:\nKOMMO_FIELD_MEETING_DATETIME_ID\nKOMMO_FIELD_EMAIL_ID\nKOMMO_FIELD_JA_FEZ_TRAFEGO_ID\nKOMMO_FIELD_NIVEL_EMPRESA_ID\n\nGatilho:\nKOMMO_STATUS_ID_REUNIAO_AGENDADA\n*/\n\nconst lead = $json;\n\nconst STATUS_ID_REUNIAO_AGENDADA = Number($env.KOMMO_STATUS_ID_REUNIAO_AGENDADA);\n\nconst MEETING_DATETIME_FIELD_ID = Number($env.KOMMO_FIELD_MEETING_DATETIME_ID);\nconst EMAIL_FIELD_ID = Number($env.KOMMO_FIELD_EMAIL_ID);\nconst JA_FEZ_TRAFEGO_FIELD_ID = Number($env.KOMMO_FIELD_JA_FEZ_TRAFEGO_ID);\nconst NIVEL_EMPRESA_FIELD_ID = Number($env.KOMMO_FIELD_NIVEL_EMPRESA_ID);\n\nconst statusId = Number(lead?.status_id ?? 0);\n\nfunction getCustomFieldValue(customFields, fieldId) {\n const cf = (customFields || []).find((f) => Number(f.field_id) === Number(fieldId));\n const v = cf?.values?.[0]?.value;\n return v ?? '';\n}\n\nconst customFields = lead?.custom_fields_values || [];\n\nconst meetingRaw = getCustomFieldValue(customFields, MEETING_DATETIME_FIELD_ID);\nconst email = String(getCustomFieldValue(customFields, EMAIL_FIELD_ID) || '');\nconst jaFezTrafego = String(getCustomFieldValue(customFields, JA_FEZ_TRAFEGO_FIELD_ID) || '');\nconst nivelEmpresa = String(getCustomFieldValue(customFields, NIVEL_EMPRESA_FIELD_ID) || '');\n\nlet phoneRaw = '';\ntry {\n const contacts = lead?._embedded?.contacts || [];\n for (const c of contacts) {\n const cfs = c?.custom_fields_values || [];\n const phoneField = cfs.find((f) => f.field_code === 'PHONE');\n const v = phoneField?.values?.[0]?.value;\n if (v) {\n phoneRaw = String(v);\n break;\n }\n }\n} catch (e) {}\n\nif (!phoneRaw) {\n const phoneField = (customFields || []).find((f) => f.field_code === 'PHONE' || /phone|telefone/i.test(f.field_name || ''));\n const v = phoneField?.values?.[0]?.value;\n if (v) phoneRaw = String(v);\n}\n\nreturn [{\n json: {\n source: 'kommo',\n kommo_lead_id: String(lead?.id || ''),\n status_id: statusId,\n is_reuniao_agendada: statusId === STATUS_ID_REUNIAO_AGENDADA,\n meeting_datetime_raw: meetingRaw,\n email,\n ja_fez_trafego: jaFezTrafego,\n nivel_empresa: nivelEmpresa,\n phone_raw: phoneRaw,\n lead_full: lead\n }\n}];\n"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0004",
      "name": "Parse Lead (fields/phone/meeting)",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        940,
        220
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$json.is_reuniao_agendada}}",
              "value2": true
            }
          ]
        }
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0005",
      "name": "IF (Etapa = Reuni\u00e3o Agendada?)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1180,
        220
      ]
    },
    {
      "parameters": {
        "functionCode": "/*\nTimezone padr\u00e3o: America/Sao_Paulo.\nEvita UTC toISOString() que pode deslocar hor\u00e1rio.\n\nRegras:\n- Se meeting_datetime_raw vier sem timezone, assume America/Sao_Paulo.\n- Se vier com offset (-03:00), respeita.\n- call_at = meeting - 30min\n*/\n\nconst { DateTime } = require('luxon');\n\nlet phoneRaw = ($json.phone_raw || '').toString();\nlet digits = phoneRaw.replace(/\\D/g, '');\nwhile (digits.startsWith('0')) digits = digits.slice(1);\nif (!digits) throw new Error('Telefone n\u00e3o encontrado no lead.');\nif (!digits.startsWith('55') && (digits.length === 10 || digits.length === 11)) digits = '55' + digits;\nconst phone = '+' + digits;\n\nconst raw = $json.meeting_datetime_raw;\nif (!raw) throw new Error('Campo de data/hora da reuni\u00e3o vazio.');\n\nconst ZONE = 'America/Sao_Paulo';\nlet meeting;\n\nif (typeof raw === 'number') {\n // se vier timestamp (segundos)\n meeting = DateTime.fromSeconds(raw, { zone: ZONE });\n} else {\n const s = String(raw).trim();\n // Se tiver offset/timezone, respeita (setZone: true). Se n\u00e3o tiver, assume SP.\n const hasTZ = /([zZ]|[+-]\\d\\d:\\d\\d)$/.test(s);\n meeting = hasTZ\n ? DateTime.fromISO(s, { setZone: true })\n : DateTime.fromISO(s, { zone: ZONE });\n}\n\nif (!meeting.isValid) throw new Error('N\u00e3o consegui interpretar a data/hora da reuni\u00e3o. Verifique o formato do campo no Kommo. Valor: ' + raw);\n\nconst callAt = meeting.minus({ minutes: 30 });\n\nreturn [{\n json: {\n ...$json,\n phone,\n meeting_datetime_iso: meeting.toISO(),\n call_at_iso: callAt.toISO(),\n timezone: ZONE\n }\n}];\n"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0006",
      "name": "Normalize Phone + Compute call_at (SP)",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        1420,
        140
      ]
    },
    {
      "parameters": {
        "resume": "={{$json.call_at_iso}}"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0007",
      "name": "Wait Until (30min antes)",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        1660,
        140
      ]
    },
    {
      "parameters": {
        "url": "https://api.retellai.com/create-phone-call",
        "method": "POST",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $env.RETELL_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": "{\n \"agent_id\": \"agent_0ea0e30d46b489a90e0425408c\",\n \"to_number\": \"{{$json.phone}}\",\n \"metadata\": {\n \"kommo_lead_id\": \"{{$json.kommo_lead_id}}\",\n \"meeting_datetime\": \"{{$json.meeting_datetime_iso}}\",\n \"timezone\": \"{{$json.timezone}}\",\n \"email\": \"{{$json.email}}\"\n }\n}"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0008",
      "name": "Retell - Start Call (30min before)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1900,
        140
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "retell_result",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0009",
      "name": "Webhook (Retell Result)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        560
      ]
    },
    {
      "parameters": {
        "functionCode": "/*\nExtrai transcript e kommo_lead_id do webhook do Retell.\n*/\n\nconst body = $json.body ?? $json;\nconst call = body.call ?? body;\n\nconst kommoLeadId = call?.metadata?.kommo_lead_id ?? body?.metadata?.kommo_lead_id ?? '';\nconst transcript = call?.transcript ?? call?.transcript_text ?? call?.conversation?.transcript ?? '';\nconst status = call?.call_status ?? call?.status ?? '';\n\nreturn [{\n json: {\n source: 'retell',\n kommo_lead_id: String(kommoLeadId || ''),\n transcript: String(transcript || ''),\n call_status: String(status || ''),\n raw: body\n }\n}];\n"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0010",
      "name": "Extract (Retell)",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        460,
        560
      ]
    },
    {
      "parameters": {
        "url": "https://api.openai.com/v1/chat/completions",
        "method": "POST",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $env.OPENAI_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": "={\n \"model\": \"gpt-4o-mini\",\n \"temperature\": 0.2,\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"Voc\u00ea \u00e9 um analista comercial. Gere um resumo curto e objetivo da liga\u00e7\u00e3o.\\n\\nRegras: (1) Retorne SOMENTE JSON v\u00e1lido (sem texto fora). (2) Timezone padr\u00e3o: America/Sao_Paulo. (3) N\u00e3o invente dados; se n\u00e3o houver, retorne vazio.\\n\\nSa\u00edda (JSON): {\\\"summary\\\": string, \\\"classification\\\": \\\"reuniao_agendada\\\"|\\\"desqualificado\\\"|\\\"futuramente\\\", \\\"next_steps\\\": string, \\\"filled_fields\\\": {\\\"ja_fez_trafego\\\": string, \\\"nivel_empresa\\\": string, \\\"email\\\": string, \\\"meeting_datetime\\\": string}}\"\n },\n {\n \"role\": \"user\",\n \"content\": \"TRANSCRIPT:\\n\" + ($json.transcript || \"\")\n }\n ]\n}"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0011",
      "name": "OpenAI - Summarize + Classify (JSON)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        720,
        560
      ]
    },
    {
      "parameters": {
        "functionCode": "/* Parseia JSON puro do OpenAI */\n\nconst resp = $json;\nconst content = resp?.choices?.[0]?.message?.content ?? '';\n\nlet parsed;\ntry {\n parsed = JSON.parse(content);\n} catch (e) {\n throw new Error('OpenAI n\u00e3o retornou JSON puro. Conte\u00fado: ' + content);\n}\n\nreturn [{\n json: {\n ...$node['Extract (Retell)'].json,\n ai: parsed\n }\n}];\n"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0012",
      "name": "Parse AI JSON",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        980,
        560
      ]
    },
    {
      "parameters": {
        "functionCode": "/*\nMonta custom_fields_values para atualizar no Kommo com base no ai.filled_fields.\nIDs via env:\n- KOMMO_FIELD_JA_FEZ_TRAFEGO_ID\n- KOMMO_FIELD_NIVEL_EMPRESA_ID\n- KOMMO_FIELD_EMAIL_ID\n- KOMMO_FIELD_MEETING_DATETIME_ID\n\nObs: s\u00f3 envia campo se vier preenchido.\n*/\n\nconst f = $json.ai?.filled_fields || {};\n\nconst FIELD_JA_FEZ = Number($env.KOMMO_FIELD_JA_FEZ_TRAFEGO_ID);\nconst FIELD_NIVEL = Number($env.KOMMO_FIELD_NIVEL_EMPRESA_ID);\nconst FIELD_EMAIL = Number($env.KOMMO_FIELD_EMAIL_ID);\nconst FIELD_MEETING = Number($env.KOMMO_FIELD_MEETING_DATETIME_ID);\n\nconst cfs = [];\n\nfunction pushField(fieldId, value) {\n if (!fieldId || !value) return;\n cfs.push({\n field_id: fieldId,\n values: [{ value }]\n });\n}\n\npushField(FIELD_JA_FEZ, String(f.ja_fez_trafego || '').trim());\npushField(FIELD_NIVEL, String(f.nivel_empresa || '').trim());\npushField(FIELD_EMAIL, String(f.email || '').trim());\npushField(FIELD_MEETING, String(f.meeting_datetime || '').trim());\n\nreturn [{\n json: {\n ...$json,\n kommo_custom_fields_values_update: cfs\n }\n}];\n"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0018",
      "name": "Build Kommo Fields Update",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        1120,
        560
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$json.kommo_custom_fields_values_update.length}}",
              "operation": "larger",
              "value2": 0
            }
          ]
        }
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0019",
      "name": "IF (Tem campos p/ atualizar?)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1280,
        560
      ]
    },
    {
      "parameters": {
        "url": "={{$env.KOMMO_BASE_URL + '/api/v4/leads'}}",
        "method": "PATCH",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $env.KOMMO_ACCESS_TOKEN}}"
            },
            {
              "name": "accept",
              "value": "application/json"
            },
            {
              "name": "content-type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": "=[{\n \"id\": {{Number($json.kommo_lead_id)}},\n \"custom_fields_values\": {{$json.kommo_custom_fields_values_update}}\n}]"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0020",
      "name": "Kommo - Update Lead Fields",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1460,
        460
      ]
    },
    {
      "parameters": {
        "url": "={{$env.KOMMO_BASE_URL + '/api/v4/leads/notes'}}",
        "method": "POST",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $env.KOMMO_ACCESS_TOKEN}}"
            },
            {
              "name": "accept",
              "value": "application/json"
            },
            {
              "name": "content-type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": "=[{\n \"entity_id\": {{Number($json.kommo_lead_id)}},\n \"note_type\": \"common\",\n \"params\": {\n \"text\": \"Resumo da liga\u00e7\u00e3o (Retell)\\n\\n\" + ($json.ai.summary || \"\") + \"\\n\\nClassifica\u00e7\u00e3o: \" + ($json.ai.classification || \"\") + \"\\nPr\u00f3ximos passos: \" + ($json.ai.next_steps || \"\")\n }\n}]"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0013",
      "name": "Kommo - Add Note (Resumo)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1460,
        660
      ]
    },
    {
      "parameters": {
        "functionCode": "/* Decide status_id para mover etapa baseado na classifica\u00e7\u00e3o da IA.\n * env:\n * KOMMO_STATUS_ID_REUNIAO_AGENDADA\n * KOMMO_STATUS_ID_DESQUALIFICADO\n * KOMMO_STATUS_ID_FUTURAMENTE\n */\n\nconst cls = String($json.ai?.classification || '').toLowerCase();\n\nconst statusReuniao = Number($env.KOMMO_STATUS_ID_REUNIAO_AGENDADA);\nconst statusDesq = Number($env.KOMMO_STATUS_ID_DESQUALIFICADO);\nconst statusFut = Number($env.KOMMO_STATUS_ID_FUTURAMENTE);\n\nlet statusId = 0;\nif (cls === 'reuniao_agendada') statusId = statusReuniao;\nelse if (cls === 'desqualificado') statusId = statusDesq;\nelse if (cls === 'futuramente') statusId = statusFut;\n\nreturn [{\n json: {\n ...$json,\n move_status_id: statusId\n }\n}];\n"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0014",
      "name": "Decide Stage",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        1660,
        660
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$json.move_status_id}}",
              "operation": "larger",
              "value2": 0
            }
          ]
        }
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0015",
      "name": "IF (Mover etapa?)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1860,
        660
      ]
    },
    {
      "parameters": {
        "url": "={{$env.KOMMO_BASE_URL + '/api/v4/leads'}}",
        "method": "PATCH",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $env.KOMMO_ACCESS_TOKEN}}"
            },
            {
              "name": "accept",
              "value": "application/json"
            },
            {
              "name": "content-type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": "=[{\n \"id\": {{Number($json.kommo_lead_id)}},\n \"status_id\": {{Number($json.move_status_id)}}\n}]"
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0016",
      "name": "Kommo - Move Stage",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        2060,
        560
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "{\n \"ok\": true\n}",
        "options": {}
      },
      "id": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a0017",
      "name": "Respond (Retell)",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        2260,
        660
      ]
    }
  ],
  "connections": {
    "Webhook (Kommo)": {
      "main": [
        [
          {
            "node": "Extract Lead ID (Kommo)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Lead ID (Kommo)": {
      "main": [
        [
          {
            "node": "Kommo - Get Lead (with contacts)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kommo - Get Lead (with contacts)": {
      "main": [
        [
          {
            "node": "Parse Lead (fields/phone/meeting)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Lead (fields/phone/meeting)": {
      "main": [
        [
          {
            "node": "IF (Etapa = Reuni\u00e3o Agendada?)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF (Etapa = Reuni\u00e3o Agendada?)": {
      "main": [
        [
          {
            "node": "Normalize Phone + Compute call_at (SP)",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Normalize Phone + Compute call_at (SP)": {
      "main": [
        [
          {
            "node": "Wait Until (30min antes)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait Until (30min antes)": {
      "main": [
        [
          {
            "node": "Retell - Start Call (30min before)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook (Retell Result)": {
      "main": [
        [
          {
            "node": "Extract (Retell)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract (Retell)": {
      "main": [
        [
          {
            "node": "OpenAI - Summarize + Classify (JSON)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Summarize + Classify (JSON)": {
      "main": [
        [
          {
            "node": "Parse AI JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI JSON": {
      "main": [
        [
          {
            "node": "Build Kommo Fields Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Kommo Fields Update": {
      "main": [
        [
          {
            "node": "IF (Tem campos p/ atualizar?)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF (Tem campos p/ atualizar?)": {
      "main": [
        [
          {
            "node": "Kommo - Update Lead Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Kommo - Add Note (Resumo)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kommo - Update Lead Fields": {
      "main": [
        [
          {
            "node": "Kommo - Add Note (Resumo)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kommo - Add Note (Resumo)": {
      "main": [
        [
          {
            "node": "Decide Stage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decide Stage": {
      "main": [
        [
          {
            "node": "IF (Mover etapa?)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF (Mover etapa?)": {
      "main": [
        [
          {
            "node": "Kommo - Move Stage",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond (Retell)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kommo - Move Stage": {
      "main": [
        [
          {
            "node": "Respond (Retell)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionTimeout": 3600
  },
  "versionId": "b8b32c3f-5d44-4c1b-a1ff-8c7b6d3a9999",
  "meta": {
    "templateCredsSetup": "Define env vars: KOMMO_BASE_URL, KOMMO_ACCESS_TOKEN, KOMMO_STATUS_ID_REUNIAO_AGENDADA, KOMMO_STATUS_ID_DESQUALIFICADO, KOMMO_STATUS_ID_FUTURAMENTE, KOMMO_FIELD_MEETING_DATETIME_ID, KOMMO_FIELD_EMAIL_ID, KOMMO_FIELD_JA_FEZ_TRAFEGO_ID, KOMMO_FIELD_NIVEL_EMPRESA_ID, RETELL_API_KEY, OPENAI_API_KEY"
  }
}