From 742afb81cd5d3c121e77be807d8843e3c025e8b0 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Tue, 30 Jul 2024 21:58:44 +0200 Subject: [PATCH] feat: #465 add Multiple Message Actions support as defined in api 7.0 --- CHANGELOG.md | 3 ++ src/BotApi.php | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e89613d4..af12a3dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Add `\TelegramBot\Api\Types\Update::$messageReaction` field - Add `\TelegramBot\Api\Types\Update::$messageReactionCount` field - Add `\TelegramBot\Api\BotApi::setMessageReaction` api method +- Add `\TelegramBot\Api\BotApi::deleteMessages` api method +- Add `\TelegramBot\Api\BotApi::copyMessages` api method +- Add `\TelegramBot\Api\BotApi::forwardMessages` api method ### Deprecated - Deprecate `reply_to_message_id` and `allow_sending_without_reply` parameters to `\TelegramBot\Api\BotApi` methods. Use `reply_parameters` instead. diff --git a/src/BotApi.php b/src/BotApi.php index f6175e08..a5603f18 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -3059,6 +3059,107 @@ public function setMessageReaction($chatId, $messageId, $reaction, $isBig = fals ]); } + /** + * Use this method to delete multiple messages simultaneously. + * If some of the specified messages can't be found, they are skipped. + * Returns True on success. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int[] $messageIds A JSON-serialized list of 1-100 identifiers of messages to delete. See deleteMessage for limitations on which messages can be deleted + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function deleteMessages($chatId, $messageIds) + { + return $this->call('deleteMessages', [ + 'chat_id' => $chatId, + 'message_ids' => $messageIds + ]); + } + + /** + * Use this method to forward multiple messages of any kind. + * If some of the specified messages can't be found or forwarded, they are skipped. + * Service messages and messages with protected content can't be forwarded. + * Album grouping is kept for forwarded messages. + * On success, an array of MessageId of the sent messages is returned. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param string|int $fromChatId Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) + * @param int[] $messageIds A JSON-serialized list of 1-100 identifiers of messages in the chat from_chat_id to forward. The identifiers must be specified in a strictly increasing order. + * @param bool $disableNotification Sends the messages silently. Users will receive a notification with no sound. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param bool $protectContent Protects the contents of the forwarded messages from forwarding and saving + * + * @return int[] + * @throws Exception + * + * @author bernard-ng + */ + public function forwardMessages( + $chatId, + $fromChatId, + $messageIds, + $messageThreadId = null, + $disableNotification = false, + $protectContent = false + ) { + return $this->call('forwardMessages', [ + 'chat_id' => $chatId, + 'from_chat_id' => $fromChatId, + 'message_ids' => $messageIds, + 'message_thread_id' => $messageThreadId, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent + ]); + } + + /** + * 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. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param string|int $fromChatId Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) + * @param int[] $messageIds A 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. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param bool $disableNotification Sends the messages silently. Users will receive a notification with no sound. + * @param bool $protectContent Protects the contents of the copied messages from forwarding and saving + * @param bool $removeCaption Pass True to copy the messages without their captions + * + * @return int[] + * @throws Exception + * + * @author bernard-ng + */ + public function copyMessages( + $chatId, + $fromChatId, + $messageIds, + $messageThreadId, + $disableNotification = false, + $protectContent = false, + $removeCaption = false + ) { + return $this->call('copyMessages', [ + 'chat_id' => $chatId, + 'from_chat_id' => $fromChatId, + 'message_ids' => $messageIds, + 'message_thread_id' => $messageThreadId, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'remove_caption' => (bool) $removeCaption + ]); + } + /** * Set an option for a cURL transfer *