messages.SendEncryptedFile
Sends a message with a file attachment to a secret chat
Example
const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");
const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});
(async function run() {
await client.connect(); // This assumes you have already authenticated with .start()
const result = await client.invoke(
new Api.messages.SendEncryptedFile({
peer: new Api.InputEncryptedChat({
chatId: 43,
accessHash: BigInt("-4156887774564"),
}),
randomId: BigInt("-4156887774564"),
data: Buffer.from("arbitrary data here"),
file: new Api.InputEncryptedFileUploaded({
id: BigInt("-4156887774564"),
parts: 43,
md5Checksum: "some string here",
keyFingerprint: 43,
}),
})
);
console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";
const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});
(async function run() {
await client.connect(); // This assumes you have already authenticated with .start()
const result: Api.messages.SentEncryptedMessage = await client.invoke(
new Api.messages.SendEncryptedFile({
peer: new Api.InputEncryptedChat({
chatId: 43,
accessHash: BigInt("-4156887774564"),
}),
randomId: BigInt("-4156887774564"),
data: Buffer.from("arbitrary data here"),
file: new Api.InputEncryptedFileUploaded({
id: BigInt("-4156887774564"),
parts: 43,
md5Checksum: "some string here",
keyFingerprint: 43,
}),
})
);
console.log(result); // prints the result
})();
Parameters
Name | Type | Description |
---|---|---|
flags | # | Flags, see TL conditional fields |
silent | flags.0?true | Whether to send the file without triggering a notification |
peer | InputEncryptedChat | Secret chat ID |
randomId | long | Unique client message ID necessary to prevent message resending |
data | bytes | TL-serialization of DecryptedMessage type, encrypted with a key generated during chat initialization |
file | InputEncryptedFile | File attachment for the secret chat |
Result
Possible errors
Code | Type | Description |
---|---|---|
400 | DATA_TOO_LONG | Data too long. |
400 | ENCRYPTION_DECLINED | The secret chat was declined. |
400 | FILE_EMTPY | An empty file was provided. |
400 | MD5_CHECKSUM_INVALID | The MD5 checksums do not match. |
400 | MSG_WAIT_FAILED | A waiting call returned an error. |
Can bots use this method?
No
Related pages
DecryptedMessage
Object describes the contents of an encrypted message.