Telegram — Send a message or a document
Input
peerId requiredThe 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 optionalThe 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 optionalRequired 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 optionalOptional: 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 optionalOptional: 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 requiredWhich of the two sends ran: "document" when fileBase64 was supplied, otherwise "text".
sent requiredTrue once an outgoing bubble matching what was sent, and carrying a server-assigned id, was found in the conversation.
peerId requiredThe peer id that was actually opened, read back from the address bar.
account_used requiredThe 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 requiredTrue when the send was confirmed by finding the bubble in the conversation afterwards, rather than assumed from the keypress or the button click.
id optionalTelegram'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 optionalThe text that was sent, or the caption for a document. Null for a document sent without a caption.
fileSize optionalThe 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 optionalThe document's filename, or null for a text message.
chatTitle optionalThe conversation title from the header — echo this to a human, since a peer id is not recognisable.
repliedTo optionalThe 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 optionalWhether 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.
