GramJS

messages.SendMultiMedia

Send an album or grouped media

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.SendMultiMedia({
      peer: "username",
      multiMedia: [
        new Api.InputSingleMedia({
          media: new Api.InputMediaUploadedPhoto({
            file: await client.uploadFile({
              file: new CustomFile(
                "file.bin",
                fs.statSync("../file.bin").size,
                "../file.bin"
              ),
              workers: 1,
            }),
            stickers: [
              new Api.InputDocument({
                id: BigInt("-4156887774564"),
                accessHash: BigInt("-4156887774564"),
                fileReference: Buffer.from("arbitrary data here"),
              }),
            ],
            ttlSeconds: 43,
          }),
          randomId: BigInt("-4156887774564"),
          message: "Hello there!",
        }),
      ],
      scheduleDate: 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.Updates = await client.invoke(
    new Api.messages.SendMultiMedia({
      peer: "username",
      multiMedia: [
        new Api.InputSingleMedia({
          media: new Api.InputMediaUploadedPhoto({
            file: await client.uploadFile({
              file: new CustomFile(
                "file.bin",
                fs.statSync("../file.bin").size,
                "../file.bin"
              ),
              workers: 1,
            }),
            stickers: [
              new Api.InputDocument({
                id: BigInt("-4156887774564"),
                accessHash: BigInt("-4156887774564"),
                fileReference: Buffer.from("arbitrary data here"),
              }),
            ],
            ttlSeconds: 43,
          }),
          randomId: BigInt("-4156887774564"),
          message: "Hello there!",
        }),
      ],
      scheduleDate: 43,
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
flags#Flags, see TL conditional fields
silentflags.5?trueWhether to send the album silently (no notification triggered)
backgroundflags.6?trueSend in background?
clearDraftflags.7?trueWhether to clear drafts
peerInputPeerThe destination chat
replyToMsgIdflags.0?intThe message to reply to
multiMediaVector<InputSingleMedia>The medias to send
scheduleDateflags.10?intScheduled message date for scheduled messages

Result

Updates

Possible errors

CodeTypeDescription
400CHAT_ADMIN_REQUIREDYou must be an admin in this chat to do this
400MEDIA_EMPTYThe provided media object is invalid
400MEDIA_INVALIDMedia invalid
400MULTI_MEDIA_TOO_LONGToo many media files for album
400PEER_ID_INVALIDThe provided peer id is invalid
400RANDOM_ID_EMPTYRandom ID empty

Can bots use this method?

Yes

Message drafts

How to handle message drafts

Uploading and Downloading Files

How to transfer large data batches correctly.