GramJS

messages.ForwardMessages

Forwards messages by their IDs.

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.ForwardMessages({
      fromPeer: "username",
      id: [43],
      randomId: [BigInt("-4156887774564")],
      toPeer: "username",
      withMyScore: true,
      dropAuthor: true,
      dropMediaCaptions: true,
      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.ForwardMessages({
      fromPeer: "username",
      id: [43],
      randomId: [BigInt("-4156887774564")],
      toPeer: "username",
      withMyScore: true,
      dropAuthor: true,
      dropMediaCaptions: true,
      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 messages silently (no notification will be triggered on the destination clients)
backgroundflags.6?trueWhether to send the message in background
withMyScoreflags.8?trueWhen forwarding games, whether to include your score in the game
dropAuthorflags.11?trueWhether to forward messages without quoting the original author
dropMediaCaptionsflags.12?trueWhether to strip captions from media
noforwardsflags.14?trueOnly for bots, disallows further re-forwarding and saving of the messages, even if the destination chat doesn't have content protection enabled
fromPeerInputPeerSource of messages
idVector<int>IDs of messages
randomIdVector<long>Random ID to prevent resending of messages
toPeerInputPeerDestination peer
scheduleDateflags.10?intScheduled message date for scheduled messages
sendAsflags.13?InputPeerForward the messages as the specified peer

Result

Updates

Possible errors

CodeTypeDescription
400BROADCAST_PUBLIC_VOTERS_FORBIDDENYou can't forward polls with public voters.
400CHANNEL_INVALIDThe provided channel is invalid.
400CHANNEL_PRIVATEYou haven't joined this channel/supergroup.
400CHAT_ADMIN_REQUIREDYou must be an admin in this chat to do this.
406CHAT_FORWARDS_RESTRICTEDYou can't forward messages from a protected chat.
400CHAT_ID_INVALIDThe provided chat id is invalid.
400CHAT_RESTRICTEDYou can't send messages in this chat, you were restricted.
403CHAT_SEND_GAME_FORBIDDENYou can't send a game to this chat.
403CHAT_SEND_GIFS_FORBIDDENYou can't send gifs in this chat.
403CHAT_SEND_MEDIA_FORBIDDENYou can't send media in this chat.
403CHAT_SEND_POLL_FORBIDDENYou can't send polls in this chat.
403CHAT_SEND_STICKERS_FORBIDDENYou can't send stickers in this chat.
403CHAT_WRITE_FORBIDDENYou can't write in this chat.
400GROUPED_MEDIA_INVALIDInvalid grouped media.
400INPUT_USER_DEACTIVATEDThe specified user was deleted.
400MEDIA_EMPTYThe provided media object is invalid.
400MESSAGE_IDS_EMPTYNo message ids were provided.
400MESSAGE_ID_INVALIDThe provided message id is invalid.
400MSG_ID_INVALIDInvalid message ID provided.
400PEER_ID_INVALIDThe provided peer id is invalid.
400QUIZ_ANSWER_MISSINGYou can forward a quiz while hiding the original author only after choosing an option in the quiz.
500RANDOM_ID_DUPLICATEYou provided a random ID that was already used.
400RANDOM_ID_INVALIDA provided random ID is invalid.
400SCHEDULE_DATE_TOO_LATEYou can't schedule a message this far in the future.
400SCHEDULE_TOO_MUCHThere are too many scheduled messages.
400SEND_AS_PEER_INVALIDYou can't send messages as the specified peer.
420SLOWMODE_WAIT_%dSlowmode is enabled in this chat: wait %d seconds before sending another message to this chat.
400SLOWMODE_MULTI_MSGS_DISABLEDSlowmode is enabled, you cannot forward multiple messages to this group.
400USER_BANNED_IN_CHANNELYou're banned from sending messages in supergroups/channels.
403USER_IS_BLOCKEDYou were blocked by this user.
400USER_IS_BOTBots can't send messages to other bots.
400YOU_BLOCKED_USERYou blocked this user.

Can bots use this method?

Yes