Skip to content
Kiba Chat
AI communication platform
Developers

Bot API

Everything a bot can call, what it receives, and its limits. The reference is in English because it is written in field names, paths and JSON.

Authentication

Create a bot in Settings → Bots. The token (mia_bot_ followed by 48 hex characters) is shown ONCE, at creation and at every regeneration; the server keeps only its SHA-256 hash and cannot show it again.

Every bot call sends the token in the X-Bot-Token header. Without the header the answer is 422 (a required field is missing); a wrong token, or the token of a disabled bot, answers 401 Invalid bot token; a bot whose owner is banned answers 403 Bot owner is banned.

Routes marked "signed-in person" are called by the apps on behalf of a person, with that person's session (Authorization: Bearer <access token> or the session cookie). They are listed so the whole surface is in one place.

Bodies are JSON unless a method says otherwise. An error is {"detail": "..."}; a body that breaks a field rule (type, length, range) answers 422 with the field named in detail.

Who a bot can talk to

A bot is an account of its own. Who may write to it is the bot's inbound_policy: owner_only (the default) or anyone, set by the owner. A message from anyone else is refused before it is stored and never reaches the bot.

A bot answers, it does not solicit: it may write to its owner and to a person who has written to it at least once — never to someone who blocked it or whom it blocked. Anything else answers 403 This bot may only message its owner and people who have written to it.

A bot receives the direct messages addressed to it. It does not read groups, channels or its owner's other chats.

Receiving updates: long poll or webhook

A bot receives by ONE transport. While a webhook URL is set, GET /self/updates answers 409 ("Long poll is disabled because a webhook URL is configured…"); clearing the URL brings long poll back.

Long poll: call GET /self/updates with after_id = the last last_id you got and timeout up to 50 seconds; the call returns as soon as something arrives or the window closes. Messages are numbered by id, so a cursor never misses one or reads one twice.

Updates that are not messages (edited_message, callback_query, poll_answer, message_reaction, my_chat_member) are served only when you send after_update_id, with their own cursor last_update_id — a separate numbering from message ids. They are kept for 24 hours; one not fetched within a day is gone.

Webhook: the server POSTs each update to your HTTPS URL. See "Webhooks" below.

KindWhenBody
messageA person wrote to the botid (long poll) / update_id (webhook), from_user_id, text, created_at, message_type (text, image, video, file, …), file (long poll: null when there is none; webhook: absent when there is none)
edited_messageA person edited their message to the botthe message fields plus edited_at; a bot's own edit-message call is not echoed back to it
callback_queryA person tapped a callback button under the bot's messageid (answer with it), from_user_id, chat_id, message {message_id, text}, data
inline_queryA person typed @yourbot text in a chat (only when inline mode is on for the bot)id (answer with it, within about 5 seconds), from_user_id, query (up to 256 characters), offset, chat_type (private or group), and location (latitude, longitude) only when the bot's owner switched on inline results by location (the owner switch in the bot settings, inline_geo of PUT /bots/{id}/inline) AND the person agreed for your bot; a located answer is never cached. The chat itself is never sent
chosen_inline_resultThe person picked one of your results (only when inline feedback is on)result_id, from_user_id, query
poll_answerSomeone answered a poll the bot can seepoll_id, from_user_id, option_ids, date. Non-anonymous polls only — an anonymous poll hides who answered
message_reactionA reaction on a message in the bot's chat was added or removedmessage_id, from_user_id, emoji, action (added or removed), date — one emoji per update. Opt-in: sent only when allowed_updates names it
my_chat_memberA person blocked (kicked) or unblocked (member) the bot, or added it to a group by a startgroup linkchat_id, from_user_id, old_status, new_status, date; for a group add also chat_type: "group", start_payload, text = /start@<bot> <payload>

Files

A message with an attachment carries file: {file_id, name, mime, size, download_url}. download_url is /api/v1/bots/self/files/{file_id}; fetch it WITH the token and it redirects (307) to a fresh signed link, so it does not expire while an update waits in the queue.

To send a file: upload it with POST /self/upload, then send-message with the returned file_id (text becomes the caption). Images arrive as image, videos as video, everything else as file. A bot may attach a file it uploaded or one it received in a message (its file_id); any other file answers 403 Not your file.

Keyboards

reply_markup on send-message carries exactly ONE of the four forms below. A wrong keyboard is refused with 400 and a message — it is never silently repaired.

Limits for both keyboards: 1-10 rows, 1-8 buttons per row, at most 100 buttons, button text 1-64 characters.

