# playbooks.create

Criar playbook. Cria um playbook. Só `name` é obrigatório; `scopes` começa em `["meeting"]`. Limites: 20 etapas, 30 perguntas por etapa, 12 tons, 40 gatilhos (até 12 palavras de 2+ letras cada), 30 anexos e 20 proteções. Ids de etapa, pergunta, tom, gatilho e anexo são texto livre (até 80) e únicos no playbook (`invalid_input` com PLAYBOOK_DUPLICATE_ID). Escopos disponíveis: meeting, livechat (os outros dão PLAYBOOK_SCOPE_NOT_AVAILABLE). Exige a migration de playbooks (`migration_pendente` sem ela).

- Endpoint: `POST https://app.atomiks.com.br/api/v1/playbooks.create` (corpo JSON)
- Quem pode chamar: administrador da conta
- Escopo da chave: `crm:write`
- Grava dados: sim
- Pela chave de API: sim
- Ferramenta MCP: `playbooks_create`
- Ficha em JSON: `https://app.atomiks.com.br/api/v1/openapi.json` (operationId `playbooks.create`)

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `name` | string | sim |  |
| `description` | string | não |  |
| `scopes` | "meeting" \| "whatsapp" \| "livechat" \| "flows"[] | não |  |
| `stages` | object[] | não |  |
| `tones` | object[] | não |  |
| `keywords` | object[] | não |  |
| `attachments` | object[] | não |  |
| `guardrails` | string[] | não |  |

<details><summary>JSON Schema</summary>

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "description": {
      "type": "string",
      "maxLength": 4000
    },
    "scopes": {
      "minItems": 1,
      "maxItems": 4,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "meeting",
          "whatsapp",
          "livechat",
          "flows"
        ]
      }
    },
    "stages": {
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "key": {
            "type": "string",
            "maxLength": 40,
            "pattern": "^[a-z0-9_-]*$"
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "objective": {
            "default": "",
            "type": "string",
            "maxLength": 600
          },
          "talkTrack": {
            "default": "",
            "type": "string",
            "maxLength": 6000
          },
          "watchOut": {
            "default": "",
            "type": "string",
            "maxLength": 600
          },
          "questions": {
            "default": [],
            "maxItems": 30,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "text": {
                  "type": "string",
                  "maxLength": 300
                }
              },
              "required": [
                "id",
                "text"
              ]
            }
          }
        },
        "required": [
          "id",
          "title"
        ]
      }
    },
    "tones": {
      "maxItems": 12,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "name": {
            "type": "string",
            "maxLength": 60
          },
          "when": {
            "default": "",
            "type": "string",
            "maxLength": 400
          },
          "delivery": {
            "default": "",
            "type": "string",
            "maxLength": 400
          }
        },
        "required": [
          "id",
          "name"
        ]
      }
    },
    "keywords": {
      "maxItems": 40,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "terms": {
            "minItems": 1,
            "maxItems": 12,
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 2,
              "maxLength": 60
            }
          },
          "title": {
            "default": "",
            "type": "string",
            "maxLength": 80
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500
          },
          "tone": {
            "default": "info",
            "type": "string",
            "enum": [
              "info",
              "warning",
              "urgent"
            ]
          }
        },
        "required": [
          "id",
          "terms",
          "text"
        ]
      }
    },
    "attachments": {
      "maxItems": 30,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "url": {
            "type": "string",
            "maxLength": 2000
          },
          "mimeType": {
            "default": "application/octet-stream",
            "type": "string",
            "maxLength": 200
          },
          "size": {
            "default": 0,
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "id",
          "name",
          "url"
        ]
      }
    },
    "guardrails": {
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 300
      }
    }
  },
  "required": [
    "name"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/playbooks.create \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"NEPQ","scopes":["meeting"],"stages":[{"id":"connecting","title":"Conexão","objective":"","talkTrack":"","watchOut":"","questions":[{"id":"connecting-1","text":"O que te fez aceitar essa conversa hoje?"}]}]}'
```

CLI:

```bash
node cli/atomiks.mjs playbooks.create --json '{"name":"NEPQ","scopes":["meeting"],"stages":[{"id":"connecting","title":"Conexão","objective":"","talkTrack":"","watchOut":"","questions":[{"id":"connecting-1","text":"O que te fez aceitar essa conversa hoje?"}]}]}'
```

MCP: ferramenta `playbooks_create` com a mesma entrada.

## Saída

Sucesso: `{"data": ...}` com o formato abaixo.

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "scopes": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "meeting",
          "whatsapp",
          "livechat",
          "flows"
        ]
      }
    },
    "stages": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "key": {
            "type": "string",
            "maxLength": 40,
            "pattern": "^[a-z0-9_-]*$"
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "objective": {
            "default": "",
            "type": "string",
            "maxLength": 600
          },
          "talkTrack": {
            "default": "",
            "type": "string",
            "maxLength": 6000
          },
          "watchOut": {
            "default": "",
            "type": "string",
            "maxLength": 600
          },
          "questions": {
            "default": [],
            "maxItems": 30,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "text": {
                  "type": "string",
                  "maxLength": 300
                }
              },
              "required": [
                "id",
                "text"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "id",
          "title",
          "objective",
          "talkTrack",
          "watchOut",
          "questions"
        ],
        "additionalProperties": false
      }
    },
    "tones": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "when": {
            "type": "string"
          },
          "delivery": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "name",
          "when",
          "delivery"
        ],
        "additionalProperties": false
      }
    },
    "keywords": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "terms": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "title": {
            "type": "string"
          },
          "text": {
            "type": "string"
          },
          "tone": {
            "type": "string",
            "enum": [
              "info",
              "warning",
              "urgent"
            ]
          }
        },
        "required": [
          "id",
          "terms",
          "title",
          "text",
          "tone"
        ],
        "additionalProperties": false
      }
    },
    "attachments": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "mimeType": {
            "type": "string"
          },
          "size": {
            "type": "number"
          }
        },
        "required": [
          "id",
          "name",
          "url",
          "mimeType",
          "size"
        ],
        "additionalProperties": false
      }
    },
    "guardrails": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "createdAt": {
      "type": "string"
    },
    "updatedAt": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "description",
    "scopes",
    "stages",
    "tones",
    "keywords",
    "attachments",
    "guardrails",
    "createdAt",
    "updatedAt"
  ],
  "additionalProperties": false
}
```

## Erros

`{"error": {"code", "message", "requestId"}}`. Códigos: `invalid_input` (400), `unauthorized` (401), `forbidden` / `account_pending` / `scope_missing` (403), `not_found` (404), `limit_reached` (409), `internal` (500).
