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

# Declarar o que aconteceu

> Depois de agir: um caso aberto ou fechado, um contato feito, como um efeito terminou, um compromisso, uma transferência, uma supressão adicionada ou levantada. Com `Idempotency-Key`.



## OpenAPI

````yaml openapi/pt/cell.json POST /v1/coordination/declare
openapi: 3.1.0
info:
  title: API de dados da Niadra
  version: '1'
  description: >-
    Escrita, contexto, histórico, objetos, identidade, privacidade e governança
    de um espaço. Cada espaço tem um endereço estável, com o espaço e a região
    no nome.
servers:
  - url: https://{space}.{region}.api.niadra.com
    variables:
      space:
        default: acme-prod
        description: O espaço, que vem na chave de fonte.
      region:
        default: us-east-2
        description: A região do espaço, que também vem na chave.
security: []
paths:
  /v1/coordination/declare:
    post:
      tags:
        - coordination
      summary: Declarar o que aconteceu
      description: >-
        O que aconteceu, depois do fato: um caso aberto ou fechado, uma posse,
        uma trava de tarefa, um contato que saiu (`contact.made`, com o `jti` do
        token), como um efeito reservado terminou, um compromisso feito,
        retirado ou decidido, uma transferência que avançou, uma supressão
        adicionada ou levantada. Uma declaração nunca falha pela ordem em que
        chega; um `contact.made` de uma decisão que já não é guardada é
        registrado mesmo assim.


        **Autenticação.** Chave de fonte: `Authorization: Bearer nia_sk_...`.
        Escopo exigido: `coordinate`. Só responde num espaço com a
        funcionalidade `coordination` ligada (o documento `features`); num
        espaço sem ela, 404.
      operationId: declare_v1_coordination_declare_post
      parameters:
        - in: header
          name: Idempotency-Key
          required: true
          schema:
            maxLength: 256
            minLength: 1
            title: Idempotency-Key
            type: string
          description: >-
            Obrigatório. Guardado por 24 horas com o hash do corpo: a mesma
            chave com o mesmo corpo devolve a primeira resposta, e a mesma chave
            com outro corpo devolve 409 `conflict`.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DeclareRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeclareResult'
          description: A declaração foi registrada; `accepted` diz se um compromisso vale.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: O pedido não bate com o contrato.
        '503':
          description: '`coordination_unavailable`: nada novo foi registrado, mande de novo.'
      security:
        - sourceKey: []
      x-codeSamples:
        - lang: python
          label: Python
          source: >-
            # One farewell per conversation: the check reserved the effect, the
            declaration settles it

            key = f"farewell:{conversation.conversation_id}"

            decision = conversation.check("farewell", purpose="service",
            effect_key=key)

            if decision.decision == "allow" and decision.effect and
            decision.effect.state == "none":
                try:
                    send(farewell)
                    conversation.declare.effect(key, "done")
                except TimeoutError:
                    conversation.declare.effect(key, "unknown_outcome")  # never sent again on its own
        - lang: typescript
          label: TypeScript
          source: >-
            // One farewell per conversation: the check reserved the effect, the
            declaration settles it

            const key = `farewell:${convo.id}`;

            const decision = await convo.check("farewell", { purpose: "service",
            effectKey: key });

            if (decision.decision === "allow" && decision.effect?.state ===
            "none") {
              try {
                await send(farewell);
                convo.declare.effect(key, "done");
              } catch {
                convo.declare.effect(key, "unknown_outcome"); // never sent again on its own
              }
            }
