{
  "$id": "https://intentschema.org/intents/communication/email/message/reply/v1.json",
  "fqdn": "org.intentschema.communication.email.message.reply.v1",
  "title": "Reply to email message",
  "description": "Sends a reply to an existing email message or thread. The target's external_id identifies the message being replied to.",
  "payload": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "required": [
      "target",
      "object"
    ],
    "properties": {
      "target": {
        "allOf": [
          {
            "$ref": "https://intentschema.org/common/target/v1.json"
          },
          {
            "required": [
              "external_id"
            ]
          }
        ]
      },
      "object": {
        "type": "object",
        "required": [
          "textBody"
        ],
        "properties": {
          "to": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "email",
              "description": "RFC 5321 mailbox. Plain address (jane@example.com) or with display name (\"Jane Doe\" <jane@example.com>)."
            }
          },
          "cc": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "email",
              "description": "RFC 5321 mailbox. Plain address (jane@example.com) or with display name (\"Jane Doe\" <jane@example.com>)."
            }
          },
          "bcc": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "email",
              "description": "RFC 5321 mailbox. Plain address (jane@example.com) or with display name (\"Jane Doe\" <jane@example.com>)."
            }
          },
          "subject": {
            "type": "string",
            "description": "Optional; defaults to Re: <original subject> if omitted."
          },
          "textBody": {
            "type": "string"
          },
          "htmlBody": {
            "type": "string"
          },
          "attachments": {
            "type": "array",
            "items": {
              "$ref": "https://intentschema.org/common/blob-ref/v1.json"
            }
          },
          "replyAll": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "idempotency_key": {
        "type": "string"
      }
    }
  },
  "result": {
    "type": "object",
    "required": [
      "external_id",
      "thread_id",
      "sent_at"
    ],
    "properties": {
      "external_id": {
        "type": "string"
      },
      "thread_id": {
        "type": "string"
      },
      "sent_at": {
        "type": "string",
        "format": "date-time"
      }
    }
  },
  "examples": [
    {
      "name": "reply to a thread",
      "value": {
        "target": {
          "system": "gmail",
          "external_id": "msg_abc123"
        },
        "object": {
          "textBody": "Thanks, got it."
        }
      }
    },
    {
      "name": "reply-all with explicit recipients",
      "value": {
        "target": {
          "system": "gmail",
          "external_id": "msg_abc123"
        },
        "object": {
          "to": [
            "jane@example.com"
          ],
          "cc": [
            "alice@example.com"
          ],
          "subject": "Re: Checking in",
          "textBody": "Looping in Alice.",
          "replyAll": true
        }
      }
    }
  ]
}
