App Logo
web.telegram.org

Telegram — Download a message's media

Pull the bytes of a document, photo or video attached to a Telegram message, given its conversation peer id and message id, returned as base64 plus the filename Telegram stores it under. Drives the message's own Download action and reads the file out of the app rather than relying on a browser download, and refuses a message that carries no media. Two side effects worth knowing: opening the conversation marks it read, and Telegram also saves the file to the browser's download folder. Note that photos are Telegram's re-encoded JPEG, not the original upload; documents come back byte-for-byte.

Input

peerId required

The conversation's peer id, as returned by get_inbox (e.g. "8591421602" for Saved Messages; negative ids are channels and groups).

messageId required

The message carrying the media, as returned by get_conversation or send_message. Must be one of the recently loaded messages in that conversation — get_conversation only loads a recent window, so raise its count until the target is present.

Output

kind required

Which bubble shape it was read from: "document" for a file bubble (a filename and size are shown in the chat), "media" for a photo or video bubble.

base64 required

The file's bytes, base64-encoded — the exact inverse of send_message's fileBase64, so a file can be round-tripped between conversations. Documents come back byte-for-byte identical to what was sent.

peerId required

The peer id that was actually opened, read back from the address bar.

filename required

The name Telegram saves the file under, taken from its own download action rather than guessed. For a document this is the original filename; for a photo it is Telegram's generated name (e.g. "5793955541833946033.jpg").

messageId required

The message the media came from.

byteLength required

Size of the returned bytes. For a document this matches the size shown on the bubble; for a photo it is the size of Telegram's re-encoded copy, which will not match the original upload.

verified_on_page required

True when the bytes were actually captured from the app's own download action, rather than the click being assumed to have worked.

mimeType optional

The MIME type Telegram attached to the blob it saved, or null if it did not set one.

chatTitle optional

The conversation title from the header — echo this to a human, since a peer id is not recognisable.

Start building not clicking