Docs

Messages

Formatted text, documents with headings, lists and code, replies and edits.

A bot writes a message in one of two ways: text with entities for plain text, or document for a rich message. Both can carry buttons and reply_to_message_id.

Text

{ "chat_id": "…", "text": "Hello, world" }

Up to 32,768 characters. Empty text or text of only spaces is refused.

Formatting

entities mark ranges of text. offset and length are in UTF-16 units (Entity).

{
  "chat_id": "…",
  "text": "Build 42 is ready: open",
  "entities": [
    { "type": "bold", "offset": 0, "length": 8 },
    { "type": "text_link", "offset": 19, "length": 4, "url": "https://ci.example.org/42" }
  ]
}

Markdown or HTML in the text is not parsed: asterisks stay asterisks.

Documents

Comon messages are documents made of blocks: paragraphs, headings, lists, quotes, code, tables, columns, callouts, toggles (formatting). A bot may send a whole document in the document field. Its shape is the JSON of the InputDocument message from protocol/comon/federation/document.proto, with camelCase fields.

{
  "chat_id": "…",
  "document": {
    "schemaVersion": 1,
    "blocks": [
      { "id": "0000000000000000000000000000000a",
        "heading": { "level": 2, "content": { "id": "0000000000000000000000000000000b", "text": "Build 42" } } },
      { "id": "0000000000000000000000000000000c",
        "code": { "content": { "id": "0000000000000000000000000000000d", "text": "flutter build web" }, "language": "sh" } },
      { "id": "0000000000000000000000000000000e",
        "list": { "kind": "DOCUMENT_LIST_KIND_BULLET", "items": [
          { "id": "0000000000000000000000000000000f", "blocks": [
            { "id": "00000000000000000000000000000010",
              "paragraph": { "id": "00000000000000000000000000000011", "text": "tests passed" } } ] } ] } }
    ]
  },
  "buttons": [[{ "text": "Open", "url": "https://ci.example.org/42" }]]
}
  • Block and text IDs are 32 lowercase hex characters, unique within the document. Their order does not matter: numbering them in sequence is fine.
  • Headings have levels 1–3.
  • Document limits: up to 256 blocks, lists and quotes nested up to 4 levels, up to 512 KiB (limits).
  • A wrong document gets 400 with a description of the error.

Replying to a message

{ "chat_id": "…", "text": "Got it", "reply_to_message_id": "<message_id>" }

The message must be from the same chat.

Editing and deleting

editMessage replaces the whole content, buttons included: to remove the buttons, send the message without buttons. A bot edits its own messages: in direct chats and groups within 48 hours, in channels and community rooms without a time limit.

deleteMessage deletes one (message_id) or up to 100 messages (message_ids) for everyone.

Sending again

So that a retry after a network failure does not send twice, pass idempotency_key (retries).

Media

Sending files, photos and voice messages through the Bot API is not supported yet. A bot receives incoming media in document as blocks with attachments and can point at outside addresses with buttons and links.

On this page