GramJS

⚠️ This project is archived and no longer maintained. Development continues in teleproto, an actively maintained fork. It's largely compatible with GramJS for most projects, migration means little more than swapping the package:
npm install teleproto
See the migration guide for details.

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

NameTypeDescription
flags#Flags, see TL conditional fields
silentflags.0?trueWhether to send the file without triggering a notification
peerInputEncryptedChatSecret chat ID
randomIdlongUnique client message ID necessary to prevent message resending
databytesTL-serialization of DecryptedMessage type, encrypted with a key generated during chat initialization
fileInputEncryptedFileFile attachment for the secret chat

Result

messages.SentEncryptedMessage

Possible errors

CodeTypeDescription
400DATA_TOO_LONGData too long.
400ENCRYPTION_DECLINEDThe secret chat was declined.
400FILE_EMTPYAn empty file was provided.
400MD5_CHECKSUM_INVALIDThe MD5 checksums do not match.
400MSG_WAIT_FAILEDA waiting call returned an error.

Can bots use this method?

No

DecryptedMessage

Object describes the contents of an encrypted message.