App Logo
web.telegram.org

Telegram — Send a message or a document

Send a text message, a document, or a document with a caption to a Telegram conversation identified by its peer id (the id get_inbox returns), optionally as a reply. Confirms the send by finding the outgoing bubble in the conversation afterwards rather than trusting the click, reading back the document's filename and size and requiring the quoted-message embed when a reply was asked for, and reports whether the same message or file was already there plus which account sent it. Refuses conversations with no composer, such as broadcast channels you do not administer.

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). Confirm the target with the user before sending — a peer id is not human-readable, so echo back the chatTitle this returns.

text optional

The message text. Required on its own for a text message; sent as the document's caption when fileBase64 is also given. Omit for a document with no caption.

filename optional

Required with fileBase64: the name Telegram gives the document, including its extension (e.g. "report.pdf"). Also what the script verifies the sent bubble against.

fileBase64 optional

Optional: base64 of a file's bytes, to send it as a document. Requires filename. Telegram Web opens its file picker natively, so there is no file input to bind — the bytes have to arrive here and are pasted into the composer. Keep it modest (a few MB); the base64 travels inside the request.

replyToMessageId optional

Optional: send this as a reply to an existing message, given its id from get_conversation. Works for both a text message and a document. This is why there is no separate reply script — on Telegram a reply is an ordinary message carrying a reply-to reference.

Output

kind required

Which of the two sends ran: "document" when fileBase64 was supplied, otherwise "text".

sent required

True once an outgoing bubble matching what was sent, and carrying a server-assigned id, was found in the conversation.

peerId required

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

account_used required

The account that actually sent it, read from the app's own account menu rather than assumed from the request. Null if the menu did not expose a name.

verified_on_page required

True when the send was confirmed by finding the bubble in the conversation afterwards, rather than assumed from the keypress or the button click.

id optional

Telegram's server-assigned message id. The script waits for the real integer id rather than the optimistic local one Telegram renders while the send is pending, so this is always usable by delete/react/reply. For a document it also means the upload finished.

text optional

The text that was sent, or the caption for a document. Null for a document sent without a caption.

fileSize optional

The size Telegram renders on the sent document bubble, read back from the page ("19.0B", "1.2 KB"). Compare it against the bytes you sent to confirm the whole file landed. Null for a text message.

filename optional

The document's filename, or null for a text message.

chatTitle optional

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

repliedTo optional

The message id this was sent as a reply to, or null for a normal message. Evidence-backed rather than echoed: when a reply was requested the script only accepts a sent bubble that actually carries the quoted-message embed, so a reply reference dropped by the attachment dialog fails loudly instead of being reported as done.

already_present optional

Whether an outgoing message with exactly this text (or a document with this filename) was already in the conversation beforehand. Reported, not enforced — resending is legitimate — so the caller decides what to do about a duplicate.

Start building not clicking