diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index cb696d4..baa5933 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -76,6 +76,7 @@ use TgBotLib\Methods\SendPaidMedia; use TgBotLib\Methods\SendPhoto; use TgBotLib\Methods\SendPoll; + use TgBotLib\Methods\SendSticker; use TgBotLib\Methods\SendVenue; use TgBotLib\Methods\SendVideo; use TgBotLib\Methods\SendVideoNote; @@ -204,6 +205,7 @@ case STOP_POLL = 'stopPoll'; case DELETE_MESSAGE = 'deleteMessage'; case DELETE_MESSAGES = 'deleteMessages'; + case SEND_STICKER = 'sendSticker'; /** * Executes a command on the provided bot with the given parameters. @@ -315,6 +317,7 @@ self::STOP_POLL => StopPoll::execute($bot, $parameters), self::DELETE_MESSAGE => DeleteMessage::execute($bot, $parameters), self::DELETE_MESSAGES => DeleteMessages::execute($bot, $parameters), + self::SEND_STICKER => SendSticker::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/SendSticker.php b/src/TgBotLib/Methods/SendSticker.php new file mode 100644 index 0000000..8ddd627 --- /dev/null +++ b/src/TgBotLib/Methods/SendSticker.php @@ -0,0 +1,80 @@ +toArray()); + } + elseif (is_array($parameters['reply_markup'])) + { + $parameters['reply_markup'] = json_encode($parameters['reply_markup']); + } + } + + if(isset($parameters['reply_parameters']) && $parameters['reply_parameters'] instanceof ReplyParameters) + { + $parameters['reply_parameters'] = $parameters['reply_parameters']->toArray(); + } + + if (isset($parameters['sticker'])) + { + $sticker = $parameters['sticker']; + + // If media is a file path and exists locally + if (is_string($sticker) && file_exists($sticker) && is_file($sticker)) + { + $curl = self::buildUpload($bot, Methods::SEND_STICKER->value, 'sticker', $sticker, array_diff_key($parameters, ['sticker' => null])); + return Message::fromArray(self::executeCurl($curl)); + } + } + + return Message::fromArray(self::executeCurl(self::buildPost($bot, Methods::SEND_STICKER->value, $parameters))); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'chat_id', + 'sticker' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'business_connection_id', + 'message_thread_id', + 'emoji', + 'disable_notification', + 'protect_content', + 'allow_paid_broadcast', + 'message_effect_id', + 'reply_parameters', + 'reply_markup' + ]; + } + } \ No newline at end of file