From cef24db929c2b863b541864491fa5d4b4191ae0a Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 22 Nov 2024 15:07:44 -0500 Subject: [PATCH] Add PreparedInlineMessage and SavePreparedInlineMessage --- src/TgBotLib/Enums/Methods.php | 3 + .../Methods/SavePreparedInlineMessage.php | 58 ++++++++++++ src/TgBotLib/Methods/SendInvoice.php | 77 +++++++++++++++ .../Objects/PreparedInlineMessage.php | 93 +++++++++++++++++++ 4 files changed, 231 insertions(+) create mode 100644 src/TgBotLib/Methods/SavePreparedInlineMessage.php create mode 100644 src/TgBotLib/Methods/SendInvoice.php create mode 100644 src/TgBotLib/Objects/PreparedInlineMessage.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index 577a050..5bbcddb 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -72,6 +72,7 @@ use TgBotLib\Methods\ReplaceStickerInSet; use TgBotLib\Methods\RestrictChatMember; use TgBotLib\Methods\RevokeChatInviteLink; + use TgBotLib\Methods\SavePreparedInlineMessage; use TgBotLib\Methods\SendAnimation; use TgBotLib\Methods\SendAudio; use TgBotLib\Methods\SendChatAction; @@ -237,6 +238,7 @@ case DELETE_STICKER_SET = 'deleteStickerSet'; case ANSWER_INLINE_QUERY = 'answerInlineQuery'; case ANSWER_WEB_APP_QUERY = 'answerWebAppQuery'; + case SAVE_PREPARED_INLINE_MESSAGE = 'savePreparedInlineMessage'; /** * Executes a command on the provided bot with the given parameters. @@ -365,6 +367,7 @@ self::DELETE_STICKER_SET => DeleteStickerFromSet::execute($bot, $parameters), self::ANSWER_INLINE_QUERY => AnswerInlineQuery::execute($bot, $parameters), self::ANSWER_WEB_APP_QUERY => AnswerWebAppQuery::execute($bot, $parameters), + self::SAVE_PREPARED_INLINE_MESSAGE => SavePreparedInlineMessage::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/SavePreparedInlineMessage.php b/src/TgBotLib/Methods/SavePreparedInlineMessage.php new file mode 100644 index 0000000..6dd48c7 --- /dev/null +++ b/src/TgBotLib/Methods/SavePreparedInlineMessage.php @@ -0,0 +1,58 @@ +toArray()); + } + + if(is_array($parameters['result'])) + { + $parameters['result'] = json_encode($parameters['result']); + } + } + + return PreparedInlineMessage::fromArray(self::executeCurl(self::buildPost($bot, Methods::SAVE_PREPARED_INLINE_MESSAGE->value, $parameters))); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'user_id', + 'result' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'allow_user_chats', + 'allow_bot_chats', + 'allow_group_chats', + 'allow_channel_chats' + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Methods/SendInvoice.php b/src/TgBotLib/Methods/SendInvoice.php new file mode 100644 index 0000000..0df9e66 --- /dev/null +++ b/src/TgBotLib/Methods/SendInvoice.php @@ -0,0 +1,77 @@ +id = null; + $this->expirationDate = null; + + return; + } + + $this->id = $data['id']; + $this->expirationDate = (int)$data['expiration_date']; + } + + /** + * Unique identifier of the prepared message + * + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * Sets the ID for the prepared inline message. + * + * @param string $id The ID to set. + * @return PreparedInlineMessage The current instance. + */ + public function setId(string $id): PreparedInlineMessage + { + $this->id = $id; + return $this; + } + + /** + * Expiration date of the prepared message, in Unix time. Expired prepared messages can no longer be used + * + * @return int + */ + public function getExpirationDate(): int + { + return $this->expirationDate; + } + + /** + * Sets the expiration date for the prepared inline message. + * + * @param int $expirationDate The expiration date timestamp. + * @return PreparedInlineMessage Returns the + */ + public function setExpirationDate(int $expirationDate): PreparedInlineMessage + { + $this->expirationDate = $expirationDate; + return $this; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'id' => $this->id, + 'expiration_date' => $this->expirationDate + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(?array $data): PreparedInlineMessage + { + return new self($data); + } + } \ No newline at end of file