From 0486a7f0abef7968cb030c0ba554a90a1b8fd9da Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 13 Nov 2024 22:07:56 -0500 Subject: [PATCH] Add EditMessageCaption --- src/TgBotLib/Enums/Methods.php | 3 + src/TgBotLib/Methods/EditMessageCaption.php | 77 +++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/TgBotLib/Methods/EditMessageCaption.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index b128974..1d3159b 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -27,6 +27,7 @@ use TgBotLib\Methods\EditChatSubscriptionInviteLink; use TgBotLib\Methods\EditForumTopic; use TgBotLib\Methods\EditGeneralForumTopic; + use TgBotLib\Methods\EditMessageCaption; use TgBotLib\Methods\EditMessageText; use TgBotLib\Methods\ExportChatInviteLink; use TgBotLib\Methods\ForwardMessage; @@ -188,6 +189,7 @@ case SET_MY_DEFAULT_ADMINISTRATOR_RIGHTS = 'setMyDefaultAdministratorRights'; case GET_MY_DEFAULT_ADMINISTRATOR_RIGHTS = 'getMyDefaultAdministratorRights'; case EDIT_MESSAGE_TEXT = 'editMessageText'; + case EDIT_MESSAGE_CAPTION = 'editMessageCaption'; /** * Executes a command on the provided bot with the given parameters. @@ -291,6 +293,7 @@ self::SET_MY_DEFAULT_ADMINISTRATOR_RIGHTS => SetMyDefaultAdministratorRights::execute($bot, $parameters), 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), }; } } diff --git a/src/TgBotLib/Methods/EditMessageCaption.php b/src/TgBotLib/Methods/EditMessageCaption.php new file mode 100644 index 0000000..40b4072 --- /dev/null +++ b/src/TgBotLib/Methods/EditMessageCaption.php @@ -0,0 +1,77 @@ +toArray(); + } + else + { + $entities[] = $entity; + } + } + $parameters['caption_entities'] = $entities; + } + + if (isset($parameters['reply_markup'])) + { + if ($parameters['reply_markup'] instanceof ObjectTypeInterface) + { + $parameters['reply_markup'] = json_encode($parameters['reply_markup']->toArray()); + } + elseif (is_array($parameters['reply_markup'])) + { + $parameters['reply_markup'] = json_encode($parameters['reply_markup']); + } + } + + return Message::fromArray(self::executeCurl(self::buildPost($bot, Methods::EDIT_MESSAGE_CAPTION->value, $parameters))); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return null; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'business_connection_id', + 'chat_id', + 'message_id', + 'inline_message_id', + 'caption', + 'parse_mode', + 'caption_entities', + 'show_caption_above_media', + 'reply_markup' + ]; + } + } \ No newline at end of file