{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/mojeeb-app/json-schema/mojeeb-app-conversation-schema.json",
  "title": "Conversation",
  "description": "A conversation with one customer on one channel, as a list shows it.",
  "x-generated": "2026-11-19",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/mojeeb-app-openapi.yaml#/components/schemas/Conversation",
  "type": "object",
  "required": [
    "id",
    "agent_id",
    "contact_id",
    "channel",
    "status",
    "customer_name",
    "last_message",
    "last_message_at",
    "last_message_by",
    "is_read",
    "urgent",
    "needs_attention",
    "sentiment",
    "ai_enabled",
    "ai_paused_until",
    "assigned_to",
    "created_at",
    "latest_ad_id",
    "attribution"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "agent_id": {
      "type": "string",
      "format": "uuid"
    },
    "contact_id": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "The contact this customer is; read it with `getContact`."
    },
    "channel": {
      "type": "string",
      "description": "`whatsapp`, `facebook`, `instagram`, `tiktok`, `widget`, `web` or `test`; new values may appear."
    },
    "status": {
      "type": "string",
      "description": "`open`, `closed` or `archived` (`draft` for one that never started); new values may appear."
    },
    "customer_name": {
      "type": [
        "string",
        "null"
      ]
    },
    "last_message": {
      "type": [
        "string",
        "null"
      ],
      "description": "The last message's text, up to 500 characters. A message sent to the customer without text reads as a placeholder such as `[Photo]`. A customer's photo, voice note, sticker or file sent without a caption changes neither this nor `last_message_at` (only `last_message_by` becomes `customer`)."
    },
    "last_message_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "When `last_message` was written; what `active_since` and the list's order follow. A customer's media message without a caption doesn't move it."
    },
    "last_message_by": {
      "type": [
        "string",
        "null"
      ],
      "description": "Who wrote the last message, in a message's `sender` words: `customer`, `ai` or `user`; null before the first message. A broadcast or a `/v1/whatsapp` send changes `last_message` but not this."
    },
    "is_read": {
      "type": "boolean",
      "description": "Whether the team has read it. Mojeeb marks it unread when the customer writes."
    },
    "urgent": {
      "type": "boolean",
      "description": "Marked urgent, by the AI or a teammate. The AI reads it again with each of its replies."
    },
    "needs_attention": {
      "type": "boolean",
      "description": "The AI asked for a person to take over. The AI reads it again with each of its replies."
    },
    "sentiment": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1,
      "maximum": 5,
      "description": "The customer's mood as the AI reads it, from 1 (very negative) to 5 (very positive)."
    },
    "ai_enabled": {
      "type": "boolean",
      "description": "The conversation's AI switch (`ai_enabled` in `updateConversation`). The AI answers when it is on, `ai_paused_until` is null, and the AI is on for the channel's messages (`respond_to_messages` in `updateConnection`). The AI can also switch itself off when the agent's `ai_stop_enabled` is on; `listConversationAiSwitches` tells who switched it and why."
    },
    "ai_paused_until": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "The end of the pause a teammate's reply started; null when no pause is running."
    },
    "assigned_to": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "The teammate it is assigned to (a `user_id` from `listAgentMembers`)."
    },
    "latest_ad_id": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "The ad behind the customer's latest touch (a tap on it, or a private reply to a comment on its post), stored on the conversation itself, so it is on every response including a write's; read the ad with `getAd`. Null when the latest touch carried no ad. The same ad as `attribution.latest.ad.id` when that is set."
    },
    "attribution": {
      "oneOf": [
        {
          "$ref": "#/$defs/Attribution"
        },
        {
          "type": "null"
        }
      ],
      "description": "Where the customer came from: the latest touch and the origin (an ad tap, a post tap, a product tap, a link, the website chat plugin or a private reply to a comment). Null when nothing is known, and always null on the response to a write; read the resource for it."
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    }
  },
  "$defs": {
    "Attribution": {
      "type": "object",
      "description": "Where a customer came from. `origin` is the earliest touch, `latest` the most recent; they are the same object when there was only one. Each touch is an ad tap, a post tap, a product tap, a link, the website chat plugin or a private reply to a comment on the agent's post.",
      "required": [
        "latest",
        "origin"
      ],
      "properties": {
        "latest": {
          "oneOf": [
            {
              "$ref": "#/$defs/AttributionTouch"
            },
            {
              "type": "null"
            }
          ]
        },
        "origin": {
          "oneOf": [
            {
              "$ref": "#/$defs/AttributionTouch"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "AttributionAd": {
      "type": "object",
      "required": [
        "id",
        "meta_ad_id",
        "title",
        "media_type",
        "image_url"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "description": "Mojeeb's id for the ad."
        },
        "meta_ad_id": {
          "type": "string",
          "description": "The ad id as Ads Manager shows it."
        },
        "title": {
          "type": [
            "string",
            "null"
          ],
          "description": "The ad's headline as the tap carried it; null when Meta sent none."
        },
        "media_type": {
          "type": [
            "string",
            "null"
          ],
          "description": "`image` or `video`, when known."
        },
        "image_url": {
          "type": [
            "string",
            "null"
          ],
          "description": "The ad's image or video thumbnail, when known; a Meta CDN link that can expire."
        }
      }
    },
    "AttributionTouch": {
      "type": "object",
      "required": [
        "kind",
        "channel",
        "occurred_at",
        "ad"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "description": "`ad_tap`, `post_tap`, `product_tap`, `link`, `plugin` or `comment_reply`; new values may appear."
        },
        "channel": {
          "type": "string",
          "description": "`whatsapp`, `facebook` or `instagram`: where the touch happened."
        },
        "occurred_at": {
          "type": "string",
          "format": "date-time",
          "description": "When the customer tapped, as Meta reports it, or when the private reply was sent."
        },
        "ad": {
          "oneOf": [
            {
              "$ref": "#/$defs/AttributionAd"
            },
            {
              "type": "null"
            }
          ],
          "description": "The ad, for a tap on it or a private reply to a comment on its ad-only post (an Instagram ad's media or a Facebook dark post); null for a link, the chat plugin, and a comment reply on an organic or boosted post."
        }
      }
    }
  }
}