{
  "openapi": "3.0.3",
  "info": {
    "title": "Pulse Bot API",
    "version": "1.0.0",
    "description": "The four current-source public bot operations for basic text messages and channel discovery. Use the hosted app API origin or replace the server URL for self-hosting. This specification describes route behavior and configurable defaults rather than guaranteeing a particular deployed release. Rich app message blocks, bot credential administration, app-platform APIs, incoming webhooks, and user/PAT APIs are outside its scope."
  },
  "servers": [
    {
      "url": "https://app.pulsechat.ru",
      "description": "Pulse hosted app API origin. Replace with your installation origin for self-hosting."
    }
  ],
  "tags": [
    {
      "name": "Messages",
      "description": "Basic bot text sends and mutations."
    },
    {
      "name": "Channels",
      "description": "Channel discovery."
    }
  ],
  "paths": {
    "/api/v1/bots/messages": {
      "post": {
        "tags": [
          "Messages"
        ],
        "operationId": "createBotMessage",
        "summary": "Create a basic bot message or thread reply",
        "description": "Requires chat:write, or chat:write:thread when parent_id is present. The bot must retain workspace access and channel membership. Channels must permit posting and must not be archived or read-only. Plaintext access to server-managed encrypted and E2EE channels is rejected. Send a channel name in the channel field. Idempotency records are scoped to the credential and route and expire after 24 hours. Keep the same credential, key, and normalized channel/text/parent payload for retries. Reuse after expiry or token rotation can create another message. Idempotency is implemented only for this creation operation in this specification.",
        "security": [
          {
            "BotToken": []
          },
          {
            "InstallationToken": []
          }
        ],
        "x-required-scopes": {
          "either": [
            "chat:write",
            "chat:write:thread with parent_id"
          ]
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Optional retry key. Trimmed before validation. Non-empty header takes precedence over idempotency_key in the body. Non-empty values contain 1–120 ASCII characters, starting with a letter or digit and continuing with letters, digits, -, _, ., or :. Empty means no header key. Retention is 24 hours.",
            "schema": {
              "type": "string"
            },
            "example": "deploy-build-1042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PostMessageRequest"
              },
              "example": {
                "channel": "general",
                "text": "Build 1042 deployed"
              }
            }
          }
        },
        "responses": {
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          },
          "201": {
            "description": "Created message object. A completed idempotency replay returns the stored creation status and response.",
            "headers": {
              "Idempotency-Replayed": {
                "description": "Present with value true when the stored response is replayed.",
                "schema": {
                  "type": "string",
                  "enum": [
                    "true"
                  ]
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "Channel name is ambiguous, idempotency_key_conflict for a retained key with a different normalized payload, or idempotency_key_in_progress for a request that cannot yet be safely resumed. Wait briefly before retrying an in-progress request unchanged.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "conflict": {
                    "value": {
                      "error": "idempotency_key_conflict"
                    }
                  },
                  "inProgress": {
                    "value": {
                      "error": "idempotency_key_in_progress"
                    }
                  },
                  "ambiguousChannel": {
                    "value": {
                      "error": "Channel name is ambiguous"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/bots/messages/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "UUID of a message authored by this credential’s bot account in its workspace.",
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "patch": {
        "tags": [
          "Messages"
        ],
        "operationId": "updateBotMessage",
        "summary": "Update the bot’s own message text",
        "description": "Requires chat:write for a bot token or chat:update for an installation token. The message must belong to this bot in this workspace and be within 24 hours of creation. Deleted messages cannot be updated. The bot must retain workspace access and channel membership. Channels must permit posting and must not be archived or read-only. Plaintext access to server-managed encrypted and E2EE channels is rejected. This operation does not implement the creation Idempotency-Key contract.",
        "security": [
          {
            "BotToken": []
          },
          {
            "InstallationToken": []
          }
        ],
        "x-required-scopes": {
          "BotToken": [
            "chat:write"
          ],
          "InstallationToken": [
            "chat:update"
          ]
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateMessageRequest"
              }
            }
          }
        },
        "responses": {
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          },
          "200": {
            "description": "Message object after the mutation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Messages"
        ],
        "operationId": "deleteBotMessage",
        "summary": "Delete the bot’s own message",
        "description": "Requires chat:write for a bot token or chat:delete for an installation token. The message must belong to this bot in this workspace and be within 24 hours of creation. The bot must retain workspace access and channel membership. Channels must permit posting and must not be archived or read-only. Plaintext access to server-managed encrypted and E2EE channels is rejected. A successful delete returns a message with type deleted. An already-deleted message is returned again when ownership, workspace, encryption, age, and scope checks pass. Current posting access is checked when deleting an existing message. This operation does not implement the creation Idempotency-Key contract.",
        "security": [
          {
            "BotToken": []
          },
          {
            "InstallationToken": []
          }
        ],
        "x-required-scopes": {
          "BotToken": [
            "chat:write"
          ],
          "InstallationToken": [
            "chat:delete"
          ]
        },
        "responses": {
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          },
          "200": {
            "description": "Message object after the mutation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/v1/bots/channels": {
      "get": {
        "tags": [
          "Channels"
        ],
        "operationId": "listBotChannels",
        "summary": "List channels visible to the bot",
        "description": "Requires channels:read for either token family. Returns unarchived public channels plus channels the bot has joined in its workspace, ordered newest first by creation time and UUID. Discovery does not grant posting access and may include direct conversations even though createBotMessage resolves only non-direct channels. Continue with the opaque next_cursor until it is null.",
        "security": [
          {
            "BotToken": []
          },
          {
            "InstallationToken": []
          }
        ],
        "x-required-scopes": {
          "BotToken": [
            "channels:read"
          ],
          "InstallationToken": [
            "channels:read"
          ]
        },
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Default 50. Zero selects the default. Values over 200 are capped at 200. Negative or malformed values return 400.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Exact next_cursor from the preceding response. Invalid cursors return 400.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          },
          "200": {
            "description": "Channel page.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChannelPage"
                },
                "example": {
                  "items": [
                    {
                      "id": "22b2c3d4-e5f6-4789-abcd-012345678901",
                      "name": "general",
                      "type": "public"
                    }
                  ],
                  "next_cursor": null
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BotToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "xoxb- token",
        "description": "A workspace bot token starting with xoxb-. Send Authorization: Bearer <token>. Bot middleware also accepts the Bot authorization scheme. Tokens must be active, unexpired, and unrevoked. Each operation also checks scopes and resource access. Workspace user sessions and personal access tokens do not authenticate these bot endpoints."
      },
      "InstallationToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "xoxa- token",
        "description": "An app installation token starting with xoxa-. Send Authorization: Bearer <token>. The installation must be active and have a bot account. Effective scopes are restricted by both token scopes and installation grants. Updates require chat:update and deletes require chat:delete. Workspace user sessions and personal access tokens do not authenticate these bot endpoints."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Diagnostic text. Handle errors primarily by HTTP status."
          },
          "error_code": {
            "type": "string",
            "description": "Optional structured application error code."
          }
        },
        "additionalProperties": true
      },
      "Message": {
        "type": "object",
        "description": "Stable message fields returned directly, without a response envelope. Additional message, sender, and rich-content fields may be present.",
        "required": [
          "id",
          "created_at",
          "updated_at",
          "channel_id",
          "user_id",
          "content",
          "content_format",
          "type",
          "parent_id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Message identifier. Retain it for replies, updates, or deletion."
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Creation timestamp."
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "Last update timestamp."
          },
          "channel_id": {
            "type": "string",
            "format": "uuid",
            "description": "Resolved channel UUID."
          },
          "user_id": {
            "type": "string",
            "format": "uuid",
            "description": "Sender bot account UUID."
          },
          "content": {
            "type": "string",
            "description": "Message text. The create and update request field is named text. A deletion marker may contain empty content."
          },
          "content_format": {
            "type": "string",
            "description": "Message content representation. New bot sends use pulse_rich_text_v1. Other formats can occur in pre-existing messages."
          },
          "type": {
            "type": "string",
            "description": "Message type. Typical values are text for a basic send and deleted for a deletion marker."
          },
          "parent_id": {
            "type": "string",
            "format": "uuid",
            "nullable": true,
            "description": "Root message UUID for a thread reply, or null for a top-level message."
          }
        },
        "additionalProperties": true
      },
      "PostMessageRequest": {
        "type": "object",
        "description": "Basic text message creation. This specification documents basic send fields only. The runtime also supports app-token blocks, whose rich-content schema is outside this specification. Additional runtime fields are not described here.",
        "required": [
          "channel",
          "text"
        ],
        "properties": {
          "channel": {
            "type": "string",
            "description": "Channel NAME in the credential’s workspace, not a UUID. Surrounding whitespace, a leading #, and letter case are normalized. The resolved channel must be non-direct and unarchived. An ambiguous name returns 409.",
            "example": "general"
          },
          "text": {
            "type": "string",
            "description": "Required non-empty text after trimming surrounding whitespace.",
            "example": "Build 1042 deployed"
          },
          "parent_id": {
            "type": "string",
            "format": "uuid",
            "description": "Optional root message in the same channel. Replies to thread replies are rejected. Required when chat:write:thread is the only write scope."
          },
          "idempotency_key": {
            "type": "string",
            "description": "Optional creation retry key. Surrounding whitespace is trimmed. An empty value means no key. A non-empty Idempotency-Key header takes precedence. Records are scoped to credential and route for 24 hours. Non-empty keys must match ^[A-Za-z0-9][A-Za-z0-9_.:-]{0,119}$.",
            "example": "deploy-build-1042"
          }
        },
        "additionalProperties": true
      },
      "UpdateMessageRequest": {
        "type": "object",
        "required": [
          "text"
        ],
        "properties": {
          "text": {
            "type": "string",
            "description": "Required non-empty replacement text after trimming surrounding whitespace.",
            "example": "Build 1042 is healthy"
          }
        },
        "additionalProperties": true
      },
      "Channel": {
        "type": "object",
        "required": [
          "id",
          "name",
          "type"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "description": "Channel name. Pass this value in channel when creating a message."
          },
          "type": {
            "type": "string",
            "description": "Channel type as stored by Pulse, for example public, private, or direct."
          }
        },
        "additionalProperties": true
      },
      "ChannelPage": {
        "type": "object",
        "required": [
          "items",
          "next_cursor"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Channel"
            }
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Opaque continuation cursor, or null when no further page is available."
          }
        },
        "additionalProperties": true
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid JSON, missing or invalid fields, an invalid parent, unsupported pagination, or an invalid idempotency key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, malformed, unknown, revoked, or expired token, or an inactive app installation.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Required scope, workspace or channel access is missing, channel encryption prevents plaintext access, or the 24-hour mutation window has expired.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "The channel could not be resolved or the message is unavailable within this bot’s ownership and workspace.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Token or workspace request budget exceeded. Defaults are 120 requests per token and 600 requests per workspace in a fixed 60-second window. Operators can configure these values. Wait for Retry-After before retrying.",
        "headers": {
          "Retry-After": {
            "description": "Seconds until the current rate-limit window ends.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Bot rate limit exceeded"
            }
          }
        }
      },
      "ServerError": {
        "description": "The server could not complete the request. For uncertain message creation results, retry with the same credential, idempotency key, and payload.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
