# automations.create

Criar automação do Instagram. Cria a automação. Gatilhos: `comment` (post ou reel), `live_comment`, `story_reply`, `dm_keyword`. `mediaIds` vazio = qualquer publicação; `keywords` vazio = qualquer texto. `publicReplies` (até 5, sorteia uma) só para `comment`. Precisa de resposta pública ou `dmText` (até 1000 caracteres). `{nome}` vira o @ de quem escreveu. `reactHeart` reage com ❤ à mensagem do contato (só `story_reply` e `dm_keyword`). `delaySeconds` (0 a 43200) espera esse tempo antes da mensagem no Direct; a resposta pública e a reação saem na hora; `live_comment` não aceita atraso.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `channelId` | string (uuid) | sim |  |
| `name` | string | sim |  |
| `trigger` | "comment" \| "live_comment" \| "story_reply" \| "dm_keyword" | sim |  |
| `mediaIds` | string[] | não | padrão [] |
| `keywords` | string[] | não | padrão [] |
| `matchMode` | "contains" \| "exact" | não | padrão "contains" |
| `publicReplies` | string[] | não | padrão [] |
| `dmText` | string \| null | não | padrão null |
| `oncePerUser` | boolean | não | padrão true |
| `reactHeart` | boolean | não | padrão false |
| `delaySeconds` | integer | não | padrão 0 |
| `enabled` | boolean | não | padrão true |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "channelId": {
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "trigger": {
      "type": "string",
      "enum": [
        "comment",
        "live_comment",
        "story_reply",
        "dm_keyword"
      ]
    },
    "mediaIds": {
      "default": [],
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 64
      }
    },
    "keywords": {
      "default": [],
      "maxItems": 30,
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 60
      }
    },
    "matchMode": {
      "default": "contains",
      "type": "string",
      "enum": [
        "contains",
        "exact"
      ]
    },
    "publicReplies": {
      "default": [],
      "maxItems": 5,
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 300
      }
    },
    "dmText": {
      "default": null,
      "anyOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "oncePerUser": {
      "default": true,
      "type": "boolean"
    },
    "reactHeart": {
      "default": false,
      "type": "boolean"
    },
    "delaySeconds": {
      "default": 0,
      "type": "integer",
      "minimum": 0,
      "maximum": 43200
    },
    "enabled": {
      "default": true,
      "type": "boolean"
    }
  },
  "required": [
    "channelId",
    "name",
    "trigger"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/automations.create \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"channelId":"00000000-0000-0000-0000-000000000000","name":"Quero o guia","trigger":"comment","mediaIds":[],"keywords":["quero"],"matchMode":"contains","publicReplies":["Te mandei no Direct!"],"dmText":"Oi {nome}, aqui está o guia.","oncePerUser":true,"reactHeart":false,"delaySeconds":0,"enabled":true}'
```

CLI:

```bash
node cli/atomiks.mjs automations.create --json '{"channelId":"00000000-0000-0000-0000-000000000000","name":"Quero o guia","trigger":"comment","mediaIds":[],"keywords":["quero"],"matchMode":"contains","publicReplies":["Te mandei no Direct!"],"dmText":"Oi {nome}, aqui está o guia.","oncePerUser":true,"reactHeart":false,"delaySeconds":0,"enabled":true}'
```

MCP: ferramenta `automations_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"
    },
    "channelId": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "enabled": {
      "type": "boolean"
    },
    "trigger": {
      "type": "string",
      "enum": [
        "comment",
        "live_comment",
        "story_reply",
        "dm_keyword"
      ]
    },
    "mediaIds": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "keywords": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "matchMode": {
      "type": "string",
      "enum": [
        "contains",
        "exact"
      ]
    },
    "publicReplies": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "dmText": {
      "type": [
        "string",
        "null"
      ]
    },
    "oncePerUser": {
      "type": "boolean"
    },
    "reactHeart": {
      "type": "boolean"
    },
    "delaySeconds": {
      "type": "number"
    },
    "createdAt": {
      "type": "string"
    },
    "updatedAt": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "channelId",
    "name",
    "enabled",
    "trigger",
    "mediaIds",
    "keywords",
    "matchMode",
    "publicReplies",
    "dmText",
    "oncePerUser",
    "reactHeart",
    "delaySeconds",
    "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).
