Skip to content

Commit e81ec60

Browse files
authored
feat: add copyMessages method
1 parent 4fa9a73 commit e81ec60

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

doc/api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ TelegramBot
4141
* [.sendMessage(chatId, text, [options])](#TelegramBot+sendMessage) ⇒ <code>Promise</code>
4242
* [.forwardMessage(chatId, fromChatId, messageId, [options])](#TelegramBot+forwardMessage) ⇒ <code>Promise</code>
4343
* [.copyMessage(chatId, fromChatId, messageId, [options])](#TelegramBot+copyMessage) ⇒ <code>Promise</code>
44+
* [.copyMessages(chatId, fromChatId, messageIds, [options])](#TelegramBot+copyMessages) ⇒ <code>Promise</code>
4445
* [.sendPhoto(chatId, photo, [options], [fileOptions])](#TelegramBot+sendPhoto) ⇒ <code>Promise</code>
4546
* [.sendAudio(chatId, audio, [options], [fileOptions])](#TelegramBot+sendAudio) ⇒ <code>Promise</code>
4647
* [.sendDocument(chatId, doc, [options], [fileOptions])](#TelegramBot+sendDocument) ⇒ <code>Promise</code>
@@ -563,6 +564,24 @@ Returns the MessageId of the sent message on success.
563564
| messageId | <code>Number</code> \| <code>String</code> | Unique message identifier |
564565
| [options] | <code>Object</code> | Additional Telegram query options |
565566

567+
<a name="TelegramBot+copyMessages"></a>
568+
569+
### telegramBot.copyMessages(chatId, fromChatId, messageIds, [options]) ⇒ <code>Promise</code>
570+
Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped.
571+
Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
572+
Returns the MessageId of the sent message on success.
573+
574+
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
575+
**Returns**: <code>Promise</code> - An array of MessageId of the sent messages
576+
**See**: https://core.telegram.org/bots/api#copymessages
577+
578+
| Param | Type | Description |
579+
| --- | --- | --- |
580+
| chatId | <code>Number</code> \| <code>String</code> | Unique identifier for the target chat |
581+
| fromChatId | <code>Number</code> \| <code>String</code> | Unique identifier for the chat where the original message was sent |
582+
| messageIds | <code>Array</code> | Identifiers of 1-100 messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order. |
583+
| [options] | <code>Object</code> | Additional Telegram query options |
584+
566585
<a name="TelegramBot+sendPhoto"></a>
567586

568587
### telegramBot.sendPhoto(chatId, photo, [options], [fileOptions]) ⇒ <code>Promise</code>

src/telegram.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,26 @@ class TelegramBot extends EventEmitter {
958958
return this._request('copyMessage', { form });
959959
}
960960

961+
/**
962+
* Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped.
963+
* Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
964+
* Returns the MessageId of the sent message on success.
965+
* @param {Number|String} chatId Unique identifier for the target chat
966+
* @param {Number|String} fromChatId Unique identifier for the chat where the
967+
* original message was sent
968+
* @param {Array} messageIds Identifiers of 1-100 messages in the chat from_chat_id to copy.
969+
* The identifiers must be specified in a strictly increasing order.
970+
* @param {Object} [options] Additional Telegram query options
971+
* @return {Promise} An array of MessageId of the sent messages
972+
* @see https://core.telegram.org/bots/api#copymessages
973+
*/
974+
copyMessages(chatId, fromChatId, messageIds, form = {}) {
975+
form.chat_id = chatId;
976+
form.from_chat_id = fromChatId;
977+
form.message_ids = messageIds;
978+
return this._request('copyMessages', { form });
979+
}
980+
961981
/**
962982
* Send photo
963983
* @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)

0 commit comments

Comments
 (0)