> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leavo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Gerenciar Follow-up

> CRUD de configurações de follow-up

## Criar Configuração

```bash theme={null}
POST /backend/followup/configs
```

**Body:**

```json theme={null}
{
  "assistant_id": "uuid",
  "trigger_status_ids": ["uuid-status-1"],
  "steps": [
    {
      "interval": "PT30M",
      "prompt": "Mensagem amigável de follow-up"
    },
    {
      "interval": "PT2H",
      "prompt": "Ofereça uma demonstração do produto"
    }
  ],
  "official_steps": [
    {
      "channel_id": "uuid",
      "channel_name": "WhatsApp Business",
      "app_id": "gupshup_app_12345",
      "steps": [
        {
          "interval": "P1D",
          "template_name": "reengajamento_v1",
          "template_language": "pt_BR",
          "template_params": ["{{LEAD_FIRSTNAME}}"]
        }
      ]
    }
  ]
}
```

| Campo                         | Tipo      | Obrigatório | Descrição                                                 |
| ----------------------------- | --------- | ----------- | --------------------------------------------------------- |
| `assistant_id`                | UUID      | Sim         | Assistente vinculado                                      |
| `trigger_status_ids`          | UUID\[]   | Sim         | Status que ativam o follow-up                             |
| `steps`                       | array     | Condicional | Steps com IA (obrigatório se não houver `official_steps`) |
| `steps[].interval`            | string    | Sim         | Intervalo ISO 8601 (mín. 30 min)                          |
| `steps[].prompt`              | string    | Condicional | Prompt para geração da mensagem por IA                    |
| `steps[].template_name`       | string    | Condicional | Obrigatório se intervalo >= 24h                           |
| `steps[].template_language`   | string    | Não         | Idioma do template (padrão: `pt_BR`)                      |
| `steps[].template_params`     | string\[] | Não         | Parâmetros do template                                    |
| `official_steps`              | array     | Não         | Steps por canal oficial (Meta/Gupshup)                    |
| `official_steps[].channel_id` | string    | Sim         | ID do canal                                               |
| `official_steps[].app_id`     | string    | Sim         | ID do app Gupshup                                         |
| `official_steps[].steps`      | array     | Sim         | Steps do canal (mín. 1)                                   |

**Resposta (201):** Objeto FollowupConfig completo.

### Validações

* Pelo menos um step (em `steps` ou `official_steps`)
* Máximo 3 steps por configuração
* Intervalo mínimo: 30 minutos
* Se intervalo >= 24h: `template_name` obrigatório
* Sem `channel_id` duplicados em `official_steps`
* Um config por assistente

## Obter Configuração

```bash theme={null}
GET /backend/followup/configs/{id}
```

## Obter por Assistente

```bash theme={null}
GET /backend/followup/configs/assistant/{assistantId}
```

Retorna a configuração de follow-up vinculada ao assistente.

## Listar por Tenant

```bash theme={null}
GET /backend/followup/configs/tenant/{tenantId}
```

## Atualizar Configuração

```bash theme={null}
PUT /backend/followup/configs/{id}
```

**Body (todos os campos opcionais):**

```json theme={null}
{
  "trigger_status_ids": ["uuid-status-1", "uuid-status-2"],
  "steps": [...],
  "official_steps": [...],
  "is_active": false
}
```

## Excluir Configuração

```bash theme={null}
DELETE /backend/followup/configs/{id}
```

**Resposta:** 204 No Content

<Note>
  Jobs de follow-up já agendados continuarão em execução até serem processados. A exclusão não cancela jobs em andamento.
</Note>
