From 744771445e8ac8ab12166660054551f5f8aa2be3 Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 9 Oct 2024 15:25:19 -0400 Subject: [PATCH] Enhance reply_markup handling and add SendPaidMedia method. --- src/TgBotLib/Enums/Methods.php | 5 ++++- src/TgBotLib/Methods/CopyMessage.php | 11 +++++++++-- src/TgBotLib/Methods/SendAnimation.php | 11 +++++++++-- src/TgBotLib/Methods/SendAudio.php | 11 +++++++++-- src/TgBotLib/Methods/SendDocument.php | 11 +++++++++-- src/TgBotLib/Methods/SendMessage.php | 11 +++++++++-- src/TgBotLib/Methods/SendPhoto.php | 11 +++++++++-- src/TgBotLib/Methods/SendVideo.php | 11 +++++++++-- 8 files changed, 67 insertions(+), 15 deletions(-) diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index a0dfa9d..7f2046a 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -16,6 +16,7 @@ use TgBotLib\Methods\SendAudio; use TgBotLib\Methods\SendDocument; use TgBotLib\Methods\SendMessage; + use TgBotLib\Methods\SendPaidMedia; use TgBotLib\Methods\SendPhoto; use TgBotLib\Methods\SendVideo; use TgBotLib\Methods\SendVideoNote; @@ -38,6 +39,7 @@ case SEND_ANIMATION = 'sendAnimation'; case SEND_VOICE = 'sendVoice'; case SEND_VIDEO_NOTE = 'sendVideoNote'; + case SEND_PAID_MEDIA = 'sendPaidMedia'; /** * Executes a command on the provided bot with the given parameters. @@ -65,7 +67,8 @@ self::SEND_VIDEO => SendVideo::execute($bot, $parameters), self::SEND_ANIMATION => SendAnimation::execute($bot, $parameters), self::SEND_VOICE => SendVoice::execute($bot, $parameters), - self::SEND_VIDEO_NOTE => SendVideoNote::execute($bot, $parameters) + self::SEND_VIDEO_NOTE => SendVideoNote::execute($bot, $parameters), + self::SEND_PAID_MEDIA => SendPaidMedia::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/CopyMessage.php b/src/TgBotLib/Methods/CopyMessage.php index dfdaf88..0f70d0b 100644 --- a/src/TgBotLib/Methods/CopyMessage.php +++ b/src/TgBotLib/Methods/CopyMessage.php @@ -58,9 +58,16 @@ $parameters['reply_parameters'] = $parameters['reply_parameters']->toArray(); } - if(isset($parameters['reply_markup']) && $parameters['reply_markup'] instanceof ObjectTypeInterface) + if (isset($parameters['reply_markup'])) { - $parameters['reply_markup'] = $parameters['reply_markup']->toArray(); + 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']); + } } diff --git a/src/TgBotLib/Methods/SendAnimation.php b/src/TgBotLib/Methods/SendAnimation.php index 4d91b96..107bac0 100644 --- a/src/TgBotLib/Methods/SendAnimation.php +++ b/src/TgBotLib/Methods/SendAnimation.php @@ -48,9 +48,16 @@ $parameters['reply_parameters'] = $parameters['reply_parameters']->toArray(); } - if(isset($parameters['reply_markup']) && $parameters['reply_markup'] instanceof ObjectTypeInterface) + if (isset($parameters['reply_markup'])) { - $parameters['reply_markup'] = $parameters['reply_markup']->toArray(); + 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']); + } } // Handle different photo input types diff --git a/src/TgBotLib/Methods/SendAudio.php b/src/TgBotLib/Methods/SendAudio.php index 0bd77d4..c923e5e 100644 --- a/src/TgBotLib/Methods/SendAudio.php +++ b/src/TgBotLib/Methods/SendAudio.php @@ -56,9 +56,16 @@ $parameters['reply_parameters'] = $parameters['reply_parameters']->toArray(); } - if(isset($parameters['reply_markup']) && $parameters['reply_markup'] instanceof ObjectTypeInterface) + if (isset($parameters['reply_markup'])) { - $parameters['reply_markup'] = $parameters['reply_markup']->toArray(); + 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']); + } } // Handle file uploads diff --git a/src/TgBotLib/Methods/SendDocument.php b/src/TgBotLib/Methods/SendDocument.php index 5e880a9..7646ff1 100644 --- a/src/TgBotLib/Methods/SendDocument.php +++ b/src/TgBotLib/Methods/SendDocument.php @@ -53,9 +53,16 @@ $parameters['reply_parameters'] = $parameters['reply_parameters']->toArray(); } - if(isset($parameters['reply_markup']) && $parameters['reply_markup'] instanceof ObjectTypeInterface) + if (isset($parameters['reply_markup'])) { - $parameters['reply_markup'] = $parameters['reply_markup']->toArray(); + 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']); + } } // Handle file uploads diff --git a/src/TgBotLib/Methods/SendMessage.php b/src/TgBotLib/Methods/SendMessage.php index dfc9a8c..c95cee6 100644 --- a/src/TgBotLib/Methods/SendMessage.php +++ b/src/TgBotLib/Methods/SendMessage.php @@ -60,9 +60,16 @@ $parameters['reply_parameters'] = $parameters['reply_parameters']->toArray(); } - if(isset($parameters['reply_markup']) && $parameters['reply_markup'] instanceof ObjectTypeInterface) + if (isset($parameters['reply_markup'])) { - $parameters['reply_markup'] = $parameters['reply_markup']->toArray(); + 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::SEND_MESSAGE->value, $parameters))); diff --git a/src/TgBotLib/Methods/SendPhoto.php b/src/TgBotLib/Methods/SendPhoto.php index dbac51d..5da43b5 100644 --- a/src/TgBotLib/Methods/SendPhoto.php +++ b/src/TgBotLib/Methods/SendPhoto.php @@ -53,9 +53,16 @@ $parameters['reply_parameters'] = $parameters['reply_parameters']->toArray(); } - if(isset($parameters['reply_markup']) && $parameters['reply_markup'] instanceof ObjectTypeInterface) + if (isset($parameters['reply_markup'])) { - $parameters['reply_markup'] = $parameters['reply_markup']->toArray(); + 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']); + } } // Handle different photo input types diff --git a/src/TgBotLib/Methods/SendVideo.php b/src/TgBotLib/Methods/SendVideo.php index 12749c5..94b6178 100644 --- a/src/TgBotLib/Methods/SendVideo.php +++ b/src/TgBotLib/Methods/SendVideo.php @@ -54,9 +54,16 @@ class SendVideo extends Method $parameters['reply_parameters'] = $parameters['reply_parameters']->toArray(); } - if(isset($parameters['reply_markup']) && $parameters['reply_markup'] instanceof ObjectTypeInterface) + if (isset($parameters['reply_markup'])) { - $parameters['reply_markup'] = $parameters['reply_markup']->toArray(); + 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']); + } } // Handle file uploads