copyMessages
Returns: MessageId[]Official docs ↗
Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
Parameters
chat_idIntegerStringRequiredUnique identifier for the target chat or username of the target channel (in the format
@channelusername)message_thread_idIntegerOptionalUnique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only
direct_messages_topic_idIntegerOptionalIdentifier of the direct messages topic to which the messages will be sent; required if the messages are sent to a direct messages chat
from_chat_idIntegerStringRequiredUnique identifier for the chat where the original messages were sent (or channel username in the format
@channelusername)message_idsInteger[]RequiredA JSON-serialized list of 1-100 identifiers of messages in the chat from\chat\id to copy. The identifiers must be specified in a strictly increasing order.
disable_notificationBooleanOptionalSends the messages silently. Users will receive a notification with no sound.
protect_contentBooleanOptionalProtects the contents of the sent messages from forwarding and saving
remove_captionBooleanOptionalPass True to copy the messages without their captions
Returns
On success, an array of MessageId objects is returned.
GramIO Usage
ts
// Copy a batch of messages from one chat to another (no attribution)
const results = await bot.api.copyMessages({
chat_id: -1001234567890,
from_chat_id: "@sourcechannel",
message_ids: [10, 11, 12, 13, 14],
});
console.log(
"Copied message IDs:",
results.map((r) => r.message_id)
);ts
// Copy messages silently without their captions
await bot.api.copyMessages({
chat_id: -1001234567890,
from_chat_id: -1009876543210,
message_ids: [20, 21, 22],
disable_notification: true,
remove_caption: true,
});ts
// Paginate through message IDs and copy in batches of 100
async function copyMessageRange(
fromChatId: number,
toChatId: number,
startId: number,
endId: number
) {
const batchSize = 100;
const allIds = Array.from(
{ length: endId - startId + 1 },
(_, i) => startId + i
);
for (let i = 0; i < allIds.length; i += batchSize) {
const batch = allIds.slice(i, i + batchSize);
await bot.api.copyMessages({
chat_id: toChatId,
from_chat_id: fromChatId,
message_ids: batch,
});
}
}
await copyMessageRange(-1009876543210, -1001234567890, 100, 350);ts
// Copy messages to a forum topic thread
await bot.api.copyMessages({
chat_id: -1001234567890,
message_thread_id: 456, // target forum topic
from_chat_id: "@sourcechannel",
message_ids: [30, 31, 32],
});Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | chat_id or from_chat_id is invalid or inaccessible to the bot |
| 400 | Bad Request: message IDs must be in strictly increasing order | message_ids array is not sorted in ascending order |
| 400 | Bad Request: too many messages | message_ids contains more than 100 identifiers |
| 403 | Forbidden: bot is not a member of the channel chat | Bot lacks access to the target channel |
| 403 | Forbidden: not enough rights | Bot does not have permission to post in the target chat |
| 429 | Too Many Requests: retry after N | Rate limit exceeded — respect retry_after, use auto-retry plugin |
TIP
Use GramIO's auto-retry plugin to handle 429 rate limit errors automatically when copying large message batches.
Tips & Gotchas
message_idsmust be in strictly increasing order. If your IDs aren't sorted, sort them first with.sort((a, b) => a - b)— the API will reject unsorted arrays with a 400 error.- Maximum 100 IDs per call. For larger ranges, split into chunks of 100 and call
copyMessagesin sequence. Sending more than 100 IDs at once results in an error. - Uncopyable messages are silently skipped. Service messages, invoice messages, paid media, giveaway messages, and protected-content messages are skipped without error — the returned array will be shorter than your input.
- Album grouping is preserved. If consecutive message IDs belong to a media album (group of photos/videos), they are copied as a group, maintaining the album layout.
- No forwarding attribution. Unlike
forwardMessages, copied messages have no "Forwarded from" header — ideal for relaying content without revealing the source. remove_caption: truestrips all captions. There's no per-message caption override in bulk mode — to set custom captions, use individualcopyMessagecalls.- Rate limits apply per chat. Telegram enforces message rate limits per target chat. When broadcasting to many chats, consider using
allow_paid_broadcast(oncopyMessage) or the auto-retry plugin.
See Also
copyMessage— copy a single message with caption override and keyboard supportforwardMessages— forward multiple messages with source attributionforwardMessage— forward a single messageMessageId— the returned type for each copied message- Auto-retry plugin — handle rate limits automatically