components:
  schemas:
    DeclareRequest:
      description: >-
        O que aconteceu, depois do fato: um tipo de declaração, com os campos do
        tipo em `detail` (a especificação de coordenação, 5).
      discriminator:
        mapping:
          case.closed:
            $ref: '#/components/schemas/CaseClosed'
          case.opened:
            $ref: '#/components/schemas/CaseOpened'
          commitment.decided:
            $ref: '#/components/schemas/CommitmentDecided'
          commitment.made:
            $ref: '#/components/schemas/CommitmentMade'
          commitment.withdrawn:
            $ref: '#/components/schemas/CommitmentWithdrawn'
          contact.made:
            $ref: '#/components/schemas/ContactMade'
          effect:
            $ref: '#/components/schemas/EffectDeclared'
          handoff:
            $ref: '#/components/schemas/HandoffDeclared'
          lease:
            $ref: '#/components/schemas/LeaseDeclared'
          suppression.added:
            $ref: '#/components/schemas/SuppressionAdded'
          suppression.lifted:
            $ref: '#/components/schemas/SuppressionLifted'
          task_lock:
            $ref: '#/components/schemas/TaskLockDeclared'
        propertyName: kind
      oneOf:
        - $ref: '#/components/schemas/CaseOpened'
        - $ref: '#/components/schemas/CaseClosed'
        - $ref: '#/components/schemas/LeaseDeclared'
        - $ref: '#/components/schemas/TaskLockDeclared'
        - $ref: '#/components/schemas/ContactMade'
        - $ref: '#/components/schemas/EffectDeclared'
        - $ref: '#/components/schemas/CommitmentMade'
        - $ref: '#/components/schemas/CommitmentWithdrawn'
        - $ref: '#/components/schemas/CommitmentDecided'
        - $ref: '#/components/schemas/HandoffDeclared'
        - $ref: '#/components/schemas/SuppressionAdded'
        - $ref: '#/components/schemas/SuppressionLifted'
      title: DeclareRequest
    DeclareResult:
      additionalProperties: false
      properties:
        accepted:
          title: Accepted
          type: boolean
        decision_id:
          anyOf:
            - format: uuid
              type: string
            - type: 'null'
          title: Decision Id
      required:
        - accepted
      title: DeclareResult
      type: object
    Problem:
      additionalProperties: false
      description: >-
        Detalhes do problema no formato da RFC 9457; `code` vem do catálogo de
        erros versionado.
      properties:
        code:
          title: Code
          type: string
        detail:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Detail
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Request Id
        status:
          title: Status
          type: integer
        title:
          title: Title
          type: string
        type:
          default: about:blank
          title: Type
          type: string
      required:
        - title
        - status
        - code
      title: Problem
      type: object
    CaseClosed:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/ReleaseDetail'
        kind:
          const: case.closed
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: CaseClosed
      type: object
    CaseOpened:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/LeaseDetail'
        kind:
          const: case.opened
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: CaseOpened
      type: object
    CommitmentDecided:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/CommitmentDecidedDetail'
        kind:
          const: commitment.decided
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: CommitmentDecided
      type: object
    CommitmentMade:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/CommitmentMadeDetail'
        kind:
          const: commitment.made
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: CommitmentMade
      type: object
    CommitmentWithdrawn:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/CommitmentWithdrawnDetail'
        kind:
          const: commitment.withdrawn
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: CommitmentWithdrawn
      type: object
    ContactMade:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/ContactMadeDetail'
        kind:
          const: contact.made
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: ContactMade
      type: object
    EffectDeclared:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/EffectDetail'
        kind:
          const: effect
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: EffectDeclared
      type: object
    HandoffDeclared:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/HandoffDetail'
        kind:
          const: handoff
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: HandoffDeclared
      type: object
    LeaseDeclared:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/LeaseDetail'
        kind:
          const: lease
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: LeaseDeclared
      type: object
    SuppressionAdded:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/SuppressionAddedDetail'
        kind:
          const: suppression.added
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: SuppressionAdded
      type: object
    SuppressionLifted:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/SuppressionLiftedDetail'
        kind:
          const: suppression.lifted
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: SuppressionLifted
      type: object
    TaskLockDeclared:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/TaskLockDetail'
        kind:
          const: task_lock
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: TaskLockDeclared
      type: object
    ReleaseDetail:
      additionalProperties: false
      description: >-
        A reivindicação que um caso encerra, com a época que ela recebeu quando
        foi aceita.
      properties:
        claim_id:
          format: uuid
          title: Claim Id
          type: string
        epoch:
          minimum: 0
          title: Epoch
          type: integer
      required:
        - claim_id
        - epoch
      title: ReleaseDetail
      type: object
    ObjectRef:
      additionalProperties: false
      description: Um objeto de negócio num sistema de registro.
      properties:
        id:
          maxLength: 512
          minLength: 1
          title: Id
          type: string
          description: O id nesse sistema.
        namespace:
          maxLength: 256
          minLength: 1
          title: Namespace
          type: string
          description: O sistema onde ele vive, como `erp`.
        type:
          maxLength: 256
          minLength: 1
          title: Type
          type: string
          description: Tipo do objeto, como `invoice`, `order` ou `ticket`.
      required:
        - type
        - namespace
        - id
      title: ObjectRef
      type: object
    Handle:
      additionalProperties: false
      description: >-
        Um identificador de um sujeito num canal ou sistema: um telefone, um
        e-mail, um id do CRM.
      properties:
        scope:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          description: >-
            Espaço de nomes dos identificadores com escopo: a conta do WhatsApp
            Business para `wa_bsuid`, o sistema para `system_id`, o país para
            `gov_id_hmac`.
          title: Scope
        subject_kind:
          anyOf:
            - $ref: '#/components/schemas/SubjectKind'
            - type: 'null'
          description: >-
            O padrão é `person`, exceto nos tipos de handle que só identificam
            organizações.
        type:
          $ref: '#/components/schemas/HandleType'
        value:
          maxLength: 320
          minLength: 1
          title: Value
          type: string
          description: >-
            O identificador. Normalizado no servidor: E.164 para telefone,
            minúsculas para e-mail.
      required:
        - type
        - value
      title: Handle
      type: object
    LeaseDetail:
      additionalProperties: false
      description: >-
        Uma posse ou um caso, detidos pelo agente que declara. `level` é por
        padrão o nível menos restritivo do espaço.
      properties:
        intents:
          items:
            pattern: ^[a-z][a-z0-9_]{0,39}$
            type: string
          maxItems: 20
          title: Intents
          type: array
        lease_s:
          maximum: 86400
          minimum: 1
          title: Lease S
          type: integer
        level:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Level
      required:
        - lease_s
      title: LeaseDetail
      type: object
    CommitmentDecidedDetail:
      additionalProperties: false
      description: >-
        A pessoa aceitou ou recusou um compromisso, talvez numa conversa
        posterior.
      properties:
        commitment_id:
          maxLength: 512
          minLength: 1
          title: Commitment Id
          type: string
        outcome:
          enum:
            - accepted
            - declined
          title: Outcome
          type: string
      required:
        - commitment_id
        - outcome
      title: CommitmentDecidedDetail
      type: object
    CommitmentMadeDetail:
      additionalProperties: false
      description: '`score` ordena compromissos de um tipo `best_wins`: o maior vale.'
      properties:
        commitment_id:
          maxLength: 512
          minLength: 1
          title: Commitment Id
          type: string
        score:
          anyOf:
            - type: number
            - type: 'null'
          title: Score
        terms:
          additionalProperties: true
          title: Terms
          type: object
        type:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Type
          type: string
        valid_until:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Valid Until
      required:
        - commitment_id
        - type
      title: CommitmentMadeDetail
      type: object
    CommitmentWithdrawnDetail:
      additionalProperties: false
      properties:
        commitment_id:
          maxLength: 512
          minLength: 1
          title: Commitment Id
          type: string
      required:
        - commitment_id
      title: CommitmentWithdrawnDetail
      type: object
    ContactMadeDetail:
      additionalProperties: false
      description: >-
        `jti` é o do token de contato; `unchecked` diz que o contato saiu sem
        decisão, porque a finalidade falha aberta e nenhuma chegou a tempo.
      properties:
        channel:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Channel
          type: string
        decision_id:
          anyOf:
            - format: uuid
              type: string
            - type: 'null'
          title: Decision Id
        gateway_id:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Gateway Id
        jti:
          anyOf:
            - format: uuid
              type: string
            - type: 'null'
          title: Jti
        purpose:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Purpose
          type: string
        unchecked:
          default: false
          title: Unchecked
          type: boolean
      required:
        - purpose
        - channel
      title: ContactMadeDetail
      type: object
    EffectDetail:
      additionalProperties: false
      description: Como terminou a tentativa que quem chama detém.
      properties:
        attempt:
          minimum: 1
          title: Attempt
          type: integer
        effect_key:
          maxLength: 512
          minLength: 1
          title: Effect Key
          type: string
        state:
          enum:
            - done
            - failed
            - unknown_outcome
          title: State
          type: string
      required:
        - effect_key
        - state
        - attempt
      title: EffectDetail
      type: object
    HandoffDetail:
      additionalProperties: false
      properties:
        handoff_id:
          maxLength: 512
          minLength: 1
          title: Handoff Id
          type: string
        outcome:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Outcome
        status:
          enum:
            - created
            - accepted
            - closed
          title: Status
          type: string
      required:
        - handoff_id
        - status
      title: HandoffDetail
      type: object
    SuppressionAddedDetail:
      additionalProperties: false
      description: >-
        O cliente não pode ser contatado para `purpose`, em `channel` ou em todo
        canal. `until` é por padrão o intervalo do próprio motivo, ou sem fim.
      properties:
        channel:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Channel
        purpose:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Purpose
          type: string
        reason:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Reason
          type: string
        until:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Until
      required:
        - purpose
        - reason
      title: SuppressionAddedDetail
      type: object
    SuppressionLiftedDetail:
      additionalProperties: false
      description: Levanta o que a mesma fonte suprimiu para `purpose` e `channel`.
      properties:
        channel:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Channel
        purpose:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Purpose
          type: string
      required:
        - purpose
      title: SuppressionLiftedDetail
      type: object
    TaskLockDetail:
      additionalProperties: false
      properties:
        lease_s:
          maximum: 86400
          minimum: 1
          title: Lease S
          type: integer
        task:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Task
          type: string
      required:
        - task
        - lease_s
      title: TaskLockDetail
      type: object
    SubjectKind:
      enum:
        - person
        - account
        - partner
      title: SubjectKind
      type: string
      description: >-
        Uma pessoa, uma organização cliente (`account`) ou uma organização que
        participa sem ser cliente (`partner`).
    HandleType:
      enum:
        - phone_e164
        - wa_id
        - wa_jid
        - wa_lid
        - wa_bsuid
        - email
        - gov_id_hmac
        - app_user_id
        - system_id
        - org_registry_hmac
        - email_domain
        - anon_id
      title: HandleType
      type: string
      description: >-
        O tipo de identificador. O valor é classificado pelo formato, nunca pelo
        campo de onde veio.
  securitySchemes:
    sourceKey:
      type: http
      scheme: bearer
      description: nia_sk_...

````