From e81ec60377680aa257b4f26c0dc79533113f56a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=A8=B1=E6=99=AF=E6=AC=A3?=
<44869012+xjx0106@users.noreply.github.com>
Date: Sat, 17 Feb 2024 06:40:17 +0800
Subject: [PATCH] feat: add copyMessages method
---
doc/api.md | 19 +++++++++++++++++++
src/telegram.js | 20 ++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/doc/api.md b/doc/api.md
index 1b39ab9..fab1f99 100644
--- a/doc/api.md
+++ b/doc/api.md
@@ -41,6 +41,7 @@ TelegramBot
* [.sendMessage(chatId, text, [options])](#TelegramBot+sendMessage) ⇒ Promise
* [.forwardMessage(chatId, fromChatId, messageId, [options])](#TelegramBot+forwardMessage) ⇒ Promise
* [.copyMessage(chatId, fromChatId, messageId, [options])](#TelegramBot+copyMessage) ⇒ Promise
+ * [.copyMessages(chatId, fromChatId, messageIds, [options])](#TelegramBot+copyMessages) ⇒ Promise
* [.sendPhoto(chatId, photo, [options], [fileOptions])](#TelegramBot+sendPhoto) ⇒ Promise
* [.sendAudio(chatId, audio, [options], [fileOptions])](#TelegramBot+sendAudio) ⇒ Promise
* [.sendDocument(chatId, doc, [options], [fileOptions])](#TelegramBot+sendDocument) ⇒ Promise
@@ -563,6 +564,24 @@ Returns the MessageId of the sent message on success.
| messageId | Number
\| String
| Unique message identifier |
| [options] | Object
| Additional Telegram query options |
+
+
+### telegramBot.copyMessages(chatId, fromChatId, messageIds, [options]) ⇒ Promise
+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, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
+Returns the MessageId of the sent message on success.
+
+**Kind**: instance method of [TelegramBot
](#TelegramBot)
+**Returns**: Promise
- An array of MessageId of the sent messages
+**See**: https://core.telegram.org/bots/api#copymessages
+
+| Param | Type | Description |
+| --- | --- | --- |
+| chatId | Number
\| String
| Unique identifier for the target chat |
+| fromChatId | Number
\| String
| Unique identifier for the chat where the original message was sent |
+| messageIds | Array
| Identifiers of 1-100 messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order. |
+| [options] | Object
| Additional Telegram query options |
+
### telegramBot.sendPhoto(chatId, photo, [options], [fileOptions]) ⇒ Promise
diff --git a/src/telegram.js b/src/telegram.js
index bd7b1e1..1fc8868 100644
--- a/src/telegram.js
+++ b/src/telegram.js
@@ -958,6 +958,26 @@ class TelegramBot extends EventEmitter {
return this._request('copyMessage', { form });
}
+ /**
+ * 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, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
+ * Returns the MessageId of the sent message on success.
+ * @param {Number|String} chatId Unique identifier for the target chat
+ * @param {Number|String} fromChatId Unique identifier for the chat where the
+ * original message was sent
+ * @param {Array} messageIds Identifiers of 1-100 messages in the chat from_chat_id to copy.
+ * The identifiers must be specified in a strictly increasing order.
+ * @param {Object} [options] Additional Telegram query options
+ * @return {Promise} An array of MessageId of the sent messages
+ * @see https://core.telegram.org/bots/api#copymessages
+ */
+ copyMessages(chatId, fromChatId, messageIds, form = {}) {
+ form.chat_id = chatId;
+ form.from_chat_id = fromChatId;
+ form.message_ids = messageIds;
+ return this._request('copyMessages', { form });
+ }
+
/**
* Send photo
* @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)