openapi: 3.1.0
info:
  title: Chatemoon API
  version: 1.0.0
  description: Account and widget extensions for the Chatemoon conversation platform.
externalDocs:
  description: Core API for conversations, attachments, contacts, operators and signed account webhooks
  url: https://developers.chatwoot.com/api-reference/introduction
servers:
  - url: /api/v1
webhooks:
  chatemoon_conversation_handed_off:
    post:
      security: []
      summary: Automation hands a conversation to an operator
      parameters:
        - $ref: '#/components/parameters/WebhookDelivery'
        - $ref: '#/components/parameters/WebhookTimestamp'
        - $ref: '#/components/parameters/WebhookSignature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [event, conversation_id, inbox_id, team_id, reason]
              properties:
                event: { const: chatemoon_conversation_handed_off }
                conversation_id: { type: integer, description: Conversation display ID in the subscribing account }
                inbox_id: { type: integer }
                team_id: { type: [integer, 'null'] }
                reason: { type: string }
      responses:
        '2XX': { description: Accepted }
  csat_survey_submitted:
    post:
      security: []
      summary: A customer submits or updates a satisfaction score
      parameters:
        - $ref: '#/components/parameters/WebhookDelivery'
        - $ref: '#/components/parameters/WebhookTimestamp'
        - $ref: '#/components/parameters/WebhookSignature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [event, id, conversation_id, assigned_agent_id, rating]
              properties:
                event: { const: csat_survey_submitted }
                id: { type: integer }
                conversation_id: { type: integer, description: Conversation display ID in the subscribing account }
                assigned_agent_id: { type: [integer, 'null'] }
                rating: { type: integer, minimum: 1, maximum: 5 }
      responses:
        '2XX': { description: Accepted }
security:
  - accountToken: []
