{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api-evangelist.com/schemas/phonely/phonely-post-call-event-schema.json",
  "title": "Phonely Post-Call Event",
  "description": "Schema for the JSON payload that Phonely POSTs to a customer-configured HTTPS webhook endpoint after a call completes (the Send Call Data post-call workflow action).",
  "type": "object",
  "required": [
    "callId",
    "callDirection",
    "callStarted",
    "callEnded",
    "duration",
    "businessPhoneNumber",
    "customerPhoneNumber"
  ],
  "properties": {
    "callId": {
      "type": "string",
      "description": "Unique identifier for the call."
    },
    "agentName": {
      "type": "string",
      "description": "Display name of the agent that handled the call."
    },
    "callerName": {
      "type": "string",
      "description": "Caller's name when known."
    },
    "callDirection": {
      "type": "string",
      "description": "Direction of the call.",
      "enum": ["inbound", "outbound"]
    },
    "callStarted": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp of when the call started."
    },
    "callEnded": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp of when the call ended."
    },
    "duration": {
      "type": "number",
      "description": "Call duration in seconds."
    },
    "businessPhoneNumber": {
      "type": "string",
      "description": "Business phone number assigned to the agent (E.164)."
    },
    "customerPhoneNumber": {
      "type": "string",
      "description": "Caller's phone number (E.164)."
    },
    "mentionedEmail": {
      "type": ["string", "null"],
      "description": "Email address mentioned during the call, if any."
    },
    "mentionedDate": {
      "type": ["string", "null"],
      "description": "Date mentioned during the call, if any."
    },
    "mentionedTime": {
      "type": ["string", "null"],
      "description": "Time mentioned during the call, if any."
    },
    "transcriptText": {
      "type": "string",
      "description": "Full text transcript of the call."
    },
    "transcript": {
      "type": "array",
      "description": "Structured transcript turns.",
      "items": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": {
            "type": "string",
            "enum": ["agent", "user"]
          },
          "content": {
            "type": "string"
          }
        }
      }
    },
    "summary": {
      "type": "string",
      "description": "Brief AI-generated summary of the call."
    },
    "longSummary": {
      "type": ["string", "null"],
      "description": "Detailed AI-generated summary of the call."
    },
    "purpose": {
      "type": "string",
      "description": "AI-extracted call objective."
    },
    "topic": {
      "type": "string",
      "description": "AI-extracted call topic / category."
    },
    "sentiment": {
      "type": "string",
      "description": "Overall sentiment of the call."
    },
    "keyPoints": {
      "type": "array",
      "description": "Highlighted insights from the call.",
      "items": { "type": "string" }
    },
    "unansweredQuestions": {
      "type": "array",
      "description": "Caller questions that were not resolved.",
      "items": { "type": "string" }
    },
    "actionItems": {
      "type": "array",
      "description": "Tasks generated by the call.",
      "items": { "type": "string" }
    },
    "followUp": {
      "type": "string",
      "description": "Follow-up indicator."
    },
    "followUpReason": {
      "type": "string",
      "description": "Reason a follow-up is needed."
    },
    "ai_success": {
      "type": "string",
      "description": "AI performance / success metric for the call."
    },
    "recordingUrl": {
      "type": "string",
      "format": "uri",
      "description": "HTTPS URL to the call recording."
    },
    "dashboardUrl": {
      "type": "string",
      "format": "uri",
      "description": "HTTPS URL to view this call in the Phonely dashboard."
    },
    "endedReason": {
      "type": "string",
      "description": "Reason the call ended (e.g. caller_hangup, agent_hangup, transfer)."
    }
  }
}
