# Conversas

## Buscar conversas

`GET /v1/conversations` · escopo `conversations:read` · ferramenta MCP `search_conversations`

Lista atendimentos com as mesmas regras da tela de atendimento (filas do usuário, carteira e configurações da empresa).

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `status` | query | `open` \| `pending` \| `closed` | não |
| `query` | query | string | não |
| `contactId` | query | integer | não |
| `cursor` | query | string | não |

```bash
curl https://api.digla.io/v1/conversations \
  -H "Authorization: Bearer dg_seu_token"
```

Resposta:

```json
{
  "items": [
    {
      "id": 1,
      "status": "texto",
      "channel": "texto",
      "contact": {
        "id": 1,
        "name": "texto",
        "number": "texto"
      },
      "queue": {
        "id": 1,
        "name": "texto"
      },
      "user": {
        "id": 1,
        "name": "texto"
      },
      "lastMessage": "texto",
      "lastMessageAt": "texto",
      "unreadMessages": 1
    }
  ],
  "nextCursor": "texto"
}
```

## Ler mensagens da conversa

`GET /v1/conversations/{id}/messages` · escopo `conversations:read` · ferramenta MCP `get_conversation_messages`

Mensagens da conversa, da mais recente para a mais antiga. Não marca como lidas.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `id` | caminho | integer | sim |
| `cursor` | query | string | não |
| `limit` | query | integer | não |

```bash
curl https://api.digla.io/v1/conversations/1/messages \
  -H "Authorization: Bearer dg_seu_token"
```

Resposta:

```json
{
  "conversation": {
    "id": 1,
    "status": "texto",
    "channel": "texto",
    "contact": {
      "id": 1,
      "name": "texto",
      "number": "texto"
    },
    "queue": {
      "id": 1,
      "name": "texto"
    },
    "user": {
      "id": 1,
      "name": "texto"
    },
    "lastMessage": "texto",
    "lastMessageAt": "texto",
    "unreadMessages": 1
  },
  "items": [
    {
      "id": "texto",
      "fromMe": true,
      "isNote": true,
      "mediaType": "texto",
      "body": "texto",
      "userId": 1,
      "createdAt": "texto"
    }
  ],
  "nextCursor": "texto"
}
```

## Transferir conversa

`POST /v1/conversations/{id}/transfer` · escopo `conversations:write` · ferramenta MCP `transfer_conversation`

Transfere a conversa para uma fila e/ou um atendente. A conversa volta para 'pending' até ser aceita.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `id` | caminho | integer | sim |
| `queueId` | corpo | integer | não |
| `userId` | corpo | integer | não |

```bash
curl -X POST https://api.digla.io/v1/conversations/1/transfer \
  -H "Authorization: Bearer dg_seu_token" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Resposta:

```json
{
  "id": 1,
  "status": "texto",
  "channel": "texto",
  "contact": {
    "id": 1,
    "name": "texto",
    "number": "texto"
  },
  "queue": {
    "id": 1,
    "name": "texto"
  },
  "user": {
    "id": 1,
    "name": "texto"
  },
  "lastMessage": "texto",
  "lastMessageAt": "texto",
  "unreadMessages": 1
}
```

## Encerrar conversa

`POST /v1/conversations/{id}/close` · escopo `conversations:write` · ferramenta MCP `close_conversation`

Encerra a conversa, opcionalmente com um desfecho. Conversa de grupo só pode ser encerrada por administrador.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `id` | caminho | integer | sim |
| `outcomeId` | corpo | integer | não |

```bash
curl -X POST https://api.digla.io/v1/conversations/1/close \
  -H "Authorization: Bearer dg_seu_token" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Resposta:

```json
{
  "id": 1,
  "status": "texto",
  "channel": "texto",
  "contact": {
    "id": 1,
    "name": "texto",
    "number": "texto"
  },
  "queue": {
    "id": 1,
    "name": "texto"
  },
  "user": {
    "id": 1,
    "name": "texto"
  },
  "lastMessage": "texto",
  "lastMessageAt": "texto",
  "unreadMessages": 1
}
```

## Enviar mensagem

`POST /v1/conversations/{id}/messages` · escopo `messages:send` · ferramenta MCP `send_message`

Envia uma mensagem de texto ao cliente numa conversa existente, em nome do usuário da credencial. Recusa contato que pediu para não receber mensagens, conversa encerrada e, no WhatsApp oficial, conversa fora da janela de 24 horas.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `id` | caminho | integer | sim |
| `body` | corpo | string | não |
| `templateId` | corpo | string | não |
| `parameters` | corpo | object | não |