paths:
  /accounts/{account_id}/inboxes/{inbox_id}:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Inbox'
    patch:
      summary: Configure embedded widget visibility for a website inbox
      description: This request replaces the supplied Chatemoon preferences. Include existing preferences to retain them. The rules only affect the embedded widget.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [channel]
              properties:
                channel:
                  type: object
                  required: [chatemoon_preferences]
                  properties:
                    chatemoon_preferences:
                      type: object
                      properties:
                        page_rules:
                          type: array
                          maxItems: 40
                          description: Any matching deny rule hides the widget. With allow rules, a page must match at least one to display the widget. An empty list displays the widget on any page.
                          items:
                            type: object
                            additionalProperties: false
                            required: [action, operator, value]
                            properties:
                              action: { type: string, enum: [allow, deny] }
                              operator: { type: string, enum: [contains, equals, starts_with] }
                              value:
                                type: string
                                minLength: 1
                                maxLength: 2048
                                description: Use a full HTTP or HTTPS address for equals and starts_with. Contains accepts a literal fragment.
      responses:
        '200': { description: Inbox with its updated widget preferences }
        '422': { description: A rule has an invalid action, operator, or value }
  /accounts/{account_id}/conversations/{conversation_id}/messages/{id}/content:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/MessageConversation'
      - $ref: '#/components/parameters/Record'
    patch:
      summary: Edit a website text reply within one hour of sending it
      description: Requires the operator who authored the reply.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [content]
              properties:
                content: { type: string, minLength: 1, maxLength: 150000 }
      responses:
        '200': { description: Updated message }
        '401': { description: Caller cannot edit this message }
        '404': { description: Conversation or message does not exist in this account }
        '422': { description: Message or replacement text is ineligible }
  /accounts/{account_id}/conversations/{conversation_id}/messages/{id}/edit_history:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/MessageConversation'
      - $ref: '#/components/parameters/Record'
    get:
      summary: List previous versions of a message for an authorized operator
      parameters:
        - in: query
          name: before_id
          description: The next cursor from the preceding page.
          schema: { type: integer, minimum: 1 }
      responses:
        '200':
          description: Up to 50 previous versions in reverse chronological order
          content:
            application/json:
              schema:
                type: object
                required: [edits, next_cursor]
                properties:
                  edits:
                    type: array
                    items:
                      type: object
                      required: [id, content, created_at]
                      properties:
                        id: { type: integer }
                        content: { type: string }
                        created_at: { type: string, format: date-time }
                  next_cursor: { type: [integer, 'null'] }
        '401': { description: Requires operator access to the conversation }
        '404': { description: Conversation or message does not exist in this account }
        '422': { description: Invalid pagination cursor }
  /accounts/{account_id}/chatemoon/inboxes/{inbox_id}/settings:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Inbox'
    get:
      summary: Read intake routing and conversation timers as administrator
      responses:
        '200':
          description: Current configuration
          content: { application/json: { schema: { $ref: '#/components/schemas/Intake' } } }
    patch:
      summary: Update intake routing, inbox conversation timers, and department overrides
      requestBody:
        required: true
        content: { application/json: { schema: { $ref: '#/components/schemas/Intake' } } }
      responses:
        '200': { description: Updated configuration }
        '422': { description: Invalid route or reference }
  /accounts/{account_id}/chatemoon/conversations/{id}/ownership:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Conversation'
    get:
      summary: Read the current owner type and available delegation modes
      responses:
        '200': { $ref: '#/components/responses/Ownership' }
  /accounts/{account_id}/chatemoon/conversations/{id}/delegate:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Conversation'
    post:
      summary: Delegate a conversation to its configured model or workflow
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                mode: { enum: [ai, workflow], default: ai }
      responses:
        '200': { $ref: '#/components/responses/Ownership' }
        '422': { description: Conversation cannot be delegated }
  /accounts/{account_id}/chatemoon/conversations/{id}/claim:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Conversation'
    post:
      summary: Transfer the conversation to the authenticated operator
      responses:
        '200': { $ref: '#/components/responses/Ownership' }
        '422': { description: Conversation cannot be claimed }
  /accounts/{account_id}/chatemoon/workflows:
    parameters:
      - $ref: '#/components/parameters/Account'
    get:
      summary: List workflow drafts and published version identifiers
      responses:
        '200': { description: Workflow list }
    post:
      summary: Create a workflow draft
      requestBody:
        $ref: '#/components/requestBodies/Workflow'
      responses:
        '201': { description: Created workflow }
        '422': { description: Invalid draft }
  /accounts/{account_id}/chatemoon/workflows/{id}:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Record'
    patch:
      summary: Edit a workflow draft
      requestBody:
        $ref: '#/components/requestBodies/Workflow'
      responses:
        '200': { description: Updated workflow }
    delete:
      summary: Delete a workflow
      responses:
        '204': { description: Deleted workflow }
        '409': { description: Workflow is in use }
  /accounts/{account_id}/chatemoon/workflows/{id}/publish:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Record'
    post:
      summary: Validate and publish an immutable workflow version
      responses:
        '200': { description: Workflow and version list }
        '422': { description: Graph could not be published }
  /accounts/{account_id}/chatemoon/workflows/{id}/rollback:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Record'
    post:
      summary: Select a previous published version
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [version_id]
              properties:
                version_id: { type: integer }
      responses:
        '200': { description: Rolled back workflow }
        '404': { description: Workflow or version does not exist }
  /accounts/{account_id}/chatemoon/workflows/{id}/preview:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Record'
    post:
      summary: Preview the draft with sample input
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                input: { type: string }
                page_url: { type: string, format: uri }
                local_hour: { type: integer, minimum: 0, maximum: 23 }
                contact: { type: object }
      responses:
        '200': { description: Preview steps }
        '422': { description: Invalid draft or input }
  /accounts/{account_id}/chatemoon/connectors:
    parameters:
      - $ref: '#/components/parameters/Account'
    get:
      summary: List connectors without their secrets
      responses:
        '200': { description: Connector list }
    post:
      summary: Create a model, MCP, A2A or HTTP connector
      requestBody:
        $ref: '#/components/requestBodies/Connector'
      responses:
        '201': { description: Created connector with a redacted secret }
        '422': { description: Invalid connector }
  /accounts/{account_id}/chatemoon/connectors/{id}:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Record'
    patch:
      summary: Update a connector
      requestBody:
        $ref: '#/components/requestBodies/Connector'
      responses:
        '200': { description: Updated connector }
    delete:
      summary: Delete a connector
      responses:
        '204': { description: Deleted connector }
        '409': { description: Connector is in use }
  /accounts/{account_id}/chatemoon/connectors/{id}/test:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Record'
    post:
      summary: Test an existing connector
      responses:
        '200': { description: Connector test result }
        '422': { description: Connector test failed }
  /accounts/{account_id}/chatemoon/connectors/import_curl:
    parameters:
      - $ref: '#/components/parameters/Account'
    post:
      summary: Parse a cURL sample into HTTP connector configuration
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [curl]
              properties:
                curl: { type: string, description: Import text is parsed as configuration. }
      responses:
        '200': { description: Parsed connector fields }
        '422': { description: Unsupported or invalid sample }
  /accounts/{account_id}/chatemoon/visitors:
    parameters:
      - $ref: '#/components/parameters/Account'
      - in: query
        name: inbox_id
        schema: { type: integer }
    get:
      summary: List recent visitors in accessible inboxes
      responses:
        '200':
          description: Visitor sessions from the last two minutes
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id: { type: integer }
                    contact_id: { type: integer }
                    inbox_id: { type: integer }
                    inbox_name: { type: string }
                    name: { type: string }
                    page_url: { type: string, format: uri }
                    referrer: { type: [string, 'null'], format: uri }
                    device: { type: [string, 'null'] }
                    last_seen_at: { type: string, format: date-time }
  /accounts/{account_id}/chatemoon/visitors/{id}/message:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Record'
    post:
      summary: Send a proactive message to the visitor's current widget session
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [content]
              properties:
                content: { type: string, minLength: 1, maxLength: 5000 }
      responses:
        '201':
          description: Conversation display identifier
          content:
            application/json:
              schema:
                type: object
                properties:
                  conversation_id: { type: integer }
        '404': { description: Session expired or outside the operator's inbox }
  /accounts/{account_id}/data_exports:
    parameters:
      - $ref: '#/components/parameters/Account'
    get:
      summary: List export history for this account
      parameters:
        - in: query
          name: before_id
          description: ID of the last export on the preceding page
          schema: { type: integer, minimum: 1 }
      responses:
        '200':
          description: Up to 25 export records, newest first
          content:
            application/json:
              schema:
                type: object
                required: [payload, has_more]
                properties:
                  payload:
                    type: array
                    items: { $ref: '#/components/schemas/DataExport' }
                  has_more: { type: boolean }
        '401': { description: Export permission is required }
        '422': { description: Invalid page cursor }
    post:
      summary: Queue a contact export, closed conversation archive, or widget form export
      description: Contact exports accept the existing contact filters. Only workspace administrators can export closed conversations or form responses. Excel files stay available for 30 days after completion. Form exports support up to 10000 recorded submissions and 100000 field answers in separate worksheets. Older forms without recorded submissions are excluded.
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - type: object
                  additionalProperties: false
                  properties:
                    data_type: { enum: [contacts, contacts_xlsx], default: contacts }
                    label: { type: string, description: Contact label title }
                    scope_name: { type: string, description: Display name for the selection }
                    column_names:
                      type: array
                      items: { type: string }
                    payload:
                      type: array
                      items: { type: object, description: A Chatwoot contact filter }
                - type: object
                  required: [data_type]
                  additionalProperties: false
                  properties:
                    data_type: { const: conversations_xlsx }
                    inbox_id: { type: integer }
                    from: { type: string, format: date, description: First inclusive creation date in Asia/Tehran }
                    to: { type: string, format: date, description: Final inclusive creation date in Asia/Tehran }
                - type: object
                  required: [data_type]
                  additionalProperties: false
                  properties:
                    data_type: { const: forms_xlsx }
                    inbox_id: { type: integer, description: Website inbox ID }
                    form_type: { enum: [prechat, offline, delay], description: Omit to include all recorded form types }
                    from: { type: string, format: date, description: First inclusive submission date in Asia/Tehran }
                    to: { type: string, format: date, description: Final inclusive submission date in Asia/Tehran }
      responses:
        '200': { $ref: '#/components/responses/DataExport' }
        '401': { description: Export permission is required }
        '422': { description: Invalid export type or filters }
  /accounts/{account_id}/data_exports/{id}:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Record'
    get:
      summary: Read progress and availability for an export
      responses:
        '200': { $ref: '#/components/responses/DataExport' }
        '401': { description: Export permission is required }
        '404': { description: Export not found in this account }
  /accounts/{account_id}/data_exports/{id}/rerun:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Record'
    post:
      summary: Queue a new export using the same options
      responses:
        '200': { $ref: '#/components/responses/DataExport' }
        '401': { description: Export permission is required }
        '404': { description: Export not found in this account }
        '422': { description: Export is still running or its filters are no longer valid }
  /accounts/{account_id}/data_exports/{id}/download:
    parameters:
      - $ref: '#/components/parameters/Account'
      - $ref: '#/components/parameters/Record'
    get:
      summary: Issue a five-minute download URL for a completed export
      responses:
        '200':
          description: Signed download URL
          content:
            application/json:
              schema:
                type: object
                required: [download_url]
                properties:
                  download_url: { type: string, format: uri }
        '401': { description: Export permission is required }
        '404': { description: Export not found in this account or file unavailable }
  /accounts/{account_id}/chatemoon/automation_report:
    parameters:
      - $ref: '#/components/parameters/Account'
      - in: query
        name: days
        schema: { type: integer, enum: [7, 30, 90], default: 30 }
      - in: query
        name: inbox_id
        schema: { type: integer }
    get:
      summary: Read human replies, automated replies, and handoff statistics
      responses:
        '200': { description: Period totals and daily series }
  /accounts/{account_id}/chatemoon/automation_report/export:
    parameters:
      - $ref: '#/components/parameters/Account'
      - in: query
        name: days
        schema: { type: integer, enum: [7, 30, 90], default: 30 }
      - in: query
        name: inbox_id
        schema: { type: integer }
    get:
      summary: Download the filtered automation report as an Excel workbook
      responses:
        '200':
          description: Workbook with period totals and replies by day
          content:
            application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:
              schema: { type: string, format: binary }
  /accounts/{account_id}/chatemoon/billing:
    parameters:
      - $ref: '#/components/parameters/Account'
    get:
      summary: Read available plans, subscription and recent payments
      responses:
        '200': { description: Workspace billing status }
  /accounts/{account_id}/chatemoon/billing/checkout:
    parameters:
      - $ref: '#/components/parameters/Account'
    post:
      summary: Create a Zarinpal checkout for a listed subscription plan
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [plan_key, interval]
              properties:
                plan_key: { type: string }
                interval: { enum: [monthly, annual] }
      responses:
        '201':
          description: Checkout created
          content:
            application/json:
              schema:
                type: object
                properties:
                  checkout_url: { type: string, format: uri }
        '422': { description: Plan or gateway is unavailable }
  /accounts/{account_id}/chatemoon/billing/payments/{id}/refund:
    post:
      summary: Request manual refund review for a verified payment
      description: Workspace administrators can request review. The current subscription stays active through its scheduled end date.
      parameters:
        - $ref: '#/components/parameters/Account'
        - in: path
          name: id
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Payment with refund requested status
          content:
            application/json:
              schema:
                type: object
                required: [id, status, amount]
                properties:
                  id:
                    type: integer
                  status:
                    const: refund_requested
                  amount:
                    type: integer
                    description: Payment amount in Iranian rials
        '403':
          description: Administrator access is required
        '404':
          description: Payment is unavailable in this workspace
        '422':
          description: Payment is ineligible or review is complete
  /widget/chatemoon/presence:
    parameters:
      - $ref: '#/components/parameters/Website'
    post:
      security:
        - widgetToken: []
      summary: Record the current page for the visitor's widget session
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [page_url]
              properties:
                page_url: { type: string, format: uri }
                referrer: { type: string, format: uri }
      responses:
        '204': { description: Presence recorded }
        '422': { description: Invalid URL or blocked contact }
  /widget/chatemoon/queue_position:
    parameters:
      - $ref: '#/components/parameters/Website'
      - in: query
        name: conversation_id
        required: true
        description: Display identifier of this widget session's current conversation
        schema: { type: integer, minimum: 1 }
    get:
      security:
        - widgetToken: []
      summary: Read the visitor's position among waiting conversations in this inbox and team
      responses:
        '200':
          description: A position from 1 to 100, or null when unavailable or disabled
          content:
            application/json:
              schema:
                type: object
                required: [position]
                properties:
                  position: { type: [integer, 'null'], minimum: 1, maximum: 100 }
        '403': { description: Blocked contact }
        '404': { description: Invalid widget session }
        '429': { description: Too many requests }
  /widget/chatemoon/offline:
    parameters:
      - $ref: '#/components/parameters/Website'
    get:
      security:
        - widgetToken: []
      summary: Read the offline mode for the visitor's inbox and current conversation
      responses:
        '200':
          description: The effective mode and fields still required from this visitor
          content:
            application/json:
              schema:
                type: object
                required: [mode, messaging_blocked]
                properties:
                  mode: { type: string, enum: [normal, hide, message, form] }
                  messaging_blocked: { type: boolean }
                  message: { type: [string, 'null'] }
                  form_submitted: { type: boolean }
                  fields:
                    type: array
                    items:
                      type: object
                      required: [id, label, type]
                      properties:
                        id: { type: string }
                        label: { type: string }
                        type: { type: string, enum: [text, email, phone] }
                        required: { type: boolean }
                        profile: { type: string, enum: ['', name, email, phone_number] }
        '403': { description: The contact is blocked }
        '404': { description: The widget session is unavailable for this inbox }
    post:
      security:
        - widgetToken: []
      summary: Submit an offline contact form as an incoming conversation message
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [message]
              properties:
                message: { type: string, minLength: 1, maxLength: 2000 }
                fields:
                  description: Map each displayed field ID to its submitted value
                  type: object
                  maxProperties: 8
                  additionalProperties: { type: string, maxLength: 254 }
      responses:
        '201':
          description: Conversation that received the form
          content:
            application/json:
              schema:
                type: object
                required: [conversation_id]
                properties:
                  conversation_id: { type: integer, description: Account-local conversation ID }
        '403': { description: The contact is blocked }
        '404': { description: The widget session is unavailable for this inbox }
        '409': { description: The form is unavailable or has already been submitted }
        '422': { description: The submitted message or fields are invalid }
  /widget/chatemoon/response_delay:
    parameters:
      - $ref: '#/components/parameters/Website'
      - in: query
        name: conversation_id
        required: true
        schema: { type: integer, minimum: 1 }
    get:
      security:
        - widgetToken: []
      summary: Read the configured notice or form for an unanswered visitor message
      responses:
        '200':
          description: The delay mode is off until the conversation is eligible
          content:
            application/json:
              schema:
                type: object
                required: [mode]
                properties:
                  mode: { type: string, enum: [off, message, form] }
                  message: { type: [string, 'null'] }
                  fields:
                    type: array
                    items:
                      type: object
                      required: [id, label, type]
                      properties:
                        id: { type: string }
                        label: { type: string }
                        type: { type: string, enum: [text, email, phone] }
                        required: { type: boolean }
                        profile: { type: string, enum: ['', name, email, phone_number] }
        '404': { description: The widget session or conversation is unavailable }
    post:
      security:
        - widgetToken: []
      summary: Add a delayed response form to the same conversation
      requestBody:
        $ref: '#/paths/~1widget~1chatemoon~1offline/post/requestBody'
      responses:
        '201':
          description: The conversation received the form
          content:
            application/json:
              schema:
                type: object
                required: [conversation_id]
                properties:
                  conversation_id: { type: integer }
        '404': { description: The widget session or conversation is unavailable }
        '409': { description: The waiting period ended or the form was already submitted }
        '422': { description: The submitted message or fields are invalid }
  /widget/conversations/chatemoon/handoff:
    parameters:
      - $ref: '#/components/parameters/Website'
    post:
      security:
        - widgetToken: []
      summary: Request a human operator from the current widget conversation
      responses:
        '200': { $ref: '#/components/responses/Ownership' }
        '404': { description: No conversation exists for this session }
  /widget/conversations/chatemoon/resume:
    parameters:
      - $ref: '#/components/parameters/Website'
    post:
      security:
        - widgetToken: []
      summary: Issue a single-use resume token for a hosted widget
      responses:
        '200':
          description: Token and expiry in seconds
          content:
            application/json:
              schema:
                type: object
                properties:
                  token: { type: string }
                  expires_in: { type: integer }
        '404': { description: No conversation exists for this session }
components:
  parameters:
    WebhookDelivery:
      in: header
      name: X-Chatwoot-Delivery
      required: true
      description: Delivery identifier that stays the same on retries
      schema: { type: string, format: uuid }
    WebhookTimestamp:
      in: header
      name: X-Chatwoot-Timestamp
      required: true
      description: Unix timestamp in seconds for the current attempt
      schema: { type: integer }
    WebhookSignature:
      in: header
      name: X-Chatwoot-Signature
      required: true
      description: HMAC-SHA256 of timestamp.body with the webhook secret, prefixed with sha256=
      schema: { type: string }
    Account: { in: path, name: account_id, required: true, schema: { type: integer } }
    Inbox: { in: path, name: inbox_id, required: true, schema: { type: integer } }
    Conversation: { in: path, name: id, required: true, description: Display identifier in this account, schema: { type: integer } }
    MessageConversation: { in: path, name: conversation_id, required: true, description: Conversation display identifier in this account, schema: { type: integer } }
    Record: { in: path, name: id, required: true, schema: { type: integer } }
    Website: { in: query, name: website_token, required: true, schema: { type: string } }
  securitySchemes:
    accountToken: { type: apiKey, in: header, name: api_access_token }
    widgetToken: { type: apiKey, in: header, name: X-Auth-Token }
  requestBodies:
    Workflow:
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              name: { type: string }
              draft_graph:
                type: object
                properties:
                  entry: { type: string }
                  nodes: { type: array, items: { type: object } }
                  edges: { type: array, items: { type: object } }
    Connector:
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              name: { type: string }
              kind: { enum: [model, mcp, agent, http] }
              enabled: { type: boolean }
              secret: { type: string, writeOnly: true }
              config: { type: object }
  responses:
    DataExport:
      description: Asynchronous export record with progress and availability
      content:
        application/json:
          schema: { $ref: '#/components/schemas/DataExport' }
    Ownership:
      description: Conversation ownership
      content:
        application/json:
          schema:
            type: object
            properties:
              mode: { enum: [human, workflow, ai] }
              revision: { type: integer }
              reason: { type: [string, 'null'] }
              available_modes: { type: array, items: { enum: [workflow, ai] } }
  schemas:
    DataExport:
      type: object
      required: [id, name, data_type, status, processed_records, export_options, downloadable, can_rerun]
      properties:
        id: { type: integer }
        name: { type: string }
        data_type: { enum: [contacts, contacts_xlsx, conversations_xlsx, forms_xlsx] }
        status: { enum: [pending, processing, completed, failed] }
        processed_records: { type: integer }
        total_records: { type: [integer, 'null'] }
        error_message: { type: [string, 'null'] }
        export_options: { type: object }
        downloadable: { type: boolean }
        can_rerun: { type: boolean }
    Intake:
      type: object
      properties:
        inbox_id: { type: integer, readOnly: true }
        mode: { enum: [human, workflow, ai] }
        fallback_team_id: { type: [integer, 'null'] }
        connector_id: { type: [integer, 'null'] }
        workflow_id: { type: [integer, 'null'] }
        return_to_queue_after_minutes:
          type: [integer, 'null']
          minimum: 1
          maximum: 43200
          description: Minimum minutes waiting for the current operator before returning to the same team's queue. Null disables the rule.
        auto_resolve_after_minutes:
          type: [integer, 'null']
          minimum: 1
          maximum: 43200
          description: Minimum minutes since the last unanswered public operator reply before resolving. Null disables the rule.
        department_modes:
          type: object
          additionalProperties:
            type: object
            properties:
              mode: { enum: [human, workflow, ai] }
              fallback_team_id: { type: [integer, 'null'] }
              connector_id: { type: [integer, 'null'] }
              workflow_id: { type: [integer, 'null'] }
