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,
      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.ForwardMessages({
      fromPeer: "username",
      id: [43],
      randomId: [BigInt("-4156887774564")],
      toPeer: "username",
      withMyScore: true,
      scheduleDate: 43,
    })
  );
  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
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

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
400CHAT_ID_INVALIDThe provided chat id is invalid
400CHAT_RESTRICTEDYou can't send messages in this chat, you were restricted
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
420P0NY_FLOODWAIT
400PEER_ID_INVALIDThe provided peer id is invalid
400RANDOM_ID_INVALIDA provided random ID is invalid
400SCHEDULE_TOO_MUCHThere are too many scheduled messages
400SLOWMODE_MULTI_MSGS_DISABLEDSlowmode is enabled, you cannot forward multiple messages to this group.
420SLOWMODE_WAIT_XSlowmode is enabled in this chat: you must wait for the specified number of seconds before sending another message to the chat.
400USER_BANNED_IN_CHANNELYou're banned from sending messages in supergroups/channels
400USER_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