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!",
        }),
      ],
      noforwards: true,
      scheduleDate: 43,
      sendAs: "username",
    })
  );
  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!",
        }),
      ],
      noforwards: true,
      scheduleDate: 43,
      sendAs: "username",
    })
  );
  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
noforwardsflags.14?trueOnly for bots, disallows forwarding and saving of the messages, even if the destination chat doesn't have content protection enabled
peerInputPeerThe destination chat
replyToMsgIdflags.0?intThe message to reply to
multiMediaVector<InputSingleMedia>The medias to send
scheduleDateflags.10?intScheduled message date for scheduled messages
sendAsflags.13?InputPeerSend this message as the specified peer

Result

Updates

Possible errors

CodeTypeDescription
400CHANNEL_PRIVATEYou haven't joined this channel/supergroup.
400CHAT_ADMIN_REQUIREDYou must be an admin in this chat to do this.
400CHAT_FORWARDS_RESTRICTEDYou can't forward messages from a protected chat.
403CHAT_WRITE_FORBIDDENYou can't write in this chat.
400MEDIA_CAPTION_TOO_LONGThe caption is too long.
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.
500RANDOM_ID_DUPLICATEYou provided a random ID that was already used.
400RANDOM_ID_EMPTYRandom ID empty.
400SCHEDULE_DATE_TOO_LATEYou can't schedule a message this far in the future.
400SCHEDULE_TOO_MUCHThere are too many scheduled messages.
420SLOWMODE_WAIT_%dSlowmode is enabled in this chat: wait %d seconds before sending another message to this chat.

Can bots use this method?

Yes

Message drafts

How to handle message drafts

Uploading and Downloading Files

How to transfer large data batches correctly.