{
  "openapi": "3.1.0",
  "info": {
    "title": "Spookat reply API",
    "version": "1",
    "description": "Read convos, reply as autopilot, add notes, hand off. The key picks the site. Writes need pro+."
  },
  "servers": [
    {
      "url": "https://api.spookat.com/v1"
    }
  ],
  "externalDocs": {
    "url": "https://spookat.com/docs/#05-reply-api"
  },
  "security": [
    {
      "key": []
    }
  ],
  "paths": {
    "/convos": {
      "get": {
        "summary": "list convos, latest activity first",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "closed",
                "waiting"
              ],
              "default": "open"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "convos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "convos": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Convo"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/convos/{ref}": {
      "get": {
        "summary": "the visitor, every message and note",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(?:[Ss][Pp]-)?[0-9A-Fa-f]{1,12}$"
            },
            "example": "SP-0001"
          }
        ],
        "responses": {
          "200": {
            "description": "the convo",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Convo"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "warnings": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 5,
                          "description": "the site's autopilot setting: how many warnings a visitor who messes around gets before end"
                        },
                        "messages": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Message"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "delete for good. admin key. fires convo.purged",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(?:[Ss][Pp]-)?[0-9A-Fa-f]{1,12}$"
            },
            "example": "SP-0001"
          }
        ],
        "responses": {
          "200": {
            "description": "gone",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ref": {
                      "type": "string"
                    },
                    "deleted": {
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/convos/{ref}/messages": {
      "post": {
        "summary": "reply as autopilot",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(?:[Ss][Pp]-)?[0-9A-Fa-f]{1,12}$"
            },
            "example": "SP-0001"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4000
                  },
                  "as": {
                    "const": "autopilot"
                  },
                  "after": {
                    "type": "integer",
                    "description": "the last visitor message you're answering: 409 answered if someone replied since"
                  }
                },
                "required": [
                  "text"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "sent (draft: true = landed as a note for the team)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "$ref": "#/components/schemas/Message"
                    },
                    "draft": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/convos/{ref}/messages/{messageId}": {
      "delete": {
        "summary": "delete a message this key sent. the visitor stops seeing it; an email that already went out stays out",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(?:[Ss][Pp]-)?[0-9A-Fa-f]{1,12}$"
            },
            "example": "SP-0001"
          },
          {
            "name": "messageId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "gone",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ref": {
                      "type": "string"
                    },
                    "message": {
                      "type": "integer"
                    },
                    "deleted": {
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/convos/{ref}/notes": {
      "post": {
        "summary": "internal note, the visitor never sees it",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(?:[Ss][Pp]-)?[0-9A-Fa-f]{1,12}$"
            },
            "example": "SP-0001"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4000
                  }
                },
                "required": [
                  "text"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "added",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "$ref": "#/components/schemas/Message"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/convos/{ref}/handoff": {
      "post": {
        "summary": "step back and ping the team",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(?:[Ss][Pp]-)?[0-9A-Fa-f]{1,12}$"
            },
            "example": "SP-0001"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "the convo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Convo"
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/convos/{ref}/end": {
      "post": {
        "summary": "end a convo autopilot answers: closed, autopilot off for it, the reason lands as a quiet note for the team, nobody pinged. the widget says the assistant left and offers the visitor a new chat",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(?:[Ss][Pp]-)?[0-9A-Fa-f]{1,12}$"
            },
            "example": "SP-0001"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "the convo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Convo"
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/convos/{ref}/assign": {
      "post": {
        "summary": "assign to a teammate by name. admin key. 409 when two teammates go by that name",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(?:[Ss][Pp]-)?[0-9A-Fa-f]{1,12}$"
            },
            "example": "SP-0001"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "assignee": {
                    "type": "string",
                    "maxLength": 100
                  }
                },
                "required": [
                  "assignee"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "the convo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Convo"
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/convos/{ref}/close": {
      "post": {
        "summary": "close. admin key",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(?:[Ss][Pp]-)?[0-9A-Fa-f]{1,12}$"
            },
            "example": "SP-0001"
          }
        ],
        "responses": {
          "200": {
            "description": "the convo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Convo"
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/export": {
      "get": {
        "summary": "everything for the site, no secrets. admin key",
        "responses": {
          "200": {
            "description": "the export",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "a bad body: bad_request, too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "no key, or a revoked one: unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "the plan: plan_required (no api without a plan, writes need pro+). held and over_limit only happen without a plan, so /v1 never answers them: it says plan_required first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden_scope (needs an admin key; a pre-claim key reads nothing), forbidden_author (as isn't autopilot, or a visitor's message), forbidden_role (a message this key didn't send)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: no such convo or message on this site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "reply refused: stepped_back, closed, autopilot_off, working_hours, too_early (retryAfter), answered. assign: ambiguous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body over 1 MB"
          },
          "429": {
            "description": "rate: 60 burst, 10 a second per key (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "our bug",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "error. the code says which, see the docs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "key": {
        "type": "http",
        "scheme": "bearer",
        "description": "sk_live_… from https://app.spookat.com. agent or admin scope"
      }
    },
    "schemas": {
      "Convo": {
        "type": "object",
        "properties": {
          "ref": {
            "type": "string",
            "example": "SP-0001"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "closed"
            ]
          },
          "assignee": {
            "type": [
              "string",
              "null"
            ]
          },
          "autopilot": {
            "type": "boolean"
          },
          "flag": {
            "type": [
              "string",
              "null"
            ]
          },
          "visitor": {
            "type": "object",
            "properties": {
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "nick": {
                "type": "string",
                "description": "what the team calls them in the inbox, Slack and Discord (sleepy otter), unique on the site"
              },
              "email": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "userId": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "createdAt": {
            "type": "integer",
            "description": "ms since epoch"
          },
          "lastMessageAt": {
            "type": "integer",
            "description": "ms since epoch"
          },
          "unanswered": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            },
            "description": "status=waiting only"
          },
          "more": {
            "type": "boolean",
            "description": "status=waiting only: older unanswered messages exist, read the convo"
          }
        }
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "author": {
            "type": "string",
            "enum": [
              "visitor",
              "human",
              "autopilot"
            ]
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "kind": {
            "type": "string",
            "enum": [
              "msg",
              "note"
            ]
          },
          "text": {
            "type": "string"
          },
          "at": {
            "type": "integer",
            "description": "ms since epoch"
          },
          "editedAt": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ms since epoch, set when a teammate edited it"
          },
          "translation": {
            "type": "object",
            "description": "live translation, coming soon: absent until then. Later (agency, when the site has it on): a visitor message in the team's language, or a team message as the visitor got it. text stays the original",
            "properties": {
              "lang": {
                "type": "string",
                "description": "translated into"
              },
              "from": {
                "type": "string",
                "description": "visitor messages: the language it was written in"
              },
              "text": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "null: not translated (same language, or the model failed and the original went out)"
              },
              "error": {
                "type": "string",
                "enum": [
                  "timeout",
                  "failed"
                ]
              }
            }
          },
          "ctx": {
            "type": "object",
            "description": "visitor messages only: where they were when they sent it",
            "properties": {
              "url": {
                "type": "string"
              },
              "referrer": {
                "type": "string"
              },
              "lang": {
                "type": "string"
              },
              "tz": {
                "type": "string"
              },
              "localTime": {
                "type": "string"
              },
              "browser": {
                "type": "string"
              },
              "country": {
                "type": "string"
              },
              "locale": {
                "type": "string"
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error",
          "code"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "a sentence to act on"
          },
          "code": {
            "type": "string",
            "enum": [
              "bad_request",
              "too_long",
              "unauthorized",
              "plan_required",
              "held",
              "over_limit",
              "forbidden_scope",
              "forbidden_author",
              "forbidden_role",
              "not_found",
              "stepped_back",
              "closed",
              "autopilot_off",
              "working_hours",
              "too_early",
              "answered",
              "ambiguous",
              "rate"
            ],
            "example": "not_found"
          },
          "retryAfter": {
            "type": "integer",
            "description": "too_early: seconds to wait (the Retry-After header too)"
          }
        }
      }
    }
  }
}