{
 "openapi": "3.0.3",
 "info": {
  "title": "za|bota API",
  "version": "1.20260908",
  "description": "Управление голосовыми роботами za|bota: создание и правка роботов (обычных и AI), обзвон, анализ звонков. Полная документация: https://www.za-bota.com/api/"
 },
 "servers": [
  {
   "url": "https://api.client.za-bota.com/v1"
  }
 ],
 "tags": [
  {
   "name": "Авторизация"
  },
  {
   "name": "Роботы"
  },
  {
   "name": "Роботы: разбор и правка"
  },
  {
   "name": "AI-роботы и анкета"
  },
  {
   "name": "Обзвон и звонки"
  },
  {
   "name": "Анализ и отчёты"
  }
 ],
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer",
    "description": "Authorization: Bearer <api_key>"
   },
   "api_key": {
    "type": "apiKey",
    "in": "query",
    "name": "api_key"
   }
  }
 },
 "paths": {
  "/me": {
   "get": {
    "summary": "Кто я",
    "description": "Проверка ключа: пользователь, роль, способ авторизации, счёт и число роботов. Первый вызов для любого агента.",
    "tags": [
     "Авторизация"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"user_id\":470,\"role\":\"member\",\"auth\":\"api_key\",\"integration_id\":157,\n  \"account\":{\"uuid\":\"…\",\"number\":\"63011\",\"balance\":12500.5,\"status\":\"active\"},\"bots\":4}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/sessions": {
   "post": {
    "summary": "Войти по логину и паролю",
    "description": "Возвращает сессионный `token` (не истекает). Нужен только если у вас нет API-ключа. Без авторизации.",
    "tags": [
     "Авторизация"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"token\":\"3f9c…\",\"user_id\":470}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "phone": {
          "type": "string",
          "description": "телефон (или `email`, `name`, `telegram_id`)"
         },
         "password": {
          "type": "string",
          "description": "пароль"
         }
        },
        "required": [
         "password"
        ]
       },
       "example": "{\"phone\":\"79991234567\",\"password\":\"…\"}"
      }
     }
    }
   }
  },
  "/integrations": {
   "get": {
    "summary": "Мои API-ключи",
    "description": "Список интеграций; поле `api_key` каждой — долгоживущий ключ.",
    "tags": [
     "Авторизация"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"data\":[{\"uuid\":\"…\",\"name\":\"Агент\",\"api_key\":\"a1b2…\",\"status\":\"enabled\"}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   },
   "post": {
    "summary": "Создать API-ключ",
    "description": "Создаёт интеграцию с ключом. Ключ виден в ответе и в списке.",
    "tags": [
     "Авторизация"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"uuid\":\"…\",\"name\":\"Мой агент\",\"api_key\":\"a1b2c3…\",\"status\":\"enabled\"}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "имя интеграции"
         },
         "status": {
          "type": "string",
          "description": "`enabled` (по умолчанию)"
         }
        },
        "required": [
         "name"
        ]
       },
       "example": "{\"name\":\"Мой агент\"}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots": {
   "get": {
    "summary": "Список роботов",
    "description": "Постраничный список. Мои роботы и роботы подчинённых пользователей.",
    "tags": [
     "Роботы"
    ],
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "description": "на страницу (по умолчанию 200)",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "page",
      "in": "query",
      "required": false,
      "description": "страница",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "filter",
      "in": "query",
      "required": false,
      "description": "поиск по имени",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "where",
      "in": "query",
      "required": false,
      "description": "фильтр `{\"fl_ai\":true}`",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"current_page\":1,\"last_page\":3,\"total\":41,\"data\":[{\"id\":2272,\"uuid\":\"6a16…\",\"name\":\"ИИ магазин шин\",\"fl_ai\":true,\"trunk_id\":null}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   },
   "post": {
    "summary": "Создать робота",
    "description": "Создать робота с готовым графом. Валидации графа нет — перед сохранением проверьте его через `/bots/{uuid}/validate` с `mind_map` в теле. Для AI-робота проще идти через анкету (см. «AI-роботы»).",
    "tags": [
     "Роботы"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"id\":2275,\"uuid\":\"…\",\"name\":\"Опрос\"}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "имя"
         },
         "mind_map": {
          "type": "object",
          "description": "массив узлов (см. «Модель бота»)"
         },
         "mind_map_cnt": {
          "type": "integer",
          "description": "максимальный id узла"
         },
         "fl_ai": {
          "type": "boolean",
          "description": "AI-робот"
         },
         "trunk_uuid": {
          "type": "string",
          "description": "uuid. линия по умолчанию"
         },
         "description": {
          "type": "string",
          "description": ""
         },
         "config": {
          "type": "object",
          "description": "`{\"audio_record\":true,…}`"
         }
        },
        "required": [
         "name",
         "mind_map",
         "mind_map_cnt"
        ]
       },
       "example": "{\"name\":\"Опрос\",\"mind_map\":[…],\"mind_map_cnt\":12,\"fl_ai\":false}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots/{uuid}": {
   "get": {
    "summary": "Робот целиком",
    "description": "Вся запись, включая полный `mind_map` (граф). Для чтения структуры удобнее `/bots/{uuid}/graph`.",
    "tags": [
     "Роботы"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"id\":2272,\"uuid\":\"…\",\"name\":\"…\",\"mind_map\":\"[…]\",\"config\":{…},\"fl_ai\":true}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   },
   "put": {
    "summary": "Изменить робота",
    "description": "Любые поля робота, в т.ч. целиком `mind_map`. Для точечных правок используйте `/nodes/{id}` — безопаснее.",
    "tags": [
     "Роботы"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"id\":2275,\"uuid\":\"…\",\"name\":\"Опрос v2\"}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": ""
         },
         "mind_map": {
          "type": "object",
          "description": "весь граф"
         },
         "trunk_uuid": {
          "type": "string",
          "description": "uuid. "
         },
         "config": {
          "type": "object",
          "description": ""
         }
        }
       },
       "example": "{\"name\":\"Опрос v2\",\"trunk_uuid\":\"…\"}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   },
   "delete": {
    "summary": "Удалить робота",
    "description": "Мягкое удаление (`deleted_at`).",
    "tags": [
     "Роботы"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"id\":2275}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots/{uuid}/summary": {
   "get": {
    "summary": "Карточка робота",
    "description": "Краткая сводка без графа: тип (`ai`/`classic`), число узлов по типам, параметры LLM-узла, база знаний, линия, анкета (если есть), звонки за 30 дней. `{uuid}` — uuid или числовой id.",
    "tags": [
     "Роботы: разбор и правка"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"id\":2272,\"uuid\":\"…\",\"name\":\"ИИ магазин шин\",\"kind\":\"ai\",\"nodes\":68,\n  \"actions\":{\"ai_request\":1,\"set_variables\":27,\"condition\":24,…},\n  \"ai\":{\"node_id\":2,\"provider\":\"openai\",\"model\":\"gpt-4o\",\"temperature\":\"0.7\",\"knowledge_uuid\":\"…\",\"fl_summarizing\":true},\n  \"profile\":null,\"trunk\":null,\"last_30_days\":{\"calls\":3,\"answered\":3,\"last_call\":\"2026-09-07 13:10:36\"}}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots/{uuid}/graph": {
   "get": {
    "summary": "Граф робота (компактно)",
    "description": "Узлы без пустых секций: id, action, description, переходы `childs`, и только те параметры, что относятся к типу узла. У AI-роботов дополнительно `prompt_slots` — тексты промптов, вытащенные из `set_variables`.",
    "tags": [
     "Роботы: разбор и правка"
    ],
    "parameters": [
     {
      "name": "full",
      "in": "query",
      "required": false,
      "description": "полные словари интентов, промпты, HTTP-параметры",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "node_id",
      "in": "query",
      "required": false,
      "description": "только эти узлы, через запятую (всегда полные)",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"bot\":{\"id\":2241,\"kind\":\"classic\"},\"start_node_id\":1,\"nodes_total\":16,\"mind_map_cnt\":100,\n  \"prompt_slots\":[],\n  \"nodes\":[{\"id\":1,\"action\":\"call\",\"childs\":[{\"type\":\"default\",\"id\":2,\"priority\":1}]},\n   {\"id\":73,\"action\":\"intent\",\"description\":\"нет\",\"childs\":[{\"type\":\"intent\",\"id\":70}],\n    \"intent\":{\"variable\":\"var_stage2_txt\",\"words_equal\":4,\"words_in\":98,\"words_not_in\":12,\"sample\":[\"ничего не\",\"не продаю\",…]}}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots/{uuid}/validate": {
   "get": {
    "summary": "Проверить граф",
    "description": "Список проблем: ошибки (битые переходы, пустое аудио, интент без переменной, нет стартового узла…) и предупреждения (узел без переходов, узел-сирота). `POST` с `mind_map` в теле проверяет граф ДО сохранения.",
    "tags": [
     "Роботы: разбор и правка"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"ok\":false,\"errors\":1,\"warnings\":2,\"problems\":[\n  {\"level\":\"error\",\"node_id\":73,\"code\":\"dangling_child\",\"text\":\"переход на несуществующий узел 99999\"},\n  {\"level\":\"warning\",\"node_id\":19,\"code\":\"no_childs\",\"text\":\"у узла нет переходов — звонок оборвётся здесь\"}]}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "mind_map": {
          "type": "object",
          "description": "проверить этот граф вместо сохранённого (POST)"
         }
        }
       },
       "example": ""
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots/{uuid}/nodes/{node_id}": {
   "put": {
    "summary": "Изменить узел",
    "description": "Точечная правка одного узла. По умолчанию — слияние (`mode=merge`): переданные ключи перезаписывают, остальные сохраняются; вложенные объекты сливаются, массивы заменяются целиком. После правки граф проверяется; если у узла появились ошибки — не сохраняется (`force=1` — сохранить всё равно). `dry_run=1` — показать результат без записи.",
    "tags": [
     "Роботы: разбор и правка"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     },
     {
      "name": "node_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": ""
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"saved\":true,\"node\":{\"id\":73,\"action\":\"intent\",\"intent\":{…}},\"before\":{…},\"check\":{\"ok\":true,\"errors\":0,\"warnings\":3}}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "node": {
          "type": "object",
          "description": "изменяемые поля узла (можно передать и без обёртки `node`)"
         },
         "mode": {
          "type": "string",
          "description": "merge|replace. `replace` — заменить узел целиком (id сохраняется)"
         },
         "dry_run": {
          "type": "string",
          "description": "0|1. не сохранять"
         },
         "force": {
          "type": "string",
          "description": "0|1. сохранить несмотря на ошибки"
         }
        },
        "required": [
         "node"
        ]
       },
       "example": "{\"node\":{\"description\":\"нет\",\"intent\":{\"words_in\":[\"не нужно\",\"не интересно\",\"нет спасибо\",\"не актуально\"]}}}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   },
   "delete": {
    "summary": "Удалить узел",
    "description": "Удаляет узел и все ссылки на него из `childs`/`parents_id` других узлов.",
    "tags": [
     "Роботы: разбор и правка"
    ],
    "parameters": [
     {
      "name": "dry_run",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     },
     {
      "name": "node_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": ""
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"saved\":true,\"nodes_total\":16,\"check\":{…}}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots/{uuid}/nodes": {
   "post": {
    "summary": "Добавить узел",
    "description": "Новый узел получает следующий свободный id. `parent_id` + `child_type` — сразу прицепить к родителю (добавляется переход у родителя).",
    "tags": [
     "Роботы: разбор и правка"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"saved\":true,\"node\":{\"id\":101,\"action\":\"speech_synthesis\",…},\"check\":{…}}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "node": {
          "type": "object",
          "description": "узел: `action` обязателен, остальное по типу"
         },
         "parent_id": {
          "type": "integer",
          "description": "родитель"
         },
         "child_type": {
          "type": "string",
          "description": "тип перехода у родителя (`default`, `intent`, `true`, `false`…)"
         },
         "dry_run": {
          "type": "string",
          "description": "0|1. "
         }
        },
        "required": [
         "node"
        ]
       },
       "example": "{\"parent_id\":73,\"child_type\":\"intent\",\"node\":{\"action\":\"speech_synthesis\",\"description\":\"прощание\",\"text\":\"Поняла, спасибо, всего доброго!\",\"tts_params\":{\"provider\":\"elevenlabs\"},\"childs\":[{\"type\":\"default\",\"id\":19,\"priority\":1}]}}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots/{uuid}/prompt": {
   "put": {
    "summary": "Изменить промпт AI-робота",
    "description": "Прямая замена текста промпт-слота в узле `set_variables` (для роботов, собранных не через анкету). Текущие слоты и их тексты — в `/graph` → `prompt_slots`.",
    "tags": [
     "Роботы: разбор и правка"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"saved\":true,\"node_id\":42,\"name\":\"default_instruction\",\"length\":812}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "`default_promt` (по умолчанию), `default_instruction`, `default_summarizing_request`, `default_classifier_answer`"
         },
         "text": {
          "type": "string",
          "description": "новый текст (без `'''`)"
         },
         "dry_run": {
          "type": "string",
          "description": "0|1. "
         }
        },
        "required": [
         "text"
        ]
       },
       "example": "{\"name\":\"default_instruction\",\"text\":\"#ВАЖНЫЕ ПРАВИЛА\\n1. Не называй цены без уточнения размера…\"}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bot-profiles/quick-start": {
   "post": {
    "summary": "Быстрый старт: анкета по 3 ответам",
    "description": "LLM пишет черновик анкеты по описанию бизнеса, цели звонка и предложению. Ничего не сохраняет — поправьте и передайте в `POST /bot-profiles`.",
    "tags": [
     "AI-роботы и анкета"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"message\":\"llm\",\"data\":{\"bot_name\":\"Анна\",\"who\":\"Тебя зовут Анна, ты сотрудница кофейни «Утро»…\",\"style\":\"Дружелюбно, коротко, без канцелярита\",\n \"rules\":[\"Не обещай скидок\",\"Если просят перезвонить — уточни время\"],\n \"facts\":[\"Открытие 20 сентября\",\"Промокод UTRO20 даёт 20%\"],\n \"plan\":[\"Поздороваться и представиться\",\"Узнать, удобно ли говорить\",\"Пригласить на открытие\",\"Продиктовать промокод\",\"Попрощаться\"],\n \"stages\":[2,3,4],\n \"result_fields\":[{\"name\":\"pridet\",\"type\":\"yes_no\",\"hint\":\"собирается ли прийти\"},{\"name\":\"comment\",\"type\":\"text\",\"hint\":\"важное из разговора\"}],\n \"knowledge\":{\"uuid\":\"…\"}}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "business": {
          "type": "string",
          "description": "кто вы"
         },
         "goal": {
          "type": "string",
          "description": "цель звонка"
         },
         "offer": {
          "type": "string",
          "description": "что предлагаете"
         },
         "bot_name": {
          "type": "string",
          "description": "имя робота"
         }
        },
        "required": [
         "business",
         "goal"
        ]
       },
       "example": "{\"business\":\"Сеть кофеен, открываем точку на Невском\",\"goal\":\"пригласить гостей из базы на открытие\",\"offer\":\"промокод на 20%\",\"bot_name\":\"Анна\"}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bot-profiles": {
   "post": {
    "summary": "Сохранить анкету (новая версия)",
    "description": "Анкета хранится цепочкой версий (`chain_uuid`). Первый вызов без `chain_uuid` создаёт цепочку, следующие — новую версию. Сохранение не меняет робота — нужен `render`.",
    "tags": [
     "AI-роботы и анкета"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"chain_uuid\":\"0eaa…\",\"version\":1,\"status\":\"draft\",\"bot_id\":null}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "profile": {
          "type": "object",
          "description": "анкета (см. пример)"
         },
         "chain_uuid": {
          "type": "string",
          "description": "uuid. цепочка существующей анкеты"
         },
         "note": {
          "type": "string",
          "description": "что изменили"
         },
         "template_bot_id": {
          "type": "integer",
          "description": "эталон (по умолчанию платформенный)"
         }
        },
        "required": [
         "profile"
        ]
       },
       "example": "{\"profile\":{\"bot_name\":\"Анна\",\"who\":\"Тебя зовут Анна, ты сотрудница кофейни «Утро»…\",\"style\":\"Дружелюбно, коротко, без канцелярита\",\n \"rules\":[\"Не обещай скидок\",\"Если просят перезвонить — уточни время\"],\n \"facts\":[\"Открытие 20 сентября\",\"Промокод UTRO20 даёт 20%\"],\n \"plan\":[\"Поздороваться и представиться\",\"Узнать, удобно ли говорить\",\"Пригласить на открытие\",\"Продиктовать промокод\",\"Попрощаться\"],\n \"stages\":[2,3,4],\n \"result_fields\":[{\"name\":\"pridet\",\"type\":\"yes_no\",\"hint\":\"собирается ли прийти\"},{\"name\":\"comment\",\"type\":\"text\",\"hint\":\"важное из разговора\"}],\n \"knowledge\":{\"uuid\":\"…\"}},\"note\":\"первая версия\"}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   },
   "get": {
    "summary": "Мои анкеты",
    "description": "Последняя версия каждой цепочки.",
    "tags": [
     "AI-роботы и анкета"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":[{\"chain_uuid\":\"…\",\"version\":15,\"status\":\"rendered\",\"bot_id\":2267,\"profile\":{…}}]}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bot-profiles/{chain_uuid}/render": {
   "post": {
    "summary": "Собрать робота из анкеты",
    "description": "Подставляет анкету в эталонный AI-сценарий и создаёт робота (или обновляет уже собранного по этой цепочке). `version` — откат на прошлую версию.",
    "tags": [
     "AI-роботы и анкета"
    ],
    "parameters": [
     {
      "name": "version",
      "in": "query",
      "required": false,
      "description": "какую версию собрать (по умолчанию последнюю)",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "chain_uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": ""
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"profile\":{\"chain_uuid\":\"…\",\"version\":1,\"status\":\"rendered\"},\"bot\":{\"id\":2267,\"uuid\":\"13e2…\",\"name\":\"Анна\"}}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bot-profiles/{chain_uuid}/versions": {
   "get": {
    "summary": "Версии анкеты",
    "description": "История версий с diff (`changed`) и источником (`client`, `quickstart`, `moderator`, `rollback`).",
    "tags": [
     "AI-роботы и анкета"
    ],
    "parameters": [
     {
      "name": "chain_uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": ""
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":[{\"version\":15,\"source\":\"client\",\"note\":\"…\",\"changed\":{…},\"created_at\":\"…\"}]}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bot-profiles/{chain_uuid}/funnel": {
   "get": {
    "summary": "Воронка по этапам разговора",
    "description": "Сколько дозвонов дошло до каждого этапа из `plan`/`stages` анкеты (по `stages_done` из анализа после звонка).",
    "tags": [
     "AI-роботы и анкета"
    ],
    "parameters": [
     {
      "name": "days",
      "in": "query",
      "required": false,
      "description": "период, ≤92",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "chain_uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": ""
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"answered\":120,\"analyzed\":118,\"rows\":[{\"code\":\"stage_1\",\"title\":\"Узнать, удобно ли говорить\",\"reached\":118,\"dropped_after\":30,\"drop_samples\":[…]}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots/{uuid}/profile": {
   "get": {
    "summary": "Анкета робота",
    "description": "Последняя версия анкеты по роботу (если робот собран из анкеты).",
    "tags": [
     "AI-роботы и анкета"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"chain_uuid\":\"…\",\"version\":15,\"status\":\"rendered\",\"profile\":{…}}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   },
   "put": {
    "summary": "Изменить анкету и пересобрать",
    "description": "Одним вызовом: новая версия анкеты + рендер в робота. `merge=1` — передать только изменяемые ключи, остальные возьмутся из текущей версии.",
    "tags": [
     "AI-роботы и анкета"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"stored\":{\"version\":16,\"status\":\"rendered\"},\"rendered\":{\"bot\":{\"id\":2267,\"uuid\":\"…\"}}}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "profile": {
          "type": "object",
          "description": "анкета или её часть"
         },
         "merge": {
          "type": "string",
          "description": "0|1. частичное обновление"
         },
         "note": {
          "type": "string",
          "description": "что изменили"
         },
         "render": {
          "type": "string",
          "description": "0|1. `0` — только сохранить"
         }
        },
        "required": [
         "profile"
        ]
       },
       "example": "{\"merge\":1,\"note\":\"добавили правило про скидки\",\"profile\":{\"rules\":[\"Не обещай скидок\",\"Скидку даёт только менеджер\"]}}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/knowledge": {
   "get": {
    "summary": "Базы знаний",
    "description": "Документы для RAG. Привязка к роботу — `knowledge.uuid` в анкете или `ai_request_params.knowledge_uuid` в узле.",
    "tags": [
     "AI-роботы и анкета"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"data\":[{\"uuid\":\"b27e…\",\"name\":\"Прайс и условия\",\"status\":\"active\",\"link\":\"…\"}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   },
   "post": {
    "summary": "Добавить базу знаний",
    "description": "Ссылка на документ (Google Doc/файл); индексируется фоново, статус смотрите в `GET /knowledge/{uuid}`.",
    "tags": [
     "AI-роботы и анкета"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"uuid\":\"…\",\"status\":\"update\"}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": ""
         },
         "link": {
          "type": "string",
          "description": "ссылка на документ"
         },
         "description": {
          "type": "string",
          "description": ""
         }
        },
        "required": [
         "name",
         "link"
        ]
       },
       "example": "{\"name\":\"Прайс\",\"link\":\"https://docs.google.com/document/d/…\"}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/dictionaries": {
   "get": {
    "summary": "Словари интентов",
    "description": "Переиспользуемые словари (`words_equal/words_in/words_not_in`), в т.ч. публичные платформенные (например, для автоответчика).",
    "tags": [
     "Роботы"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"data\":[{\"uuid\":\"…\",\"name\":\"Автоответчик\",\"access\":\"public\",\"words_in\":[…]}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/trunks": {
   "get": {
    "summary": "Линии (транки)",
    "description": "Свои SIP-линии. Для звонка нужна `trunk_uuid` линии или номер платформы.",
    "tags": [
     "Обзвон и звонки"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"data\":[{\"uuid\":\"…\",\"name\":\"Mango\",\"status\":\"active\"}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/contacts/categories": {
   "post": {
    "summary": "Создать список обзвона",
    "description": "Категория = список контактов для задачи. `GET /contacts/categories` — мои списки с числом контактов (`contacts_qnt`).",
    "tags": [
     "Обзвон и звонки"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"uuid\":\"…\",\"id\":901,\"name\":\"База сентябрь\"}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": ""
         },
         "comments": {
          "type": "string",
          "description": ""
         }
        },
        "required": [
         "name"
        ]
       },
       "example": "{\"name\":\"База сентябрь\"}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/contacts": {
   "post": {
    "summary": "Добавить контакт",
    "description": "Контакт в список. `variables` доступны роботу как `$first_name` и т.д.",
    "tags": [
     "Обзвон и звонки"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"uuid\":\"…\",\"phone\":\"79991234567\",\"category_id\":901}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "phone": {
          "type": "string",
          "description": "нормализуется к формату 7XXXXXXXXXX"
         },
         "category_uuid": {
          "type": "string",
          "description": "uuid. список (категория)"
         },
         "name1": {
          "type": "string",
          "description": "имя → роботу как `$first_name`"
         },
         "name2": {
          "type": "string",
          "description": "отчество"
         },
         "name3": {
          "type": "string",
          "description": "фамилия"
         },
         "fullname": {
          "type": "string",
          "description": ""
         },
         "email": {
          "type": "string",
          "description": ""
         },
         "company": {
          "type": "string",
          "description": ""
         },
         "city": {
          "type": "string",
          "description": ""
         },
         "more_data": {
          "type": "object",
          "description": "произвольные поля"
         }
        },
        "required": [
         "phone",
         "category_uuid"
        ]
       },
       "example": "{\"phone\":\"79991234567\",\"category_uuid\":\"…\",\"name1\":\"Иван\",\"company\":\"ООО Ромашка\"}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/imports/upload": {
   "post": {
    "summary": "Загрузить контакты файлом",
    "description": "CSV/XLSX; дальше `POST /imports` с картой колонок. Для небольших списков проще `POST /contacts` по одному.",
    "tags": [
     "Обзвон и звонки"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": ""
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/tasks": {
   "post": {
    "summary": "Создать задачу обзвона",
    "description": "Задача = робот + список + линия + параметры дозвона. Создаётся в статусе `created`, конвейер платформы сам разворачивает её в звонки. Остановить — `PUT` со `status=stopped`, возобновить — `active`.",
    "tags": [
     "Обзвон и звонки"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"uuid\":\"…\",\"id\":17250,\"status\":\"created\",\"qnt_calls\":0}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": ""
         },
         "bot_uuid": {
          "type": "string",
          "description": "uuid. "
         },
         "contact_category_uuid": {
          "type": "string",
          "description": "uuid. список"
         },
         "trunk_uuid": {
          "type": "string",
          "description": "uuid. линия"
         },
         "more_data": {
          "type": "object",
          "description": "`{\"call_params\":{\"attempts\":\"2\",\"time_retries\":\"3\",\"delayed\":false}}` — попыток и часов между ними"
         },
         "notify_email": {
          "type": "string",
          "description": "письмо по завершении"
         }
        },
        "required": [
         "name",
         "bot_uuid",
         "contact_category_uuid"
        ]
       },
       "example": "{\"name\":\"Открытие — база сентябрь\",\"bot_uuid\":\"…\",\"contact_category_uuid\":\"…\",\"trunk_uuid\":\"…\",\"more_data\":{\"call_params\":{\"attempts\":\"2\",\"time_retries\":\"3\"}}}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/tasks/{uuid}": {
   "get": {
    "summary": "Задача",
    "description": "Статус и счётчики: `qnt_calls`, `qnt_calls_finished`.",
    "tags": [
     "Обзвон и звонки"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"uuid\":\"…\",\"status\":\"active\",\"qnt_calls\":500,\"qnt_calls_finished\":212}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   },
   "put": {
    "summary": "Остановить / возобновить",
    "description": "",
    "tags": [
     "Обзвон и звонки"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"uuid\":\"…\",\"status\":\"stopped\"}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "status": {
          "type": "string",
          "description": "`stopped` | `active`"
         }
        },
        "required": [
         "status"
        ]
       },
       "example": "{\"status\":\"stopped\"}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/calls": {
   "post": {
    "summary": "Позвонить одному номеру",
    "description": "Тестовый звонок себе или звонок по событию (заявка с сайта). Учитывает тихие часы (→ `planned`) и чёрный список (→ `blocked`).",
    "tags": [
     "Обзвон и звонки"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"uuid\":\"8a34…\",\"status\":\"created\"}}"
       }
      }
     }
    },
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "phone": {
          "type": "string",
          "description": ""
         },
         "bot_uuid": {
          "type": "string",
          "description": "uuid. "
         },
         "trunk_uuid": {
          "type": "string",
          "description": "uuid. "
         },
         "variables": {
          "type": "object",
          "description": "переменные для робота: `first_name`, свои поля"
         },
         "attempts": {
          "type": "integer",
          "description": "попыток"
         },
         "time_retries": {
          "type": "string",
          "description": "`30m`, `1h`, `1d`"
         },
         "delayed_at": {
          "type": "string",
          "description": "datetime. позвонить не раньше"
         }
        },
        "required": [
         "phone",
         "bot_uuid"
        ]
       },
       "example": "{\"phone\":\"79991234567\",\"bot_uuid\":\"…\",\"variables\":{\"first_name\":\"Иван\"}}"
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   },
   "get": {
    "summary": "Все звонки (штатный список)",
    "description": "Постраничный список по всем роботам с фильтрами. Для отчёта по одному роботу быстрее `/bots/{uuid}/calls`.",
    "tags": [
     "Анализ и отчёты"
    ],
    "parameters": [
     {
      "name": "date_start",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "date_end",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "status",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "where",
      "in": "query",
      "required": false,
      "description": "`{\"bot_id\":2241}`",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "page",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "full_variables",
      "in": "query",
      "required": false,
      "description": "все переменные звонка",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"total\":2623,\"data\":[{\"uuid\":\"…\",\"status\":\"answer\",\"bill_sec\":30,\"cost\":6.6,\"bot_name\":\"…\",\"task_name\":\"…\",\"variables\":{…}}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/contacts/blacklist": {
   "get": {
    "summary": "Чёрный список",
    "description": "Номера, которым не звоним. `POST` с `phone` — добавить, `DELETE /{uuid}` — убрать.",
    "tags": [
     "Обзвон и звонки"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"data\":[{\"uuid\":\"…\",\"phone\":\"7999…\"}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots/{uuid}/analytics": {
   "get": {
    "summary": "Аналитика робота",
    "description": "Всё для отчёта по одному роботу за период: итоги, статусы, длительности, по дням, распределение полей результата (что робот узнал), узлы, на которых заканчиваются разговоры (`exit_nodes` — где обрыв у обычных ботов), этапы разговора (`stages` — для роботов из анкеты).",
    "tags": [
     "Анализ и отчёты"
    ],
    "parameters": [
     {
      "name": "days",
      "in": "query",
      "required": false,
      "description": "период назад (по умолчанию 30, ≤92)",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "from",
      "in": "query",
      "required": false,
      "description": "`YYYY-MM-DD`",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "task_id",
      "in": "query",
      "required": false,
      "description": "только одна задача",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "sample",
      "in": "query",
      "required": false,
      "description": "сколько дозвонов разбирать для распределений (≤5000)",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"bot\":{\"id\":2241,\"kind\":\"classic\"},\"from\":\"2026-08-10\",\"to\":\"2026-09-08\",\n  \"totals\":{\"calls\":2623,\"answered\":1791,\"answer_rate\":68.3,\"answered_30s\":171,\"unique_phones\":2074,\"minutes\":450.5,\"avg_sec\":13.4,\"cost\":7876.3},\n  \"by_status\":{\"answer\":1791,\"noanswer\":307,\"voicemail\":248,\"busy\":213,\"error\":59},\n  \"duration_buckets\":{\"lt10\":657,\"10_30\":963,\"30_60\":171,\"60_180\":0,\"gt180\":0},\n  \"daily\":[{\"day\":\"2026-09-07\",\"calls\":756,\"answered\":617,\"minutes\":110.1,\"cost\":2255.2}],\n  \"result_fields\":[{\"field\":\"var_is_actual\",\"filled\":1791,\"empty\":0,\"distinct\":2,\"values\":{\"false\":1620,\"true\":171}}],\n  \"exit_nodes\":[{\"node_id\":19,\"count\":900,\"action\":\"end_call\",\"description\":\"тишина\"}],\n  \"stages\":[]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/bots/{uuid}/calls": {
   "get": {
    "summary": "Звонки робота",
    "description": "Список звонков с результатом (поля, которые робот узнал) и ссылкой на запись. `with=transcript` добавляет расшифровку разговора.",
    "tags": [
     "Анализ и отчёты"
    ],
    "parameters": [
     {
      "name": "days",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "from",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "status",
      "in": "query",
      "required": false,
      "description": "через запятую: `answer,noanswer`",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "task_id",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "phone",
      "in": "query",
      "required": false,
      "description": "поиск по номеру",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "min_sec",
      "in": "query",
      "required": false,
      "description": "не короче N секунд",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "with",
      "in": "query",
      "required": false,
      "description": "`transcript`, `track`",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "description": "≤500",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "offset",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"total\":182,\"items\":[{\"uuid\":\"8a34…\",\"created_at\":\"2026-09-07 13:10:36\",\"phone\":\"7901…\",\"status\":\"answer\",\"bill_sec\":262,\"cost\":21.86,\n  \"result\":{\"summary\":\"Клиент согласился на зимние шины APLUS 275/45 R20\",\"var_is_actual\":\"1\",\"client_name\":\"\"},\n  \"record_url\":\"https://client.za-bota.com/calls/storage/3497/8a34…/….mp3\",\n  \"transcript\":{\"source\":\"dialog\",\"turns\":[{\"who\":\"bot\",\"text\":\"Добрый день! Меня зовут Дмитрий…\"},{\"who\":\"human\",\"text\":\"Здравствуйте, мне нужны шины на Ауди…\"}]}}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/calls/{uuid}/transcript": {
   "get": {
    "summary": "Разбор одного звонка",
    "description": "Расшифровка, результат, маршрут по узлам (`path`), расход LLM/TTS/STT (`usage`), запись.",
    "tags": [
     "Анализ и отчёты"
    ],
    "parameters": [
     {
      "name": "uuid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "uuid или числовой id"
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"uuid\":\"…\",\"status\":\"answer\",\"bill_sec\":262,\"cost\":21.86,\"bot\":{\"id\":2272,\"kind\":\"ai\"},\n  \"transcript\":{\"source\":\"dialog\",\"turns\":[…]},\"result\":{…},\"stages_done\":[\"stage_1\",\"stage_2\"],\n  \"path\":[{\"node_id\":1,\"action\":\"call\"},{\"node_id\":2,\"action\":\"ai_request\",\"description\":\"ai_answer\"}],\n  \"usage\":{\"llm\":{\"requests\":13,\"prompt_tokens\":41200,\"completion_tokens\":900,\"cached_tokens\":30000,\"from_cache\":2},\"tts\":{\"requests\":12,\"chars\":1400,\"from_cache\":5},\"stt\":{\"requests\":12,\"seconds\":95}},\n  \"record_url\":\"…\"}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/calls/report": {
   "get": {
    "summary": "Выгрузка звонков CSV",
    "description": "Те же фильтры, что у `/calls`; ответ — CSV (windows-1251) со всеми переменными.",
    "tags": [
     "Анализ и отчёты"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": ""
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/statistics/dashboard": {
   "get": {
    "summary": "Дашборд аккаунта",
    "description": "Счётчики контактов/звонков/баланса и график за 12 месяцев.",
    "tags": [
     "Анализ и отчёты"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": ""
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/accounts": {
   "get": {
    "summary": "Счёт и баланс",
    "description": "Лицевой счёт: `balance`, `status`. Отрицательный баланс блокирует задачи.",
    "tags": [
     "Анализ и отчёты"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": "{\"status\":\"success\",\"data\":{\"data\":[{\"uuid\":\"…\",\"number\":\"63011\",\"balance\":12500.5,\"status\":\"active\"}]}}"
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  },
  "/finance": {
   "get": {
    "summary": "Операции по счёту",
    "description": "Пополнения и списания.",
    "tags": [
     "Анализ и отчёты"
    ],
    "parameters": [
     {
      "name": "date_start",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "date_end",
      "in": "query",
      "required": false,
      "description": "",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "JSON `{status, message, data}`",
      "content": {
       "application/json": {
        "example": ""
       }
      }
     }
    },
    "security": [
     {
      "bearer": []
     },
     {
      "api_key": []
     }
    ]
   }
  }
 }
}