{
 "openapi": "3.1.0",
 "info": {
  "title": "Toki Bot API",
  "version": "1",
  "description": "HTTP API for Toki bots and the server side of their web apps.\n\n- Authenticate with `Authorization: Bearer <bot token>`.\n- Every update goes to one ordered log per bot. Read it by cursor with `GET /updates` (add `timeout` to wait for new ones) or receive the same pages on a signed webhook. Both can be used at once; anything a webhook missed is still readable by cursor for 30 days.\n- `POST /messages` is idempotent by `client_id`: a retry returns the message created the first time.\n- Text is plain. Formatting travels next to it as `entities`: ranges counted in UTF-16 code units, the unit of string indexes in JavaScript, Java, Kotlin, Swift's `NSString` and C#. In Python, Go, Rust or PHP count a character above U+FFFF (most emoji) as two.\n- A photo, document, audio track or video is uploaded once with `POST /files` and sent by its `id` as `file_id`. What a person sends arrives in the `files` of a `message` update with a download link that lives 10 minutes.\n- A `callback` update may be answered with `POST /updates/{id}/answer` within 10 seconds: the person sees the text as a short notice, or just stops waiting.\n- Errors are `{ok:false,error:{code,message}}`. React to `code`; `message` is English text for logs.\n- Limits are counted per bot ID and survive token rotation. A `429` carries `Retry-After` in seconds.\n- Skip update types and fields you do not know: both lists will grow."
 },
 "servers": [
  {
   "url": "https://toki.biz/api/bot/v1"
  }
 ],
 "security": [
  {
   "botToken": []
  }
 ],
 "paths": {
  "/me": {
   "get": {
    "operationId": "getMe",
    "summary": "The bot's profile, settings and webhook state",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Bot"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "operationId": "updateSettings",
    "summary": "Choose which update types the bot receives",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "update_types"
        ],
        "properties": {
         "update_types": {
          "type": [
           "array",
           "null"
          ],
          "items": {
           "type": "string",
           "enum": [
            "message",
            "message_edited",
            "callback",
            "blocked",
            "unblocked"
           ]
          },
          "description": "null turns every type on."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "update_types": {
           "type": "array",
           "items": {
            "type": "string",
            "enum": [
             "message",
             "message_edited",
             "callback",
             "blocked",
             "unblocked"
            ]
           }
          }
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Invalid"
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/updates": {
   "get": {
    "operationId": "getUpdates",
    "summary": "A page of updates after a cursor",
    "parameters": [
     {
      "name": "after",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 0,
       "default": 0
      },
      "description": "`next_cursor` of the previous page."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 50
      }
     },
     {
      "name": "timeout",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 0,
       "maximum": 25,
       "default": 0
      },
      "description": "Seconds to wait when there is nothing new. One request per bot waits: a newer one takes the wait over and the older answers 409 `poll_conflict`."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/UpdatesPage"
        }
       }
      },
      "headers": {
       "Retry-After": {
        "schema": {
         "type": "integer"
        },
        "description": "Present on an empty page that was answered at once because no waiting place was free. Pause for this many seconds before the next request."
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Invalid"
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "409": {
      "description": "`poll_conflict`: another request with this token took over the wait. Run one poller per bot token.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/updates/{id}/answer": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "integer"
     },
     "description": "`id` of a `callback` update."
    }
   ],
   "post": {
    "operationId": "answerCallback",
    "summary": "Answer a button press",
    "description": "Ends the wait on the button the person pressed and, with `text`, shows it to that person as a short notice. Send it before `answer_until` of the update. The first answer is final: a repeat returns the same success and changes nothing, so an update delivered twice is safe to answer twice.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "text": {
          "type": [
           "string",
           "null"
          ],
          "maxLength": 200,
          "description": "Plain text for the notice. Leave it out to answer without one."
         }
        }
       },
       "example": {
        "text": "Added to the cart"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "answered"
         ],
         "properties": {
          "answered": {
           "const": true
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "`update_not_found`: not a `callback` update of this bot. `chat_unavailable`: the person removed the chat or blocked the bot.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "`answer_expired`: `answer_until` has passed and the person no longer waits.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Invalid"
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/messages": {
   "post": {
    "operationId": "sendMessage",
    "summary": "Send text or one media attachment to a chat a person has started",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/NewMessage"
       },
       "examples": {
        "text": {
         "summary": "Text with formatting and buttons",
         "value": {
          "chat_id": 9001,
          "client_id": "reply-51244",
          "text": "Order 15 is ready 🎉\nPickup code: A7K2",
          "entities": [
           {
            "type": "bold",
            "offset": 0,
            "length": 8
           },
           {
            "type": "code",
            "offset": 33,
            "length": 4
           }
          ],
          "buttons": [
           [
            {
             "text": "Pay",
             "web_app": {
              "start_param": "order-15"
             }
            }
           ],
           [
            {
             "text": "Cancel",
             "callback_data": "cancel:15"
            },
            {
             "text": "Site",
             "url": "https://shop.example/o/15"
            }
           ]
          ]
         }
        },
        "photo": {
         "summary": "A photo with a caption",
         "value": {
          "chat_id": 9001,
          "client_id": "card-15",
          "file_id": 4410,
          "text": "Green tea, 450"
         }
        },
        "audio": {
         "summary": "A track with a caption",
         "value": {
          "chat_id": 41,
          "client_id": "track-812",
          "file_id": 4410,
          "text": "Night Walk"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/MessageRef"
        }
       }
      }
     },
     "404": {
      "description": "`chat_unavailable`: the person has not started this chat, removed it or blocked the bot. `file_not_found`: `file_id` is not this bot's upload.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "This `client_id` was already used in another chat.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Invalid"
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/messages/{id}": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "integer"
     }
    }
   ],
   "patch": {
    "operationId": "editMessage",
    "summary": "Change the text, its formatting, the file, the buttons or several of them",
    "description": "Meant for streaming too: edit one message as an answer grows (up to 5 edits a second per message). Edited bot messages carry no \"edited\" mark. Every field left out stays as it is, except that a new `text` without `entities` drops the old formatting.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "minProperties": 1,
        "properties": {
         "text": {
          "type": [
           "string",
           "null"
          ],
          "maxLength": 4096,
          "description": "A text message cannot lose its text; a caption can: null or an empty string removes it."
         },
         "entities": {
          "type": [
           "array",
           "null"
          ],
          "maxItems": 100,
          "items": {
           "$ref": "#/components/schemas/Entity"
          },
          "description": "Formatting of the text the message has after this edit. null or [] removes it."
         },
         "file_id": {
          "type": "integer",
          "description": "A replacement upload of the same kind as the current attachment."
         },
         "buttons": {
          "type": [
           "array",
           "null"
          ],
          "maxItems": 8,
          "items": {
           "type": "array",
           "minItems": 1,
           "maxItems": 4,
           "items": {
            "$ref": "#/components/schemas/Button"
           }
          },
          "description": "null or [] removes the buttons."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/MessageRef"
        }
       }
      }
     },
     "404": {
      "description": "`message_not_found`: not the bot's message, or it is deleted. `file_not_found`: `file_id` is not this bot's upload.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Invalid"
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "operationId": "deleteMessage",
    "summary": "Delete the bot's own message for both sides",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "deleted": {
           "const": true
          }
         }
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/files": {
   "post": {
    "operationId": "uploadFile",
    "summary": "Upload a photo, document, audio track or video",
    "description": "Returns an `id` for `file_id` of a message. A photo is JPEG, PNG, WebP or GIF up to 10 MB and 40 megapixels; it is shown in the chat as a picture, stored without camera metadata and with the long side up to 2560. A file is any non-empty file up to 50 MB, kept byte for byte and shown as a document with its name. Audio and video accept up to 50 MiB and 600 seconds. MP3 audio is delivered as MP3. Other supported audio inputs are prepared as AAC/M4A. A real video stream is converted to H.264 MP4 with a poster. An upload no message carries is removed after 24 hours. Up to 20 uploads a minute, with two files processing concurrently per bot. The default daily input budget is 2 GiB and resets at server midnight. Reuse an existing file_id without consuming upload bytes. A 429 includes Retry-After.",
    "requestBody": {
     "required": true,
     "content": {
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "required": [
         "file",
         "kind"
        ],
        "properties": {
         "file": {
          "type": "string",
          "format": "binary"
         },
         "kind": {
          "enum": [
           "photo",
           "file",
           "audio",
           "video"
          ]
         },
         "title": {
          "type": "string",
          "maxLength": 128,
          "description": "Audio only. Track title; defaults to the embedded title or file name."
         },
         "performer": {
          "type": "string",
          "maxLength": 128,
          "description": "Audio only. Performer; defaults to the embedded artist if available."
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Stored",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/File"
        }
       }
      }
     },
     "413": {
      "description": "`file_too_large`",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "`invalid_file`: not a picture for `photo`, or a kind of file Toki does not store. `validation_failed`: a field is missing.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/files/{id}": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "integer"
     }
    }
   ],
   "get": {
    "operationId": "getFile",
    "summary": "A file with a fresh download link",
    "description": "For the bot's own uploads and for files of messages people sent to the bot, while the bot can read the message: a removed message, a removed chat or a block closes the file.",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/FileLink"
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/FileNotFound"
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/chats/{chat_id}/typing": {
   "post": {
    "operationId": "sendTyping",
    "summary": "Show \"typing\" in the chat for 7 seconds",
    "parameters": [
     {
      "name": "chat_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "updated": {
           "const": true
          }
         }
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/ChatUnavailable"
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/commands": {
   "put": {
    "operationId": "setCommands",
    "summary": "Replace the command menu",
    "description": "Without `lang` this is the default list; with `lang` the list people with that language see. An empty array removes the list.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "commands"
        ],
        "properties": {
         "lang": {
          "type": [
           "string",
           "null"
          ],
          "enum": [
           "ru",
           "en",
           null
          ]
         },
         "commands": {
          "type": "array",
          "maxItems": 30,
          "items": {
           "$ref": "#/components/schemas/Command"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "commands": {
           "type": "object",
           "additionalProperties": {
            "type": "array",
            "items": {
             "$ref": "#/components/schemas/Command"
            }
           },
           "description": "Lists by scope: default, ru, en."
          }
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Invalid"
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/webhook": {
   "put": {
    "operationId": "setWebhook",
    "summary": "Deliver updates to an HTTPS endpoint",
    "description": "Returns the signing secret once. A second call issues a new one. By default, delivery starts with new updates. Pass your last processed cursor to resume from that point.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "url"
        ],
        "properties": {
         "url": {
          "type": "string",
          "format": "uri",
          "maxLength": 1024,
          "description": "https, a public host name, the default port."
         },
         "after": {
          "type": "integer",
          "minimum": 0,
          "description": "Last processed cursor, at most last_update_id. Starts delivery with the next retained update."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "url",
          "secret"
         ],
         "properties": {
          "url": {
           "type": "string"
          },
          "secret": {
           "type": "string",
           "description": "toki_whsec_…"
          }
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Invalid"
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "operationId": "deleteWebhook",
    "summary": "Stop webhook delivery",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "deleted": {
           "const": true
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/InvalidToken"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/webapp/session": {
   "post": {
    "operationId": "exchangeWebAppLaunch",
    "summary": "Exchange web app launch data for the person who opened it",
    "description": "Call it from the web app's own server with the string the page read from `Toki.WebApp.initData`. Launch data works once and for 120 seconds, so there is nothing to verify or store on your side.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "initData"
        ],
        "properties": {
         "initData": {
          "type": "string",
          "maxLength": 4096
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/WebAppSession"
        }
       }
      }
     },
     "401": {
      "description": "`invalid_token`, or `invalid_launch`: the data is invalid, expired or already used.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/ChatUnavailable"
     },
     "422": {
      "$ref": "#/components/responses/Invalid"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  }
 },
 "webhooks": {
  "updates": {
   "post": {
    "operationId": "receiveUpdates",
    "summary": "What Toki sends to the webhook URL",
    "description": "The body is the same page `GET /updates` returns. Verify `Toki-Signature: t=<unix>,v1=<hex>`: v1 is HMAC-SHA256 of `<t>.<raw body>` with the webhook secret; reject a `t` older than 5 minutes. Answer 2xx within 8 seconds. Delivery failures retry from the last acknowledged cursor after 5 s, 15 s, 1 min, 5 min, 15 min, 30 min, then hourly. The batch can include newer events on retry. 410 or a day of failures switches the webhook off. Handle an update ID twice without harm.",
    "security": [],
    "parameters": [
     {
      "name": "Toki-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "Toki-Bot-Id",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/UpdatesPage"
       }
      }
     }
    },
    "responses": {
     "2XX": {
      "description": "The page is accepted."
     },
     "410": {
      "description": "Switch this webhook off."
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "botToken": {
    "type": "http",
    "scheme": "bearer",
    "description": "`toki_bot_…` from \"My bots\" in the Toki app. Replacing the token there revokes the old one."
   }
  },
  "responses": {
   "InvalidToken": {
    "description": "`invalid_token`",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "RateLimited": {
    "description": "`rate_limited`",
    "headers": {
     "Retry-After": {
      "schema": {
       "type": "integer"
      },
      "description": "Seconds to wait."
     }
    },
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "ChatUnavailable": {
    "description": "`chat_unavailable`: the person has not started this chat, removed it or blocked the bot.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "NotFound": {
    "description": "`message_not_found`: not the bot's message, or it is deleted.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "Invalid": {
    "description": "`validation_failed` (with `fields`), `invalid_buttons`, `invalid_entities`, `invalid_file`, `invalid_webhook_url` or `nothing_to_change`.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "FileNotFound": {
    "description": "`file_not_found`: not this bot's upload and not a file of a message the bot can read now.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "required": [
     "ok",
     "error"
    ],
    "properties": {
     "ok": {
      "const": false
     },
     "error": {
      "type": "object",
      "required": [
       "code",
       "message"
      ],
      "properties": {
       "code": {
        "type": "string",
        "examples": [
         "invalid_token",
         "chat_unavailable",
         "message_not_found",
         "invalid_buttons",
         "invalid_entities",
         "invalid_file",
         "file_too_large",
         "file_not_found",
         "update_not_found",
         "answer_expired",
         "invalid_webhook_url",
         "nothing_to_change",
         "validation_failed",
         "invalid_launch",
         "rate_limited",
         "poll_conflict"
        ]
       },
       "message": {
        "type": "string"
       },
       "fields": {
        "type": "object",
        "additionalProperties": {
         "type": "array",
         "items": {
          "type": "string"
         }
        }
       }
      }
     }
    }
   },
   "User": {
    "type": "object",
    "required": [
     "id",
     "name",
     "username",
     "lang"
    ],
    "properties": {
     "id": {
      "type": "integer",
      "description": "Stable Toki ID of the person. Use it as the key; name and username can change."
     },
     "name": {
      "type": "string"
     },
     "username": {
      "type": [
       "string",
       "null"
      ]
     },
     "lang": {
      "type": "string",
      "enum": [
       "ru",
       "en"
      ]
     }
    }
   },
   "Button": {
    "type": "object",
    "required": [
     "text"
    ],
    "description": "Exactly one of callback_data, url, web_app.",
    "properties": {
     "text": {
      "type": "string",
      "maxLength": 32
     },
     "callback_data": {
      "type": "string",
      "maxLength": 256,
      "description": "Comes back in the `callback` update. It never reaches the client app, so a person cannot forge it."
     },
     "url": {
      "type": "string",
      "format": "uri",
      "maxLength": 1024,
      "description": "https only. Toki asks the person before leaving."
     },
     "web_app": {
      "type": "object",
      "properties": {
       "start_param": {
        "type": "string",
        "maxLength": 64,
        "pattern": "^[A-Za-z0-9_-]+$"
       }
      },
      "description": "Opens the bot's web app. Needs a web app URL in the bot's settings."
     }
    },
    "oneOf": [
     {
      "required": [
       "callback_data"
      ]
     },
     {
      "required": [
       "url"
      ]
     },
     {
      "required": [
       "web_app"
      ]
     }
    ]
   },
   "Command": {
    "type": "object",
    "required": [
     "command",
     "description"
    ],
    "properties": {
     "command": {
      "type": "string",
      "pattern": "^[a-z0-9_]{1,32}$"
     },
     "description": {
      "type": "string",
      "maxLength": 64
     }
    }
   },
   "Bot": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer"
     },
     "username": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "short_description": {
      "type": [
       "string",
       "null"
      ]
     },
     "description": {
      "type": [
       "string",
       "null"
      ]
     },
     "avatar_url": {
      "type": [
       "string",
       "null"
      ]
     },
     "web_app_url": {
      "type": [
       "string",
       "null"
      ]
     },
     "web_app_label": {
      "type": [
       "string",
       "null"
      ]
     },
     "commands": {
      "type": "object",
      "additionalProperties": {
       "type": "array",
       "items": {
        "$ref": "#/components/schemas/Command"
       }
      }
     },
     "update_types": {
      "type": "array",
      "items": {
       "type": "string",
       "enum": [
        "message",
        "message_edited",
        "callback",
        "blocked",
        "unblocked"
       ]
      }
     },
     "last_update_id": {
      "type": "integer"
     },
     "webhook": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "url": {
        "type": "string"
       },
       "cursor": {
        "type": "integer"
       },
       "pending": {
        "type": "boolean"
       },
       "failures": {
        "type": "integer"
       },
       "last_error": {
        "type": [
         "string",
         "null"
        ],
        "description": "http_<status>, timeout, connection_failed or address_not_allowed."
       },
       "retry_at": {
        "type": [
         "integer",
         "null"
        ]
       },
       "disabled": {
        "type": "boolean"
       }
      }
     }
    }
   },
   "NewMessage": {
    "type": "object",
    "required": [
     "chat_id",
     "client_id"
    ],
    "properties": {
     "chat_id": {
      "type": "integer"
     },
     "client_id": {
      "type": "string",
      "maxLength": 64,
      "description": "Your key for this send. `reply-<update id>` suits an answer to an update."
     },
     "text": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 4096,
      "description": "The message, or the caption of the file. Required without `file_id`."
     },
     "entities": {
      "type": [
       "array",
       "null"
      ],
      "maxItems": 100,
      "items": {
       "$ref": "#/components/schemas/Entity"
      },
      "description": "Formatting of `text`. See `Entity`."
     },
     "file_id": {
      "type": "integer",
      "description": "`id` from `POST /files`: the bot's own upload. One upload serves any number of messages."
     },
     "reply_to_message_id": {
      "type": [
       "integer",
       "null"
      ]
     },
     "buttons": {
      "type": [
       "array",
       "null"
      ],
      "maxItems": 8,
      "items": {
       "type": "array",
       "minItems": 1,
       "maxItems": 4,
       "items": {
        "$ref": "#/components/schemas/Button"
       }
      },
      "description": "Rows of buttons under the message."
     }
    },
    "description": "`text`, `file_id` or both."
   },
   "MessageRef": {
    "type": "object",
    "required": [
     "id",
     "chat_id"
    ],
    "properties": {
     "id": {
      "type": "integer"
     },
     "chat_id": {
      "type": "integer"
     }
    }
   },
   "UpdatesPage": {
    "type": "object",
    "required": [
     "updates",
     "next_cursor"
    ],
    "properties": {
     "updates": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Update"
      }
     },
     "next_cursor": {
      "type": "integer",
      "description": "Pass it as `after` once the page is handled. It moves on an empty page too."
     }
    }
   },
   "Update": {
    "oneOf": [
     {
      "$ref": "#/components/schemas/MessageUpdate"
     },
     {
      "$ref": "#/components/schemas/CallbackUpdate"
     },
     {
      "$ref": "#/components/schemas/BlockUpdate"
     }
    ],
    "discriminator": {
     "propertyName": "type",
     "mapping": {
      "message": "#/components/schemas/MessageUpdate",
      "message_edited": "#/components/schemas/MessageUpdate",
      "callback": "#/components/schemas/CallbackUpdate",
      "blocked": "#/components/schemas/BlockUpdate",
      "unblocked": "#/components/schemas/BlockUpdate"
     }
    }
   },
   "MessageUpdate": {
    "type": "object",
    "description": "A person wrote to the bot or edited their message.",
    "required": [
     "id",
     "type",
     "date",
     "chat_id",
     "user_id",
     "user",
     "message_id",
     "text"
    ],
    "properties": {
     "type": {
      "enum": [
       "message",
       "message_edited"
      ]
     },
     "id": {
      "type": "integer",
      "description": "Grows in the order events were written. Store the page cursor, not single IDs."
     },
     "date": {
      "type": "integer",
      "description": "Unix time."
     },
     "chat_id": {
      "type": [
       "integer",
       "null"
      ]
     },
     "user_id": {
      "type": "integer"
     },
     "user": {
      "$ref": "#/components/schemas/User"
     },
     "message_id": {
      "type": "integer"
     },
     "reply_to_message_id": {
      "type": "integer",
      "description": "ID of the message the person replied to, when it is still visible to this bot in this chat."
     },
     "text": {
      "type": "string",
      "description": "The text or the caption as it is when the page is read; empty when there is none."
     },
     "files": {
      "type": "array",
      "minItems": 1,
      "maxItems": 10,
      "items": {
       "allOf": [
        {
         "$ref": "#/components/schemas/FileLink"
        },
        {
         "type": "object",
         "properties": {
          "kind": {
           "enum": [
            "photo",
            "file",
            "audio"
           ]
          }
         }
        }
       ]
      },
      "description": "A photo, an album of photos, a document, or a chat MP3 track. A new download link is issued on each read."
     },
     "start_param": {
      "type": "string",
      "maxLength": 64,
      "pattern": "^[A-Za-z0-9_-]+$",
      "description": "Present when the person came through a link or button with a start parameter."
     }
    }
   },
   "CallbackUpdate": {
    "type": "object",
    "description": "A callback button under the bot's message was pressed. Answer it with `POST /updates/{id}/answer` before `answer_until`, with a text or without: until then the button shows the person that it waits.",
    "required": [
     "id",
     "type",
     "date",
     "chat_id",
     "user_id",
     "user",
     "message_id",
     "data",
     "answer_until"
    ],
    "properties": {
     "type": {
      "const": "callback"
     },
     "id": {
      "type": "integer",
      "description": "Grows in the order events were written. Store the page cursor, not single IDs."
     },
     "date": {
      "type": "integer",
      "description": "Unix time."
     },
     "chat_id": {
      "type": [
       "integer",
       "null"
      ]
     },
     "user_id": {
      "type": "integer"
     },
     "user": {
      "$ref": "#/components/schemas/User"
     },
     "message_id": {
      "type": "integer"
     },
     "data": {
      "type": "string",
      "description": "The `callback_data` of the pressed button."
     },
     "answer_until": {
      "type": "integer",
      "description": "Unix time until which the person waits for an answer: 10 seconds after the press."
     }
    }
   },
   "BlockUpdate": {
    "type": "object",
    "description": "The person blocked or unblocked the bot.",
    "required": [
     "id",
     "type",
     "date",
     "chat_id",
     "user_id",
     "user"
    ],
    "properties": {
     "type": {
      "enum": [
       "blocked",
       "unblocked"
      ]
     },
     "id": {
      "type": "integer",
      "description": "Grows in the order events were written. Store the page cursor, not single IDs."
     },
     "date": {
      "type": "integer",
      "description": "Unix time."
     },
     "chat_id": {
      "type": [
       "integer",
       "null"
      ]
     },
     "user_id": {
      "type": "integer"
     },
     "user": {
      "$ref": "#/components/schemas/User"
     }
    }
   },
   "WebAppSession": {
    "type": "object",
    "required": [
     "bot_id",
     "chat_id",
     "user",
     "start_param",
     "auth_date"
    ],
    "properties": {
     "bot_id": {
      "type": "integer"
     },
     "chat_id": {
      "type": "integer"
     },
     "user": {
      "$ref": "#/components/schemas/User"
     },
     "start_param": {
      "type": [
       "string",
       "null"
      ],
      "description": "The trusted copy of the start parameter."
     },
     "auth_date": {
      "type": "integer",
      "description": "Unix time of this exchange."
     }
    }
   },
   "Entity": {
    "type": "object",
    "required": [
     "type",
     "offset",
     "length"
    ],
    "description": "Formatting of one range of `text`. Ranges of one type do not overlap; `code` does not overlap `bold`, `italic` or `link`; a range never splits a surrogate pair. Up to 100 per message.",
    "properties": {
     "type": {
      "enum": [
       "bold",
       "italic",
       "code",
       "link",
       "quote"
      ]
     },
     "offset": {
      "type": "integer",
      "minimum": 0,
      "description": "Start of the range in UTF-16 code units."
     },
     "length": {
      "type": "integer",
      "minimum": 1,
      "description": "Length of the range in UTF-16 code units."
     },
     "url": {
      "type": "string",
      "format": "uri",
      "maxLength": 1024,
      "description": "For `link` only, and required there: https. Toki asks the person before leaving. A `quote` covers whole lines."
     }
    }
   },
   "File": {
    "type": "object",
    "required": [
     "id",
     "kind",
     "name",
     "size",
     "mime",
     "width",
     "height"
    ],
    "properties": {
     "id": {
      "type": "integer"
     },
     "kind": {
      "enum": [
       "photo",
       "file",
       "audio",
       "video"
      ]
     },
     "name": {
      "type": [
       "string",
       "null"
      ],
      "description": "Download filename for a document or audio track; null otherwise."
     },
     "size": {
      "type": "integer",
      "description": "Bytes."
     },
     "mime": {
      "type": "string"
     },
     "width": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Pixel width for photo and video."
     },
     "height": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Pixel height for photo and video."
     },
     "duration_sec": {
      "type": "number",
      "exclusiveMinimum": 0,
      "description": "Playback duration for audio and video, in seconds."
     },
     "title": {
      "type": "string",
      "description": "Audio track title."
     },
     "performer": {
      "type": [
       "string",
       "null"
      ],
      "description": "Audio performer if known."
     }
    }
   },
   "FileLink": {
    "allOf": [
     {
      "$ref": "#/components/schemas/File"
     },
     {
      "type": "object",
      "required": [
       "url",
       "expires_at"
      ],
      "properties": {
       "url": {
        "type": [
         "string",
         "null"
        ],
        "format": "uri",
        "description": "Download link, valid until `expires_at`. No authorization header is needed. Null while storage is unavailable: ask again with `GET /files/{id}`."
       },
       "expires_at": {
        "type": [
         "integer",
         "null"
        ],
        "description": "Unix time."
       }
      }
     }
    ]
   }
  }
 }
}
