From 6e6e207c544dddc873f8f0de4fa751a1c174cccc Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 14 Nov 2024 00:19:26 -0500 Subject: [PATCH] Add EditMessageMedia method --- src/TgBotLib/Enums/Methods.php | 3 + src/TgBotLib/Methods/EditMessageMedia.php | 71 +++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/TgBotLib/Methods/EditMessageMedia.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index 1d3159b..f3098f9 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -28,6 +28,7 @@ use TgBotLib\Methods\EditForumTopic; use TgBotLib\Methods\EditGeneralForumTopic; use TgBotLib\Methods\EditMessageCaption; + use TgBotLib\Methods\EditMessageMedia; use TgBotLib\Methods\EditMessageText; use TgBotLib\Methods\ExportChatInviteLink; use TgBotLib\Methods\ForwardMessage; @@ -190,6 +191,7 @@ case GET_MY_DEFAULT_ADMINISTRATOR_RIGHTS = 'getMyDefaultAdministratorRights'; case EDIT_MESSAGE_TEXT = 'editMessageText'; case EDIT_MESSAGE_CAPTION = 'editMessageCaption'; + case EDIT_MESSAGE_MEDIA = 'editMessageMedia'; /** * Executes a command on the provided bot with the given parameters. @@ -294,6 +296,7 @@ self::GET_MY_DEFAULT_ADMINISTRATOR_RIGHTS => GetMyDefaultAdministratorRights::execute($bot, $parameters), self::EDIT_MESSAGE_TEXT => EditMessageText::execute($bot, $parameters), self::EDIT_MESSAGE_CAPTION => EditMessageCaption::execute($bot, $parameters), + self::EDIT_MESSAGE_MEDIA => EditMessageMedia::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/EditMessageMedia.php b/src/TgBotLib/Methods/EditMessageMedia.php new file mode 100644 index 0000000..18a7607 --- /dev/null +++ b/src/TgBotLib/Methods/EditMessageMedia.php @@ -0,0 +1,71 @@ +toArray()); + } + elseif (is_array($parameters['reply_markup'])) + { + $parameters['reply_markup'] = json_encode($parameters['reply_markup']); + } + } + + // Handle different media input types + if (isset($parameters['media'])) + { + $media = $parameters['media']; + + // If media is a file path and exists locally + if (is_string($media) && file_exists($media) && is_file($media)) + { + $curl = self::buildUpload($bot, Methods::EDIT_MESSAGE_MEDIA->value, 'media', $media, array_diff_key($parameters, ['media' => null])); + return Message::fromArray(self::executeCurl($curl)); + } + } + + return Message::fromArray(self::executeCurl(self::buildPost($bot, Methods::EDIT_MESSAGE_MEDIA->value, $parameters))); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'media' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'business_connection_id', + 'chat_id', + 'message_id', + 'inline_message_id', + 'reply_markup' + ]; + } + } \ No newline at end of file