Inline keyboard: each button has text and exactly one of callback_data (1-64 bytes), url (an https:// link, at most 512 characters), web_app ({"url": "https://..."}) or login_url ({"url": ...} plus optional forward_text, bot_username, request_write_access); web_app and login_url open outside the app like url. A tap on a callback button writes no chat message; the bot gets a callback_query and should answer it with answer-callback-query.

Reply keyboard: a tap SENDS the button's text as an ordinary message from the person. A button is a string or {"text": ...}; {"text": ..., "web_app": {"url": "https://..."}} opens the link outside the app instead of sending the text. Any other field (contact, location requests) is refused.

An edit (edit-message-text, edit-message-reply-markup) carries an inline keyboard only; an edit without reply_markup removes the keyboard.

FormShape
Inline keyboard{"inline_keyboard": [[{"text": "Yes", "callback_data": "yes"}, {"text": "Site", "url": "https://example.com"}]]}
Reply keyboard{"keyboard": [["One", {"text": "Two"}]]} plus optional booleans is_persistent, resize_keyboard, one_time_keyboard, selective and input_field_placeholder (1-64 characters)
Remove reply keyboard{"remove_keyboard": true} plus optional selective
Force reply{"force_reply": true} plus optional input_field_placeholder (1-64 characters) and selective

Commands and scopes

A command list is up to 100 items of {command, description}: command 1-32 of lowercase a-z, digits and _; description 1-256 characters; no command twice.

scope is {"type": ...} with one of default, all_private_chats, all_group_chats, all_chat_administrators, chat and chat_administrators (both need chat_id), chat_member (needs chat_id and user_id). Omitted = default. language_code is a two-letter ISO 639-1 code; omitted or empty = everyone the scope covers.

What a person sees after typing "/" in a direct chat with the bot: the first list that is set among chat (their chat) → all_private_chats → default, each tried in the person's app language first, then without a language.

The menu button beside the composer opens this list. It is shown by default; set-menu-button with hidden removes it, with web_app and an https url it opens that page as a mini app instead.

Mini apps

A mini app is your https page opened inside the chat app from a web_app button, the menu button (set-menu-button with web_app) or the attach menu. The person confirms the first open of each bot's mini app. The page receives signed launch data (initData, a URL-encoded query string): user (JSON with id, first_name, last_name, username, language_code), auth_date (unix seconds), start_param and hash. Nothing else is sent. The page talks to the app with the reference's postMessage protocol (web_app_ready, web_app_close, web_app_data_send, web_app_expand, web_app_open_link, web_app_request_theme, web_app_request_viewport, web_app_setup_closing_behavior); other events are ignored.

Verify the launch data on your server exactly as the reference documents, with ONE difference: we never hold your bot token (only its sha256), so the secret key is built from sha256(token) hex instead of the token. Build the data-check-string from every field except hash, sorted by key, as key=value lines joined by a newline; then secret = HMAC_SHA256(key="WebAppData", msg=sha256_hex(token)) and hash = hex(HMAC_SHA256(key=secret, msg=data_check_string)). Also check that auth_date is recent.

secret = hmac.new(b"WebAppData", hashlib.sha256(TOKEN.encode()).hexdigest().encode(), hashlib.sha256).digest()
check = "\n".join(f"{k}={v}" for k, v in sorted(fields.items()) if k != "hash")
valid = hmac.compare_digest(hmac.new(secret, check.encode(), hashlib.sha256).hexdigest(), fields["hash"])

Data the page sends back with web_app_data_send (at most 4096 bytes) reaches the bot as an update of kind web_app_data: {from_user_id, data, button_text, date}. When the page is opened from a chat (the menu button, a keyboard button or the attach menu) the launch data also carries query_id, a one-use right to send ONE message as that person into that chat with answer-web-app-query below; it is bound to your bot, the person and the chat, and lasts 15 minutes. It is part of the signed fields, so it is covered by the hash.

Webhooks

The URL must be https://, carry no user or password, and resolve only to public addresses (no localhost, private, link-local or metadata addresses). It is checked when saved AND again before every delivery. With the ip_address option that public address is used instead of DNS.

Options saved with the URL: max_connections (1-100, default 40) caps deliveries in flight; allowed_updates limits the kinds sent (by webhook and long poll); drop_pending_updates skips everything addressed to the bot before the call.

The first time a URL is saved, the response carries webhook_secret — shown once. Saving another URL keeps the secret; clearing the URL clears it; rotate-secret issues a new one and the old one stops at once.

Each delivery is POST <url> with Content-Type: application/json and the headers X-MiaChat-Bot-Update-Id, X-MiaChat-Bot-Update-Kind (message, edited_message, callback_query, poll_answer, message_reaction or my_chat_member), X-MiaChat-Bot-Delivery: 1 and X-MiaChat-Bot-Signature: sha256=<hex> — the HMAC-SHA256 of the raw body with your secret as the key. Verify it against the exact bytes received.

Body for a message: {"update_id", "type": "message", "from_user_id", "text", "message_type", "created_at", "file"?}. Body for the other kinds: {"update_id", "type": kind, kind: {...}, "created_at"}. Messages and other updates are numbered separately, so deduplicate by (kind, update id).

Your endpoint has 5 seconds to answer. A delivery is tried up to 4 times, 0.5 s, 1 s and 2 s apart; network errors, 5xx, 408 and 429 are retried, any other 4xx is not.

After the last attempt the update is dropped: nothing is stored for redelivery, and long poll cannot fetch it while the webhook is set. Answer quickly with a 2xx and do slow work afterwards.

Errors and rate limits

A bot may send 60 messages per minute (send-message and upload share this budget) and 120 chat actions per minute.

A send-message call is counted before its target, write rule and file are checked, so a refused send (403, 404) still spends the budget.

Over the budget the answer is 429 with the body {"detail": "...", "retry_after": N} and the header Retry-After: N — wait N whole seconds, then retry.

A bot receives at most 120 messages per minute across all senders; past that a person's message is refused on their side and never reaches the bot.

A person may tap 30 callback buttons per minute across all bots.

Bot methods (X-Bot-Token)

Called by your bot with its token.

GET/api/v1/bots/self/infoBot token

Who the token belongs to.

Returns: {id, name, username, description, commands} — commands is the default list.

Errors: 401 Invalid bot token · 403 Bot owner is banned
GET/api/v1/bots/self/updatesBot token

Long poll for messages and other updates.

Query parameters

after_idinteger0 to 2147483647, default 0. Messages with a greater id.
limitinteger1-100, default 50. Applies to messages and to updates separately.
timeoutinteger0-50 seconds, default 0 (answer at once).
after_update_idinteger0 to 2147483647. Send it to also receive callback_query and my_chat_member.

Returns: {messages: [...], last_id, updates: [{update_id, type, <type>: {...}, created_at}], last_update_id}. The bot's own messages are not included.

Errors: 401 Invalid bot token · 403 Bot owner is banned · 409 Long poll is disabled because a webhook URL is configured
POST/api/v1/bots/self/send-messageBot token

Send a message to a person in the bot's direct chat.

Body

target_user_idintegerThe person (their user id, as from_user_id in an update). Exactly one of target_user_id / target_group_id.
target_group_idintegerA group the bot is a member of.
reply_to_message_idintegerGroups only.
topic_idintegerGroups only: a topic of a forum group.
textstringUp to 4000 characters. Required unless file_id, location, contact_user_id or poll is set; with file_id it is the caption.
file_idintegerA file from POST /self/upload. Direct chats only.
reply_markupobjectA keyboard, see "Keyboards". Direct chats only.
parse_modestringMarkdownV2, Markdown or HTML (any case). Bold, italic, strikethrough, spoiler, inline code, pre blocks, http(s) links and block quotes are shown; underline shows as plain text; a link to anything but http(s) shows its label only. Omitted = text is shown as sent (our own markdown: **bold**, *italic*, ~~strike~~, ||spoiler||).
locationobject{latitude, longitude, address?} — a location message; nothing else beside it.
contact_user_idintegerShare an account as a contact: the owner or a person who wrote to the bot.
pollobject{question, options (2-12), is_anonymous?, allow_multi_choice?, is_quiz?, quiz_correct_idx?, explanation?, closes_in_minutes?}.

Returns: {ok: true, message_id}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 (target_user_id missing) · 400 text, file_id, location, contact_user_id or poll required · 400 exactly one of target_user_id or target_group_id required · 400 (a keyboard rule) · 400 Unsupported parse_mode / can't parse entities: … (an unknown mode, an unsupported or unclosed tag, a bad numeric entity) · 403 This bot may only message its owner and people who have written to it · 403 Not your file · 404 Target user not found · 404 File not found · 429 rate limit, see "Errors and rate limits"
POST/api/v1/bots/self/uploadBot token

Upload a photo, video or document as the bot: multipart/form-data with one field file, the same type checks and size limits as a person's upload.

Returns: {ok, file_id, original_name, size_bytes, content_type, url, …} — pass file_id to send-message.

Errors: 401 Invalid bot token · 403 Bot owner is banned · 429 rate limit (shares the 60 messages/min budget)
GET/api/v1/bots/self/files/{file_id}Bot token

Download a file from an update.

Returns: 307 redirect to a short-lived signed link.

Errors: 401 Invalid bot token · 403 Bot owner is banned · 404 File not found (not in a live message to or from this bot)
POST/api/v1/bots/self/edit-message-textBot token

Edit the text of one of the bot's own messages.

Body

message_idinteger · requiredA message this bot sent.
textstring · required1-4000 characters.
reply_markupobjectInline keyboard only; omitted removes the keyboard.
parse_modestringMarkdownV2, Markdown or HTML (any case). Bold, italic, strikethrough, spoiler, inline code, pre blocks, http(s) links and block quotes are shown; underline shows as plain text; a link to anything but http(s) shows its label only. Omitted = text is shown as sent (our own markdown: **bold**, *italic*, ~~strike~~, ||spoiler||).

Returns: {ok: true, message_id, edited_at}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 (a keyboard rule) · 400 Unsupported parse_mode / can't parse entities: … (an unknown mode, an unsupported or unclosed tag, a bad numeric entity) · 400 text is empty after parse_mode · 404 Message not found
POST/api/v1/bots/self/edit-message-reply-markupBot token

Replace or remove the inline keyboard of one of the bot's own messages; the text is kept.

Body

message_idinteger · requiredA message this bot sent.
group_idintegerSet for a group message; omitted = a direct message.
reply_markupobjectInline keyboard only; omitted removes the keyboard.

Returns: {ok: true, message_id, edited_at}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 (a keyboard rule) · 403 This bot is not a member of that group · 404 Message not found
POST/api/v1/bots/self/delete-messageBot token

Delete one of the bot's own messages, for everyone.

Body

message_idinteger · requiredA message this bot sent.

Returns: {ok: true, message_id}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 404 Message not found
POST/api/v1/bots/self/answer-callback-queryBot token

Answer a button tap. The person sees text as a short notice, or as an alert with show_alert. Once per query.

Body

callback_query_idstring · requiredThe id of the callback_query.
textstringUp to 200 characters.
show_alertbooleanDefault false.
urlstringAn https:// link (up to 512 characters) the person's app offers to open, after an "Open this link?" confirm.
cache_timeinteger0-86400 seconds, default 0. For that long the same person's tap on the same button of the same message gets this answer again without a new callback_query reaching the bot.

Returns: {ok: true}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 Query is unknown or already answered · 422 (url not https, cache_time out of range)
POST/api/v1/bots/self/answer-inline-queryBot token

Answer an inline_query with a list of results the person can pick. Once per query. A picked result is sent into the chat as the person, marked "via @yourbot". Inline mode is switched on in the bot's settings (with an optional input hint).

Body

inline_query_idstring · requiredThe id of the inline_query.
resultsarray · requiredAt most 50 objects with a unique id (1-64 bytes) and a type: article (title, input_message_content {message_text, up to 4000 characters}, optional url, description, thumbnail_url), photo (photo_url) or gif (gif_url). Photo and gif links must be https://; our server downloads the picture (public addresses only, up to 5 MB, a gif up to 4096 px and 300 frames) and sends it as an image message. A picture that cannot be loaded makes the pick fail.
cache_timeinteger0-86400 seconds, default 300. The same query is answered from the cache for that long.
is_personalbooleanDefault false. True keeps the cached answer for the asking person only.
next_offsetstringUp to 64 bytes. Empty or omitted = no more pages; otherwise it comes back as offset of the next inline_query.
buttonobject{text, start_parameter} or {text, web_app: {url}} (exactly one): a button above the results that either opens a private chat with the bot and passes start_parameter (A-Z a-z 0-9 _ -, up to 64) as the start payload, or opens the bot's mini app at the https url.

Returns: {ok: true}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 Query is unknown or already answered · 400 (a result, cache_time, next_offset or button rule)
POST/api/v1/bots/self/answer-web-app-queryBot token

Answer a mini app's query_id (a field of its signed launch data): the message is sent into the chat the page was opened from, as the person who opened it, marked "via @yourbot". Once per query, within 15 minutes; the same send rules as a picked inline result apply to the person (blocks, bans, mutes, slow mode).

Body

web_app_query_idstring · requiredThe query_id of the launch data.
resultobject · requiredOne inline result in the same form as in answer-inline-query: an article (id, title, input_message_content {message_text}), a photo or a gif.

Returns: {ok: true, message_id}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 Query is unknown, expired, already answered or not this bot's · 400 (a result rule) · 403 The message could not be sent to this chat
POST/api/v1/bots/self/send-gameBot token

Send one of the bot's registered games to a person as a message with a Play button. The owner registers games in Bots > the bot > Games; a tap on Play records a callback_query update with game_short_name and opens the game's https link after the same "Open this link?" confirm as a url button.

Body

target_user_idinteger · requiredThe person. The same write rule as send-message.
game_short_namestring · required3-64 letters, digits or underscores; a game of THIS bot (404 otherwise).
reply_markupobjectAn inline_keyboard that must carry a callback_game button; omitted = one "Play" button. The button is bound to the game on our side.

Returns: {ok: true, message_id}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 reply_markup of a game must carry a callback_game button · 403 This bot may only message its owner and people who have written to it · 404 Game not found · 404 Target user not found · 429 rate limit (60 messages/min)
POST/api/v1/bots/self/send-invoiceBot token

Send a Stars invoice (currency XTR, no provider token) to a person as a message with a Pay button. When the person pays, the bot receives a pre_checkout_query update and must answer it within 10 seconds; an ok answer charges the person and credits the bot owner, then a successful_payment update follows.

Body

target_user_idinteger · requiredThe person. The same write rule as send-message.
titlestring · required1-32 characters.
descriptionstring · required1-255 characters.
payloadstring · required1-128 characters, opaque to us; echoed back as invoice_payload.
currencystringMust be XTR (Stars). Default XTR.
pricesarray · requiredExactly one item {label, amount}; amount 1-10000 Stars.
provider_tokenstringMust be empty or absent.

Returns: {ok: true, message_id, invoice}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 currency must be XTR · 422 (a field rule) · 403 This bot may only message its owner and people who have written to it · 404 Target user not found · 429 rate limit (60 messages/min)
POST/api/v1/bots/self/answer-pre-checkout-queryBot token

Answer a pre_checkout_query update. ok: true lets the payment go through (nothing is charged before this); ok: false with error_message cancels it and the person sees the message. Unanswered for 10 seconds = cancelled.

Body

pre_checkout_query_idstring · requiredThe id of the update's pre_checkout_query.
okboolean · requiredTrue to proceed.
error_messagestringRequired when ok is false; at most 255 characters.

Returns: {ok: true}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 error_message is required when ok is false · 400 Query is unknown, already answered or expired
POST/api/v1/bots/self/refund-star-paymentBot token

Refund a completed Stars payment: the Stars move from the bot owner back to the person. Once per payment.

Body

user_idinteger · requiredThe person who paid.
payment_charge_idstring · requiredThe payment_charge_id of the successful_payment update.

Returns: {ok: true}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 Payment already refunded · 400 The bot owner does not have enough Stars to refund · 404 Payment not found
POST/api/v1/bots/self/set-game-scoreBot token

Set a person's score in one of the bot's games. A lower score than the stored one, or a person who never tapped Play, needs force.

Body

user_idinteger · requiredThe person.
scoreinteger · required0 to 2147483647.
game_short_namestring · requiredA game of this bot.
forcebooleanDefault false. Allows a lower score and a first score for a person who has not played (the write rule of send-message still applies).

Returns: {ok: true, score}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 The new score is lower than the current one; pass force to lower it · 400 This person has not played the game; pass force to set a score anyway · 403 This bot may only message its owner and people who have written to it · 404 Game not found
POST/api/v1/bots/self/get-game-high-scoresBot token

The top 10 of a game's table, and optionally one person's own place.

Body

game_short_namestring · requiredA game of this bot.
user_idintegerAdds user with that person's score and position when they have a score above 0.

Returns: {scores: [{position, user_id, name, score}], user?: {user_id, score, position}}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 404 Game not found
POST/api/v1/bots/self/send-chat-actionBot token

Show "typing…" in the chat with a person or in a group the bot is in. It disappears about 3 seconds after the last call, so repeat it while the bot works.

Body

target_user_idintegerThe person. Exactly one of this or target_group_id.
target_group_idintegerA group the bot is a member of (403 otherwise).
actionstringOnly typing (the default).

Returns: {ok: true}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 exactly one of target_user_id or target_group_id required · 400 Only the 'typing' action is supported · 403 This bot may only message its owner and people who have written to it · 403 This bot is not a member of that group · 429 rate limit (120 actions/min)
POST/api/v1/bots/self/set-my-commandsBot token

Set the command list of a scope and language.

Body

commandsarray · required[{command, description}], see "Commands and scopes".
scopeobjectSee "Commands and scopes". Omitted = default.
language_codestringTwo letters, or empty for every language.

Returns: {ok: true}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 (a scope, language or command rule)
POST/api/v1/bots/self/get-my-commandsBot token

The list stored for exactly this scope and language (no fallback). POST because the scope is a JSON object.

Body

scopeobjectSee "Commands and scopes". Omitted = default.
language_codestringTwo letters, or empty for every language.

Returns: {commands: [...]} — [] when none is set.

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 (a scope or language rule)
POST/api/v1/bots/self/delete-my-commandsBot token

Delete the list of a scope and language; the next broader list then applies.

Body

scopeobjectSee "Commands and scopes". Omitted = default.
language_codestringTwo letters, or empty for every language.

Returns: {ok: true}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 (a scope or language rule)
POST/api/v1/bots/self/set-menu-buttonBot token

Show or hide the menu button beside the composer in chats with the bot, or make it open a mini app.

Body

typestring · requiredcommands, hidden or web_app.
urlstringRequired with web_app (an https:// page, at most 1024 characters); refused with the other types.

Returns: {ok: true, menu_button, url}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 (web_app without an https url, or url with another type)
GET/api/v1/bots/self/webhook-infoBot token

The state of the bot's webhook delivery.

Returns: {url, has_custom_certificate: false, pending_update_count, dropped_update_count, last_error_date, last_error_message, max_connections, allowed_updates}. pending_update_count = deliveries in flight right now (updates are never queued); dropped_update_count = updates that failed since the last successful delivery; the last error is kept until the URL is set again or removed.

Errors: 401 Invalid bot token · 403 Bot owner is banned
POST/api/v1/bots/self/set-message-reactionBot token

React to a message in the bot's direct chat or in a group it is in. Like a person's tap it toggles: a second call with the same emoji removes it. The bot is not told of its own reaction.

Body

message_idinteger · requiredThe message.
group_idintegerSet for a group message; omitted = a direct message.
emojistring · required1-32 characters; the group's reaction rules apply.
bigbooleanDefault false.

Returns: {action: "added" | "removed", …}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 403 (not a member of the group, or the reaction is not allowed) · 404 Message not found · 429 rate limit
POST/api/v1/bots/self/pin-messageBot token

Pin a message. In a group the bot needs the pin_messages right, as a member would.

Body

message_idinteger · requiredThe message.
group_idintegerSet for a group message; omitted = a direct message.
silentbooleanGroups only: no "pinned a message" service line.

Returns: {ok: true, is_pinned: true, …}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 403 (not a member, or no `pin_messages` right) · 404 Message not found · 429 rate limit
POST/api/v1/bots/self/unpin-messageBot token

Unpin a message; the same body and rules as pin-message.

Body

message_idinteger · requiredThe message.
group_idintegerSet for a group message; omitted = a direct message.

Returns: {ok: true, is_pinned: false, …}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 403 (not a member, or no `pin_messages` right) · 404 Message not found · 429 rate limit
POST/api/v1/bots/self/stop-pollBot token

Close a poll the bot sent itself (in a direct chat of its own or in a group it is in). Members get the same "poll closed" update as when a person closes a poll.

Body

message_idinteger · requiredThe poll message.
group_idintegerSet for a group message; omitted = a direct message.

Returns: {ok: true, poll_id, closed_at}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 That message is not a poll · 400 The poll could not be closed · 403 A bot may close only a poll it sent itself · 403 This bot is not a member of that group · 404 Message not found · 409 The poll is already closed
POST/api/v1/bots/self/forward-messageBot token

Forward a message the bot can read (its direct chat, or a group it is in) to a person or a group, with the "Forwarded from" header.

Body

message_idinteger · requiredThe source message.
from_group_idintegerSet when the source is a group message.
target_user_idintegerExactly one of target_user_id / target_group_id; a person must be one the bot may write to.
target_group_idintegerA group the bot is a member of.
hide_captionsbooleanDrop the caption of a photo or file.

Returns: The forwarded message's ids.

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 exactly one of target_user_id or target_group_id required · 403 This bot may only message its owner and people who have written to it · 403 (not a member of a group, or content protection) · 404 Message not found · 429 rate limit
POST/api/v1/bots/self/copy-messageBot token

Copy a message: the same as forward-message without the "Forwarded from" header.

Body

message_idinteger · requiredThe source message.
from_group_idintegerSet when the source is a group message.
target_user_idintegerExactly one of target_user_id / target_group_id.
target_group_idintegerA group the bot is a member of.
hide_captionsbooleanDrop the caption of a photo or file.

Returns: The copied message's ids.

Errors: 401 Invalid bot token · 403 Bot owner is banned · 400 exactly one of target_user_id or target_group_id required · 403 This bot may only message its owner and people who have written to it · 403 (not a member of a group, or content protection) · 404 Message not found · 429 rate limit
GET/api/v1/bots/self/default-admin-rightsBot token

The rights the bot asks for when it is added as an administrator.

Returns: {group, channel} — each {right: bool}, or null when none is requested.

Errors: 401 Invalid bot token · 403 Bot owner is banned
GET/api/v1/bots/self/chat-memberBot token

A person's standing in a group the bot is a member of. Query: chat_id, user_id.

Returns: {user_id, status} — creator, administrator (with rights: {right: bool}), member, left or kicked.

Errors: 401 Invalid bot token · 403 Bot owner is banned · 403 (the bot is not a member of the group)

Managing a bot (signed-in owner)

What Settings → Bots calls. Only the bot's owner may call them for a bot; any other bot id answers 404.

GET/api/v1/bots/meSigned-in person

The caller's bots, newest first.

Returns: [{id, name, username, description, about, avatar_url, commands, webhook_url, enabled, inbound_policy, transfer_pending_to, created_at}] — never the token.

POST/api/v1/botsSigned-in person

Create a bot. Up to 10 bots per person.

Body

namestring · required1-64 characters.
usernamestring · required5-32 of A-Z, a-z, 0-9, _, ending in bot (any case); stored lowercase.
descriptionstringUp to 500 characters; shown in an empty chat with the bot.
aboutstringUp to 120 characters.

Returns: The bot as in GET /me, plus bot_token — the only time it is shown.

Errors: 403 Max 10 bots per user · 409 Username already taken · 422 (a username rule)
PUT/api/v1/bots/{bot_id}Signed-in person

Change the bot's profile and who may write to it. Only the fields sent are changed.

Body

namestring1-64 characters.
descriptionstringUp to 500; empty clears it.
aboutstringUp to 120; empty clears it.
avatar_urlstringUp to 512 characters.
enabledbooleanA disabled bot's token answers 401.
inbound_policystringowner_only or anyone.

Returns: {ok: true}

Errors: 404 Bot not found
PUT/api/v1/bots/{bot_id}/default-admin-rightsSigned-in person

Set the rights the bot asks for when it is added as an administrator — to groups, or to channels.

Body

for_channelsbooleanDefault false (groups).
rightsobject{right: bool} from the group permissions (or channel rights); null clears the request.

Returns: {ok: true, for_channels, rights}

Errors: 400 Unknown right(s): … · 404 Bot not found
POST/api/v1/bots/{bot_id}/transferSigned-in person

Offer the bot to another person. Nothing moves until they accept within 48 hours; a new offer replaces a pending one. Needs a confirmed sign-in.

Body

usernamestring · requiredThe new owner's username (a leading @ is fine). They must have written to the bot at least once.

Returns: {ok: true, transfer_pending_to, expires_at}; GET /me shows transfer_pending_to while the offer waits.

Errors: 400 You already own this bot · 403 session_unconfirmed · 403 Max 10 bots per user (the new owner's limit) · 404 Bot not found · 404 User not found · 409 The new owner must have written to this bot at least once
DELETE/api/v1/bots/{bot_id}/transferSigned-in person

Withdraw a pending transfer offer.

Returns: {ok: true}

Errors: 404 Bot not found
GET/api/v1/bots/transfer-offersSigned-in person

Bots offered to the caller and still waiting for an answer.

Returns: [{bot_id, name, username, avatar_url, from_username, from_display_name, expires_at}]

POST/api/v1/bots/{bot_id}/transfer/acceptSigned-in person

Take the bot offered to you. In the same step its token is replaced (the old one stops at once) and its webhook URL, secret and options are cleared. Needs a confirmed sign-in.

Returns: The bot as in GET /me, plus the new bot_token — the only time it is shown.

Errors: 403 session_unconfirmed · 403 Max 10 bots per user · 404 No such transfer offer · 410 This transfer offer has expired
POST/api/v1/bots/{bot_id}/transfer/declineSigned-in person

Turn down a transfer offer; the bot stays with its owner.

Returns: {ok: true}

Errors: 404 No such transfer offer
DELETE/api/v1/bots/{bot_id}Signed-in person

Delete the bot. Its chats leave every list, the message history stays readable, and the username becomes free.

Returns: {ok: true}

Errors: 404 Bot not found
POST/api/v1/bots/{bot_id}/regenerate-tokenSigned-in person

Issue a new token; the old one stops working at once.

Returns: {bot_token} — shown once.

Errors: 404 Bot not found
GET/api/v1/bots/{bot_id}/tokenSigned-in person

A token cannot be read back; this route says so.

Returns: Always 410 for the owner's bot — regenerate instead.

Errors: 404 Bot not found · 410 shown once at creation or regeneration
PUT/api/v1/bots/{bot_id}/preview-mediaSigned-in person

Replace the bot's profile preview pictures with up to 5 images the owner uploaded; an empty list clears them.

Body

file_idsarray · requiredIds of the owner's own uploaded images, in display order; duplicates are dropped.

Returns: {preview_media: [...]} as stored.

Errors: 404 Bot not found · 404 File not found (missing or not the owner's) · 400 Preview media must be images
POST/api/v1/bots/{bot_id}/commandsSigned-in person

Replace the default command list (no scope, no language). Items without a command or a description are dropped; at most 50 are kept.

Body

commandsarray · required[{command, description}]; the command is lowercased and cut to 32, the description cut to 256.

Returns: {commands: [...]} as stored.

Errors: 404 Bot not found
POST/api/v1/bots/{bot_id}/webhookSigned-in person

Set or clear the webhook URL and its options. While a URL is set, long poll answers 409. An option left out keeps its stored value.

Body

urlstringUp to 512 characters, see "Webhooks". Null or omitted clears the URL, its secret, max_connections and ip_address.
max_connectionsinteger1-100, default 40: how many deliveries to your URL may be in flight at once.
allowed_updatesarrayKinds to receive: message, callback_query, my_chat_member; [] = all (the default). Applies to long poll too. An unknown kind is refused (422).
drop_pending_updatesbooleanDefault false. True: nothing addressed to the bot before this call is served again, by webhook or long poll.
ip_addressstringA public IPv4/IPv6 address to deliver to instead of resolving the URL's host (the host still goes as Host and TLS name); "" clears it.

Returns: {webhook_url, max_connections, allowed_updates, ip_address}, plus webhook_secret the first time a URL is set.

Errors: 400 Webhook URL rejected: <reason> · 404 Bot not found · 422 (an option out of range)
POST/api/v1/bots/{bot_id}/webhook/rotate-secretSigned-in person

Issue a new webhook signing secret; the old one stops at once.

Returns: {webhook_secret} — shown once.

Errors: 404 Bot not found · 409 Set a webhook URL first

Used by the apps (signed-in person)

Called by the apps when a person meets a bot. A bot never calls these; they are listed so you know what happens on the person's side.

POST/api/v1/bots/webapp/initSigned-in person

Signed launch data for a bot's mini app (the app calls this when a person opens one).

Body

bot_user_idinteger · requiredThe bot's account id.
urlstring · requiredThe https page being opened.
start_paramstringA-Za-z0-9_-, at most 512.

Returns: {init_data, url, bot}

Errors: 400 (not an https url) · 403 (the person may not message the bot) · 404 Bot not found
POST/api/v1/bots/webapp/dataSigned-in person

A mini app sent data back; the bot gets a web_app_data update.

Body

bot_user_idinteger · requiredThe bot's account id.
datastring · required1-4096 bytes.
button_textstringThe label of the button that opened the app, at most 64.

Returns: {ok: true}

Errors: 400 (over 4096 bytes) · 403 · 404 Bot not found
GET/api/v1/bots/by-username/{username}Signed-in person

Resolve a bot for a link.

Returns: {bot_user_id, username, name, description, about, avatar_url, is_bot, can_message, commands}

Errors: 404 Bot not found
GET/api/v1/bots/peer/{peer_id}/commandsSigned-in person

The "/" list a person sees in their chat with the bot whose account id is peer_id.

Returns: {is_bot, commands, menu_button}; {is_bot: false, commands: []} for a person.

GET/api/v1/bots/group/{group_id}/commandsSigned-in person

The "/" lists a group member sees: every enabled bot in the group, its group-scope commands resolved for the caller (admin scopes only for owners and admins).

Returns: {bots: [{bot_user_id, username, commands}]}; a bot with no command for this caller is left out.

Errors: 404 Group not found (the caller is not a member)
POST/api/v1/bots/callbackSigned-in person

A person tapped a callback button; it becomes a callback_query for the bot.

Body

message_idinteger · requiredThe bot's message the button is under.
group_idintegerSet when the message is a group message: any current member may tap, the update carries chat_id = the group and chat_type: "group".
callback_datastring · required1-64 bytes; must be a button on that message.

Returns: {ok: true, callback_query_id}; while the bot's answer to this same tap is cached (cache_time) the answer is replayed over WS and the body adds cached: true — no new update reaches the bot.

Errors: 400 No such button on this message · 403 This bot only accepts messages from its owner · 404 Message not found · 429 Too many button taps
POST/api/v1/bots/share-pickSigned-in person

A person answered a request_users / request_chat reply-keyboard button with a pick; it becomes a users_shared / chat_shared update for the bot.

Body

message_idinteger · requiredThe bot's DM message that carries the keyboard; only its recipient may answer.
request_idinteger · requiredThe button's request_id; must be a button on that message.
user_idsarray1-10 friends of the person, no more than the button allows. Send this or group_id.
group_idintegerA group the person belongs to. Send this or user_ids.

Returns: {ok: true, update_id}

Errors: 400 Send either user_ids or group_id · 400 No such button on this message · 400 Too many people picked · 400 Only friends can be picked · 403 This bot only accepts messages from its owner · 404 Message not found · 404 Chat not found · 429 Too many button taps
GET/api/v1/bots/attach-menuSigned-in person

The bots this person keeps in the attach menu of the composer, oldest first. A disabled or deleted bot is not listed.

Returns: [{bot_user_id, username, name, avatar_url}]

PUT/api/v1/bots/attach-menu/{bot_user_id}Signed-in person

Put a bot into the person's attach menu. The owner must have allowed it (attach_menu_enabled) and the person must be able to write to the bot.

Returns: {ok: true}

Errors: 404 Bot not found · 403 This bot cannot be added to the attach menu · 409 The attach menu holds at most 8 bots
DELETE/api/v1/bots/attach-menu/{bot_user_id}Signed-in person

Take a bot out of the person's attach menu.

Returns: {ok: true}

POST/api/v1/bots/start-groupSigned-in person

A person followed a startgroup link and picked a group: add the bot and queue a my_chat_member update.

Body

usernamestring · requiredThe bot's username.
group_idinteger · requiredA group where the person may add members.
payloadstring1-64 of A-Z a-z 0-9 _ -.

Returns: {ok: true, added, group_id}

Errors: 403 This bot only accepts messages from its owner · 404 Bot not found · 409 The bot could not be added to this group (<reason>)
POST/api/v1/bots/self/get-business-connectionBot token

Read a business connection a person made with this bot: its rights and whether it is enabled. The bot learns of a connection by a business_connection update; messages of the chats the person chose arrive as business_message updates (chat_id, from_user_id, text, business_connection_id, and file for a photo or document: {file_id, name, mime, size, download_url}, fetched with the bot token). When the peer edits such a message the bot gets edited_business_message (the same fields plus edited_at); when the peer deletes it, deleted_business_messages (business_connection_id, chat_id, message_ids). Needs the can_read_messages right. The person's own messages in a covered chat arrive too, flagged is_outgoing: true. Never delivered: one-time and disappearing messages, secret chats, messages from bots, the bot's own sends, paused chats, and messages written before the connection.

Body

business_connection_idstring · requiredThe id from a business_connection update.

Returns: {id, user_id, can_reply, can_read_messages, can_delete_messages, is_enabled, date}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 404 business connection not found (also for another bot's connection)
POST/api/v1/bots/self/business/send-messageBot token

Send a text into one of the chats a person gave this bot, as that person. The peer sees an ordinary message from the person with no via mark; only the person sees the mark. Never available for secret chats.

Body

business_connection_idstring · requiredThe connection to send through.
chat_idinteger · requiredThe peer's user id; must be one of the chats the person chose.
textstring · required1-4000 characters.
parse_modestringAs for sendMessage.

Returns: {ok: true, message_id}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 403 business connection is disabled · 403 the can_reply right was not granted · 403 this chat was not given to the bot · 403 the owner paused the bot in this chat · 403 secret chats are never open to a bot · 404 business connection not found · 429 rate limit
POST/api/v1/bots/self/business/delete-messagesBot token

Delete messages the person wrote in one of the chats they gave this bot, on their behalf. Needs the can_delete_messages right (off until the person grants it). Only the person's own messages of that chat can be deleted, the same as the person could do by hand; one id that is not such a message refuses the whole call and nothing is deleted. The person's own messages in the chat also reach the bot as business_message updates with is_outgoing: true (from_user_id is the person); one-time and disappearing messages and the bot's own sends are never reported.

Body

business_connection_idstring · requiredThe connection to act through.
chat_idinteger · requiredThe peer's user id; must be one of the chats the person chose.
message_idsinteger[] · required1-100 ids of the person's own messages in that chat.

Returns: {ok: true, deleted: [message_id, ...]}

Errors: 401 Invalid bot token · 403 Bot owner is banned · 403 business connection is disabled · 403 the can_delete_messages right was not granted · 403 this chat was not given to the bot · 403 the owner paused the bot in this chat · 404 business connection not found · 404 message not found (not the person's own message of this chat, or already deleted) · 429 rate limit