{
  "openapi": "3.0.3",
  "info": {
    "title": "TARS",
    "version": "5.1.0",
    "description": "TARS é o Bot responsável pelo atendimento automatizado do OmniChannel utilizando fluxos criados com o FlowBuilder Convert.",
    "contact": {
      "name": "Convert Company",
      "email": "developers@convertcompany.com.br",
      "url": "https://convertcompany.com.br"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://convertcompany.com.br/termos-de-uso/"
    }
  },
  "servers": [
    {
      "url": "http://{serverUrl}:{serverPort}",
      "description": "Servidor do Bot",
      "variables": {
        "serverUrl": {
          "default": "autobotsxg01.convert.app.br",
          "description": "URL do Autobot"
        },
        "serverPort": {
          "default": "9000",
          "description": "Porta do Bot"
        }
      }
    }
  ],
  "security": [],
  "tags": [],
  "paths": {
    "/hubot/stats": {
      "post": {
        "operationId": "botStats",
        "tags": [
          "Bot"
        ],
        "summary": "Consulta o status do bot",
        "responses": {
          "200": {
            "description": "Status do bot",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "botname": {
                          "type": "string"
                        },
                        "startedAt": {
                          "type": "string"
                        },
                        "cpu": {
                          "type": "object"
                        },
                        "total": {
                          "type": "object"
                        },
                        "salas": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/hubot/timeout_fluxo/{room}": {
      "post": {
        "operationId": "botTimeoutFluxoRoom",
        "tags": [
          "Fluxo"
        ],
        "summary": "Executa timeout no fluxo da sala",
        "description": "Executa o timeout no fluxo da sala informada, prosseguindo para o bloco de timeout do bloco atual.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Room"
          }
        ],
        "responses": {
          "200": {
            "description": "Timeout executado com sucesso"
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/check": {
      "get": {
        "operationId": "getBotCheck",
        "tags": [
          "Bot"
        ],
        "summary": "Verificar conexão com o bot",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Conexão validada com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Status da operação.",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "description": "Informativo",
                      "example": "Bot ativo!"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/clear-rooms": {
      "post": {
        "operationId": "clearBotRooms",
        "tags": [
          "Bot"
        ],
        "summary": "Limpar salas do banco",
        "responses": {
          "200": {
            "description": "Limpeza realizada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "removedRooms": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/flow-auto-resume": {
      "post": {
        "operationId": "botFlowAutoResume",
        "tags": [
          "Fluxo"
        ],
        "summary": "Resumir fluxo automaticamente",
        "description": "Resumir automaticamente o fluxo do atendimento de salas pendentes.",
        "responses": {
          "200": {
            "description": "Fluxo resumido",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/flow-restart/{room}": {
      "post": {
        "operationId": "botFlowRestart",
        "tags": [
          "Fluxo"
        ],
        "summary": "Reiniciar fluxo",
        "parameters": [
          {
            "$ref": "#/components/parameters/Room"
          },
          {
            "name": "getFlow",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fluxo reiniciado"
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/flow-resume/{room}": {
      "post": {
        "operationId": "botFlowResumeRoom",
        "tags": [
          "Fluxo"
        ],
        "summary": "Resumir fluxo da sala",
        "parameters": [
          {
            "$ref": "#/components/parameters/Room"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Fluxo resumido",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/flow-status/{room}": {
      "get": {
        "operationId": "botFlowStatusRoom",
        "tags": [
          "Fluxo"
        ],
        "summary": "Status do fluxo",
        "parameters": [
          {
            "$ref": "#/components/parameters/Room"
          }
        ],
        "responses": {
          "200": {
            "description": "Status retornado"
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/incoming-message": {
      "post": {
        "operationId": "botIncomingMessage",
        "tags": [
          "Mensagem"
        ],
        "summary": "Receber mensagem",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "roomId": {
                    "type": "string"
                  },
                  "message": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "msg": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Mensagem processada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/info": {
      "get": {
        "operationId": "botInfo",
        "tags": [
          "Bot"
        ],
        "summary": "Informações do bot",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Informações do bot retornadas com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Status da operação.",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "description": "Mensagem informativa",
                      "example": "Dados obtidos com sucesso."
                    },
                    "data": {
                      "type": "object",
                      "description": "Dados das informações do bot",
                      "properties": {
                        "bot": {
                          "type": "object",
                          "description": "Informações básicas do bot",
                          "properties": {
                            "username": {
                              "type": "string",
                              "description": "Nome de usuário do bot",
                              "example": "whatsbot"
                            }
                          }
                        },
                        "exec": {
                          "type": "object",
                          "description": "Informações de execução do processo",
                          "properties": {
                            "processName": {
                              "type": "string",
                              "description": "Nome do processo",
                              "example": "bot-omni02"
                            },
                            "startedAt": {
                              "type": "string",
                              "description": "Data e hora de início do processo",
                              "example": "2025-10-02 04:19:00 (UTC-3)"
                            },
                            "uptimeSec": {
                              "type": "number",
                              "description": "Tempo de atividade em segundos",
                              "example": 35374.744404882
                            },
                            "version": {
                              "type": "string",
                              "description": "Versão do bot",
                              "example": "5.1.0"
                            },
                            "mode": {
                              "type": "string",
                              "description": "Modo de execução",
                              "example": "pm2"
                            },
                            "isClusterMode": {
                              "type": "boolean",
                              "description": "Indica se está executando em modo cluster",
                              "example": true
                            },
                            "instancesNumber": {
                              "type": "integer",
                              "description": "Número de instâncias ativas",
                              "example": 3
                            }
                          }
                        },
                        "rooms": {
                          "type": "object",
                          "description": "Estatísticas das salas",
                          "properties": {
                            "totalCreated": {
                              "type": "integer",
                              "description": "Total de salas criadas",
                              "example": 0
                            },
                            "processingIds": {
                              "type": "array",
                              "description": "IDs das salas em processamento",
                              "items": {
                                "type": "string"
                              },
                              "example": []
                            },
                            "dataIds": {
                              "type": "array",
                              "description": "IDs das salas com dados",
                              "items": {
                                "type": "string"
                              },
                              "example": []
                            }
                          }
                        },
                        "messages": {
                          "type": "object",
                          "description": "Estatísticas das mensagens",
                          "properties": {
                            "totalProcessed": {
                              "type": "integer",
                              "description": "Total de mensagens processadas",
                              "example": 0
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/logs": {
      "get": {
        "operationId": "botLogs",
        "tags": [
          "Bot"
        ],
        "summary": "Obter logs do bot",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Limite de linhas de log a retornar",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000,
              "example": 100
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Termo de busca para filtrar logs",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "example": "ERROR"
            }
          },
          {
            "name": "contextLines",
            "in": "query",
            "description": "Número de linhas de contexto ao redor do resultado da busca",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 5,
              "example": 2
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Logs obtidos com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Status da operação.",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "description": "Mensagem informativa",
                      "example": "Logs obtidos com sucesso."
                    },
                    "logs": {
                      "type": "object",
                      "description": "Dados dos logs do bot",
                      "properties": {
                        "count": {
                          "type": "integer",
                          "description": "Número total de linhas de log",
                          "example": 17
                        },
                        "lines": {
                          "type": "array",
                          "description": "Array com as linhas de log",
                          "items": {
                            "type": "string",
                            "description": "Linha individual do log"
                          },
                          "example": [
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |   _________ ________  ______   ______                    ",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |  /________//_______//_____/\\ /_____/\\                ",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |  \\__.::.__\\\\::: _  \\ \\:::_ \\ \\\\::::_/_         ",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |     \\::\\ \\  \\::(_)  \\ \\:(_) ) )\\:/___/\\       ",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |      \\::\\ \\  \\:: __  \\ \\: __ `\\ \\_::._\\:\\      ",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |       \\::\\ \\  \\:.\\ \\  \\ \\ \\ `\\ \\ /____\\:\\ ",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |        \\__/   \\__/\\__/\\_/ \\_/\\_____/   ",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |  WORKING DIRECTORY: /var/lib/tars",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |  PORT: 9002",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |  BOTNAME: bot-omni02",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |  CHAT URL: https://devomni02.convert.app.br",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |  EXEC MODE: PM2 [CLUSTER MODE - worker]",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |  DEVELOPMENT MODE: ENABLED",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] |",
                            "[2025-10-02 14:10:28] [INFO] [297594] [ROUTES] [START] Rotas de API iniciadas.",
                            "[2025-10-02 14:10:28] [INFO] [297594] [START] =============== TARS BOT (v5.1.0) ==============="
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/prepare-restart": {
      "post": {
        "operationId": "botPrepareRestart",
        "tags": [
          "Bot"
        ],
        "summary": "Preparar reinicialização do bot",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "roomId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Preparação concluída",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "totalRoomsProcessing": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    },
    "/tars/remove-closed-rooms": {
      "post": {
        "operationId": "botRemoveClosedRooms",
        "tags": [
          "Bot"
        ],
        "summary": "Remove salas fechadas da memória",
        "responses": {
          "200": {
            "description": "Salas removidas com sucesso"
          },
          "400": {
            "description": "Erro"
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "Room": {
        "name": "room",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "Id da sala.",
        "example": "EiiNfJYav4AkyuEde"
      }
    }
  }
}