From f8e5b0f6322d2feecb71ad30454cc6714a40c1dc Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 1 Nov 2024 13:51:52 -0400 Subject: [PATCH] Add SetWebhook method and integrate with Methods enum --- src/TgBotLib/Enums/Methods.php | 3 ++ src/TgBotLib/Methods/SetWebhook.php | 63 +++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/TgBotLib/Methods/SetWebhook.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index 1e520ea..f604ee1 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -29,10 +29,12 @@ use TgBotLib\Methods\SendVideo; use TgBotLib\Methods\SendVideoNote; use TgBotLib\Methods\SendVoice; + use TgBotLib\Methods\SetWebhook; enum Methods : string { case GET_UPDATES = 'getUpdates'; + case SET_WEBHOOK = 'setWebhook'; case GET_ME = 'getMe'; case LOGOUT = 'logOut'; case CLOSE = 'close'; @@ -70,6 +72,7 @@ return match($this) { self::GET_UPDATES => GetUpdates::execute($bot, $parameters), + self::SET_WEBHOOK => SetWebhook::execute($bot, $parameters), self::GET_ME => GetMe::execute($bot, $parameters), self::LOGOUT => LogOut::execute($bot, $parameters), self::CLOSE => Close::execute($bot, $parameters), diff --git a/src/TgBotLib/Methods/SetWebhook.php b/src/TgBotLib/Methods/SetWebhook.php new file mode 100644 index 0000000..2b9c7f7 --- /dev/null +++ b/src/TgBotLib/Methods/SetWebhook.php @@ -0,0 +1,63 @@ +value, 'certificate', $certificate, array_diff_key($parameters, ['certificate' => null])); + return self::executeCurl($curl); + } + } + + // If no local files to upload, use regular POST method + return self::executeCurl(self::buildPost($bot, Methods::SET_WEBHOOK->value, $parameters)); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'url', + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'certificate', + 'ip_address', + 'max_connections', + 'allowed_updates', + 'drop_pending_updates', + 'secret_token' + ]; + } + } \ No newline at end of file