```bash
curl -X POST https://api.digla.io/v1/conversations/1/messages \
  -H "Authorization: Bearer dg_seu_token" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Resposta:

```json
{
  "id": "texto",
  "fromMe": true,
  "isNote": true,
  "mediaType": "texto",
  "body": "texto",
  "userId": 1,
  "createdAt": "texto"
}
```

## Iniciar conversa

`POST /v1/conversations` · escopo `messages:send` · ferramenta MCP `start_conversation`

Abre um atendimento com um contato por uma conexão e envia a primeira mensagem: texto no WhatsApp por QR Code; modelo aprovado no WhatsApp oficial. Informe contactId ou number (number cria o contato e exige crm:write). Recusa contato com opt-out, grupo, conexão desconectada e contato que já tem conversa aberta.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `contactId` | corpo | integer | não |
| `number` | corpo | string (formato) | não |
| `name` | corpo | string | não |
| `connectionId` | corpo | integer | sim |
| `queueId` | corpo | integer | não |
| `body` | corpo | string | não |
| `templateId` | corpo | string | não |
| `parameters` | corpo | object | não |

```bash
curl -X POST https://api.digla.io/v1/conversations \
  -H "Authorization: Bearer dg_seu_token" \
  -H "Content-Type: application/json" \
  -d '{"connectionId":1}'
```

Resposta:

```json
{
  "id": 1,
  "status": "texto",
  "channel": "texto",
  "contact": {
    "id": 1,
    "name": "texto",
    "number": "texto"
  },
  "queue": {
    "id": 1,
    "name": "texto"
  },
  "user": {
    "id": 1,
    "name": "texto"
  },
  "lastMessage": "texto",
  "lastMessageAt": "texto",
  "unreadMessages": 1
}
```

## Ler conversa (o que a tela mostra)

`GET /v1/conversations/{id}` · escopo `conversations:read` · ferramenta MCP `get_conversation`

Estado completo do atendimento: status, fila, atendente, conexão, prioridade, atenção, cliente esperando, tags, robô/fluxo/agente de IA, humor, desfecho, janela do WhatsApp oficial e relógios de SLA (quando o módulo está ligado).

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `id` | caminho | integer | sim |

```bash
curl https://api.digla.io/v1/conversations/1 \
  -H "Authorization: Bearer dg_seu_token"
```

Resposta:

```json
{
  "id": 1,
  "status": "texto",
  "channel": "texto",
  "contact": {
    "id": 1,
    "name": "texto",
    "number": "texto"
  },
  "queue": {
    "id": 1,
    "name": "texto"
  },
  "user": {
    "id": 1,
    "name": "texto"
  },
  "lastMessage": "texto",
  "lastMessageAt": "texto",
  "unreadMessages": 1,
  "connection": {
    "id": 1,
    "name": "texto",
    "channel": "texto",
    "status": "texto"
  },
  "priority": "texto",
  "needsAttention": true,
  "customerWaiting": true,
  "transferPending": true,
  "tags": [
    "texto"
  ],
  "automation": {
    "bot": true,
    "chatFlowId": 1,
    "aiAgent": {
      "id": 1,
      "name": "texto"
    },
    "aiActive": true,
    "aiHandoffReason": "texto"
  },
  "mood": {
    "value": "texto",
    "reason": "texto",
    "urgent": true,
    "at": "texto"
  },
  "outcome": {
    "id": 1,
    "name": "texto"
  },
  "startedAt": "texto",
  "firstStartedAt": "texto",
  "lastCustomerMessageAt": "texto",
  "whatsappWindowOpenUntil": "texto",
  "sla": [
    {
      "target": "texto",
      "state": "texto",
      "targetMinutes": 1,
      "deadlineAt": "texto",
      "remainingMinutes": 1,
      "consumedPct": 1
    }
  ]
}
```

## Aceitar atendimento

`POST /v1/conversations/{id}/accept` · escopo `conversations:write` · ferramenta MCP `accept_conversation`

Aceita um atendimento pendente da fila: vira aberto e o usuário da credencial passa a ser o atendente.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `id` | caminho | integer | sim |

```bash
curl -X POST https://api.digla.io/v1/conversations/1/accept \
  -H "Authorization: Bearer dg_seu_token" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Resposta:

```json
{
  "id": 1,
  "status": "texto",
  "channel": "texto",
  "contact": {
    "id": 1,
    "name": "texto",
    "number": "texto"
  },
  "queue": {
    "id": 1,
    "name": "texto"
  },
  "user": {
    "id": 1,
    "name": "texto"
  },
  "lastMessage": "texto",
  "lastMessageAt": "texto",
  "unreadMessages": 1
}
```

## Assumir atendimento de outro atendente

`POST /v1/conversations/{id}/assume` · escopo `conversations:write` · ferramenta MCP `assume_conversation`

Puxa para o usuário da credencial um atendimento que está com outro atendente. Só administrador, ou gestor quando o atendente atual é do time dele.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `id` | caminho | integer | sim |

```bash
curl -X POST https://api.digla.io/v1/conversations/1/assume \
  -H "Authorization: Bearer dg_seu_token" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Resposta:

```json
{
  "id": 1,
  "status": "texto",
  "channel": "texto",
  "contact": {
    "id": 1,
    "name": "texto",
    "number": "texto"
  },
  "queue": {
    "id": 1,
    "name": "texto"
  },
  "user": {
    "id": 1,
    "name": "texto"
  },
  "lastMessage": "texto",
  "lastMessageAt": "texto",
  "unreadMessages": 1
}
```

## Marcar como lida

`POST /v1/conversations/{id}/read` · escopo `conversations:write` · ferramenta MCP `mark_conversation_read`

Marca como lidas as mensagens recebidas da conversa (todas, ou só as informadas em messageIds). Não envia recibo de leitura ao cliente.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `id` | caminho | integer | sim |
| `messageIds` | corpo | lista de string | não |

```bash
curl -X POST https://api.digla.io/v1/conversations/1/read \
  -H "Authorization: Bearer dg_seu_token" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Resposta:

```json
{
  "id": 1,
  "unreadMessages": 1
}
```

## Tags da conversa

`PATCH /v1/conversations/{id}/tags` · escopo `conversations:write` · ferramenta MCP `set_conversation_tags`

Adiciona e/ou remove tags do atendimento (diferentes das tags do contato). Use os nomes de get_directory.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `id` | caminho | integer | sim |
| `add` | corpo | lista de string | não |
| `remove` | corpo | lista de string | não |

```bash
curl -X PATCH https://api.digla.io/v1/conversations/1/tags \
  -H "Authorization: Bearer dg_seu_token" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Resposta:

```json
{
  "id": 1,
  "tags": [
    "texto"
  ]
}
```

## Criar follow-up da conversa

`POST /v1/conversations/{id}/followup` · escopo `crm:write` · ferramenta MCP `create_followup`

Cria um follow-up (tarefa do tipo FU) ligado ao atendimento e ao contato, como o botão da tela. Sem responsável, fica com o atendente da conversa (ou o usuário da credencial). Cancelar = complete_task ou delete_task.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `id` | caminho | integer | sim |
| `date` | corpo | string (formato) | sim |
| `time` | corpo | string (formato) | não |
| `name` | corpo | string | não |
| `note` | corpo | string | não |
| `responsibleUserId` | corpo | integer | não |

```bash
curl -X POST https://api.digla.io/v1/conversations/1/followup \
  -H "Authorization: Bearer dg_seu_token" \
  -H "Content-Type: application/json" \
  -d '{"date":"texto"}'
```

Resposta:

```json
{
  "id": 1,
  "name": "texto",
  "type": "texto",
  "date": "texto",
  "time": "texto",
  "durationMinutes": 1,
  "completed": true,
  "responsibleUserId": 1,
  "contactId": 1,
  "opportunityId": 1,
  "observation": "texto"
}
```

## Respostas rápidas

`GET /v1/quick-answers` · escopo `conversations:read` · ferramenta MCP `list_quick_answers`

Respostas rápidas do usuário e as gerais da empresa; busca no atalho e no texto.

| Campo | Onde | Tipo | Obrigatório |
|---|---|---|---|
| `query` | query | string | não |
| `limit` | query | integer | não |

```bash
curl https://api.digla.io/v1/quick-answers \
  -H "Authorization: Bearer dg_seu_token"
```

Resposta:

```json
{
  "items": [
    {
      "id": 1,
      "shortcut": "texto",
      "message": "texto",
      "personal": true
    }
  ]
}
```
